📄 interbase.pm
字号:
$sth = $dbh->prepare($sql, $attr);=backSince locale settings affect the result of strftime(), if your applicationis designed to be portable across different locales, you may consider using thesetwo special formats: 'TM' and 'ISO'. C<TM> returns a 9-element list, much likePerl's localtime(). The C<ISO> format applies sprintf()'s pattern"%04d-%02d-%02d %02d:%02d:%02d.%04d" for TIMESTAMP, "%04d-%02d-%02d" forDATE, and "%02d:%02d:%02d.%04d" for TIME. C<$dbh-E<gt>{ib_time_all}> can be used to specify all of the three formats atonce. Example: $dbh->{ib_time_all} = 'TM';=head1 EVENT ALERT SUPPORTEvent alerter is used to notify client applications whenever something ishappened on the database. For this to work, a trigger should be created,which then calls POST_EVENT to post the event notification to the interestedclient. A client could behave in two ways: wait for the event synchronously,or register a callback which will be invoked asynchronously each time aposted event received.=over=item C<ib_init_event> $evh = $dbh->func(@event_names, 'ib_init_event');Creates an event handle from a list of event names. =item C<ib_wait_event> $dbh->func($evh, 'ib_wait_event');Wait synchronously for particular events registered via event handle $evh.Returns a hashref containing pair(s) of posted event's name and its corresponding count,or undef on failure.=item C<ib_register_callback> my $cb = sub { my $posted_events = $_[0]; ++$::COUNT < 6 }; $dbh->func($evh, $cb, 'ib_register_callback'); sub inc_count { my $posted_events = shift; ++$::COUNT < 6 }; $dbh->func($evh, \&inc_count, 'ib_register_callback'); # or anonyomus subroutine $dbh->func( $evh, sub { my ($pe) = @_; ++$::COUNT < 6 }, 'ib_register_callback' );Associates an event handle with an asynchronous callback. A callback will bepassed a hashref as its argument, this hashref contains pair(s) of posted event's nameand its corresponding count. It is safe to call C<ib_register_callback> multiple times for the same event handle. In this case, the previously registered callback will be automatically cancelled.If the callback returns FALSE, the registered callback will be no longer invoked, but internallyit is still there until the event handle goes out of scope (or undef-ed), or you call C<ib_cancel_callback> to actually disassociate it from the event handle.=item C<ib_cancel_callback> $dbh->func($evh, 'ib_cancel_callback');Unregister a callback from an event handle. This function has a limitation,however, that it can't be called from inside a callback. In many cases, you won'tneed this function, since when an event handle goes out of scope, its associated callback(s)will be automatically cancelled before it is cleaned up. =back=head1 RETRIEVING FIREBIRD / INTERBASE SPECIFIC INFORMATION=over=item C<ib_tx_info> $hash_ref = $dbh->func('ib_tx_info');Retrieve information about current active transaction.=item C<ib_database_info> $hash_ref = $dbh->func(@info, 'ib_database_info'); $hash_ref = $dbh->func([@info], 'ib_database_info');Retrieve database information from current connection. =item C<ib_plan> $plan = $sth->func('ib_plan');Retrieve query plan from a prepared SQL statement. my $sth = $dbh->prepare('SELECT * FROM foo'); print $sth->func('ib_plan'); # PLAN (FOO NATURAL)=back=head1 UNSUPPORTED SQL STATEMENTSHere is a list of SQL statements which can't be used. But this shouldn't be a problem, because their functionality are already provided by the DBI methods.=over 4=item * SET TRANSACTIONUse C<$dbh->func(..., 'set_tx_param')> instead.=item * DESCRIBEProvides information about columns that are retrieved by a DSQL statement,or about placeholders in a statement. This functionality is supported by thedriver, and transparent for users. Column names are available via$sth->{NAME} attributes.=item * EXECUTE IMMEDIATECalling do() method without bind value(s) will do the same.=item * CLOSE, OPEN, DECLARE CURSOR$sth->{CursorName} is automagically available upon executing a "SELECT .. FORUPDATE" statement. A cursor is closed after the last fetch(), or by calling$sth->finish(). =item * PREPARE, EXECUTE, FETCHSimilar functionalities are obtained by using prepare(), execute(), and fetch() methods.=back=head1 COMPATIBILITY WITH DBIx::* MODULES C<DBD::InterBase> is known to work with C<DBIx::Recordset> 0.21, andC<Apache::DBI> 0.87. Yuri Vasiliev <I<yuri.vasiliev@targuscom.com>> reported successful usage with Apache::AuthDBI (part of C<Apache::DBI> 0.87 distribution).The driver is untested with C<Apache::Session::DBI>. Doesn't work with C<Tie::DBI>. C<Tie::DBI> calls $dbh->prepare("LISTFIELDS $table_name") on which InterBase fails to parse. I think that the call should be made within an eval block.=head1 FAQ=head2 Why do some operations performing positioned update and delete fail when AutoCommit is on? For example, the following code snippet fails: $sth = $dbh->prepare( "SELECT * FROM ORDERS WHERE user_id < 5 FOR UPDATE OF comment"); $sth->execute; while (@res = $sth->fetchrow_array) { $dbh->do("UPDATE ORDERS SET comment = 'Wonderful' WHERE CURRENT OF $sth->{CursorName}"); }When B<AutoCommit is on>, a transaction is started within prepare(), andcommitted automatically after the last fetch(), or within finish(). Withindo(), a transaction is started right before the statement is executed, andgets committed right after the statement is executed. The transaction handleis stored within the database handle. The driver is smart enough not tooverride an active transaction handle with a new one. So, if you notice thesnippet above, after the first fetchrow_array(), the do() is still using thesame transaction context, but as soon as it has finished executing the statement, itB<commits> the transaction, whereas the next fetchrow_array() still needsthe transaction context!So the secret to make this work is B<to keep the transaction open>. This can bedone in two ways:=over 4=item * Using AutoCommit = 0If yours is default to AutoCommit on, you can put the snippet within a block: { $dbh->{AutoCommit} = 0; # same actions like above .... $dbh->commit; }=item * Using $dbh->{ib_softcommit} = 1This driver-specific attribute is available as of version 0.30. You may wantto look at t/40cursoron.t to see it in action.=back=head2 Why do nested statement handles break under AutoCommit mode?The same explanation as above applies. The workaround is alsomuch alike: { $dbh->{AutoCommit} = 0; $sth1 = $dbh->prepare("SELECT * FROM $table"); $sth2 = $dbh->prepare("SELECT * FROM $table WHERE id = ?"); $sth1->execute; while ($row = $sth1->fetchrow_arrayref) { $sth2->execute($row->[0]); $res = $sth2->fetchall_arrayref; } $dbh->commit; }You may also use $dbh->{ib_softcommit} introduced in version 0.30, please checkt/70nested-sth.t for an example on how to use it.=head2 Why do placeholders fail to bind, generating unknown datatype error message?You can't bind a field name. The following example will fail: $sth = $dbh->prepare("SELECT (?) FROM $table"); $sth->execute('user_id');There are cases where placeholders can't be used in conjunction with COLLATEclause, such as this: SELECT * FROM $table WHERE UPPER(author) LIKE UPPER(? COLLATE FR_CA);This deals with the InterBase's SQL parser, not with C<DBD::InterBase>. Thedriver just passes SQL statements through the engine.=head2 How to do automatic increment for a specific field?Create a generator and a trigger to associate it with the field. Thefollowing example creates a generator named PROD_ID_GEN, and a trigger fortable ORDERS which uses the generator to perform auto increment on fieldPRODUCE_ID with increment size of 1. $dbh->do("CREATE GENERATOR PROD_ID_GEN"); $dbh->do( "CREATE TRIGGER INC_PROD_ID FOR ORDERS BEFORE INSERT POSITION 0 AS BEGIN NEW.PRODUCE_ID = GEN_ID(PROD_ID_GEN, 1); END");=head2 How can I perform LIMIT clause as I usually do in MySQL?C<LIMIT> clause let users to fetch only a portion rather than the whole records as the result of a query. This is particularly efficient and useful for paging feature on web pages, where users can navigate back and forth between pages. Using InterBase (Firebird is explained later), this can be emulated by writing astored procedure. For example, to display a portion of table_forum, first create the following procedure: CREATE PROCEDURE PAGING_FORUM (start INTEGER, num INTEGER) RETURNS (id INTEGER, title VARCHAR(255), ctime DATE, author VARCHAR(255)) AS DECLARE VARIABLE counter INTEGER; BEGIN counter = 0; FOR SELECT id, title, ctime, author FROM table_forum ORDER BY ctime INTO :id, :title, :ctime, :author DO BEGIN IF (counter = :start + :num) THEN EXIT; ELSE IF (counter >= :start) THEN SUSPEND; counter = counter + 1; END END !! SET TERM ; !!And within your application: # fetch record 1 - 5: $res = $dbh->selectall_arrayref("SELECT * FROM paging_forum(0,5)"); # fetch record 6 - 10: $res = $dbh->selectall_arrayref("SELECT * FROM paging_forum(5,5)");But never expect this to work: $sth = $dbh->prepare(<<'SQL'); EXECUTE PROCEDURE paging_forum(5,5) RETURNING_VALUES :id, :title, :ctime, :author SQLWith Firebird 1 RCx and later, you can use C<SELECT FIRST>: SELECT FIRST 10 SKIP 30 * FROM table_forum;C<FIRST x> and C<SKIP x> are both optional. C<FIRST> limits the number ofrows to return, C<SKIP> ignores (skips) the first x rows in resultset. =head2 How can I use the date/time formatting attributes?Those attributes take the same format as the C function strftime()'s.Examples: $attr = { ib_timestampformat => '%m-%d-%Y %H:%M', ib_dateformat => '%m-%d-%Y', ib_timeformat => '%H:%M', };Then, pass it to prepare() method. $sth = $dbh->prepare($stmt, $attr); # followed by execute() and fetch(), or: $res = $dbh->selectall_arrayref($stmt, $attr);=head2 Can I set the date/time formatting attributes between prepare and fetch?No. C<ib_dateformat>, C<ib_timeformat>, and C<ib_timestampformat> can onlybe set during $sth->prepare. If this is a problem to you, let me know, andprobably I'll add this capability for the next release.=head2 Can I change ib_dialect after DBI->connect ?No. If this is a problem to you, let me know, and probably I'll add this capability for the next release.=head2 Why do execute(), do() method and rows() method always return -1 upon a successful operation?Incorrect question. $sth->rows returns the number of fetched rows after asuccessful SELECT. Starting from version 0.43, execute() method returns thenumber of affected rows. But it's true that do() method returns -1, thiswill change in future release.=head1 OBSOLETE FEATURES=over =item Private MethodC<set_tx_param()> is obsoleted by C<ib_set_tx_param()>.=back=head1 TESTED PLATFORMS=head2 Clients=over 4=item Linux=item FreeBSD=item SPARC Solaris=item Win32=back=head2 Servers=over 4=item InterBase 6.0/6.01 SS and Classic for Linux=item InterBase 6.0/6.01 for Windows, FreeBSD, SPARC Solaris=item FirebirdSS 1.0 Final for Windows, Linux, SPARC Solaris=item FirebirdSS 1.5.2.4731 for Windows, Linux=item FirebirdSS 2.0 RC4 for Linux. The AMD64 (64-bit) version is also tested. Should also work with Intel EM64T. =back=head1 AUTHORS=over 4=item * DBI by Tim Bunce <Tim.Bunce@pobox.com>=item * DBD::InterBase by Edwin Pratomo <edpratomo@cpan.org> and Daniel Ritz <daniel.ritz@gmx.ch>.This module is originally based on the work of Bill Karwin's IBPerl.=back=head1 BUGS/LIMITATIONSPlease report bugs and feature suggestions using http://rt.cpan.org/Public/Dist/Display.html?Name=DBD-InterBase.This module doesn't work with MSWin32 ActivePerl iThreads, and its emulatedfork. Tested with MSWin32 ActivePerl build 809 (Perl 5.8.3). The wholeprocess will block in unpredictable manner.Under Linux, this module has been tested with several different iThreadsenabled Perl releases: perl-5.8.0-88 from RedHat 9, perl-5.8.5-9 from FedoraCore 3, perl-5.8.6-15 from Fedora Core 4, and Perl 5.8.[78]. No problem occurred so far.. until you try to share a DBI handle ;-)But if you plan to use thread, you'd better use the latest stable version ofPerl, 5.8.8 has fairly stable iThreads.Limitations:=over 4=item * Arrays are not (yet) supported=item * Read/Write BLOB fields block by block not (yet) supported. Themaximum size of a BLOB read/write is hardcoded to about 1 MB.=item * service manager API is not supported.=back=head1 SEE ALSODBI(3).=head1 COPYRIGHTThe DBD::InterBase module is Copyright (c) 1999-2008 Edwin Pratomo.Portions Copyright (c) 2001-2005 Daniel Ritz.The DBD::InterBase module is free software. You may distribute under the terms of either the GNU General PublicLicense or the Artistic License, as specified in the Perl README file,with the exception that it cannot be placed on a CD-ROM or similar mediafor commercial distribution without the prior approval of the author.=head1 ACKNOWLEDGEMENTSAn attempt to enumerate all who have contributed patches (may misses some):Michael Moehle, Igor Klingen, Sergey Skvortsov, Ilya Verlinsky, PavelZheltouhov, Peter Wilkinson, Mark D. Anderson, Michael Samanov, MichaelArnett, Flemming Frandsen, Mike Shoyher, Christiaan Lademann. =cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -