# $Id: InterBase.pm,v 1.60 2006/10/25 16:13:18 edpratomo Exp $ # # Copyright (c) 1999-2006 Edwin Pratomo # # You may distribute under the terms of either the GNU General Public # License 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 media # for commercial distribution without the prior approval of the author. require 5.004; package DBD::InterBase; use strict; use Carp; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); use DBI 1.41 (); require Exporter; require DynaLoader; @ISA = qw(Exporter DynaLoader); $VERSION = '0.46'; bootstrap DBD::InterBase $VERSION; use vars qw($VERSION $err $errstr $drh); $err = 0; $errstr = ""; $drh = undef; sub CLONE { $drh = undef; } sub driver { return $drh if $drh; my($class, $attr) = @_; $class .= "::dr"; $drh = DBI::_new_drh($class, {'Name' => 'InterBase', 'Version' => $VERSION, 'Err' => \$DBD::InterBase::err, 'Errstr' => \$DBD::InterBase::errstr, 'Attribution' => 'DBD::InterBase by Edwin Pratomo and Daniel Ritz'}); $drh; } # taken from JWIED's DBD::mysql, with slight modification sub _OdbcParse($$$) { my($class, $dsn, $hash, $args) = @_; my($var, $val); if (!defined($dsn)) { return; } while (length($dsn)) { if ($dsn =~ /([^;]*)[;]\r?\n?(.*)/s) { $val = $1; $dsn = $2; } else { $val = $dsn; $dsn = ''; } if ($val =~ /([^=]*)=(.*)/) { $var = $1; $val = $2; if ($var eq 'hostname') { $hash->{'host'} = $val; } elsif ($var eq 'db' || $var eq 'dbname') { $hash->{'database'} = $val; } else { $hash->{$var} = $val; } } else { foreach $var (@$args) { if (!defined($hash->{$var})) { $hash->{$var} = $val; last; } } } } $hash->{host} = "$hash->{host}/$hash->{port}" if ($hash->{host} && $hash->{port}); $hash->{database} = "$hash->{host}:$hash->{database}" if $hash->{host}; } package DBD::InterBase::dr; sub connect { my($drh, $dsn, $dbuser, $dbpasswd, $attr) = @_; $dbuser ||= $ENV{ISC_USER}; #"SYSDBA"; $dbpasswd ||= $ENV{ISC_PASSWORD}; #"masterkey"; my ($this, $private_attr_hash); $private_attr_hash = { 'Name' => $dsn, 'user' => $dbuser, 'password' => $dbpasswd }; DBD::InterBase->_OdbcParse($dsn, $private_attr_hash, ['database', 'host', 'port', 'ib_role', 'ib_dbkey_scope', 'ib_charset', 'ib_dialect', 'ib_cache', 'ib_lc_time']); # second attr args will be retrieved using DBIc_IMP_DATA my $dbh = DBI::_new_dbh($drh, {}, $private_attr_hash); DBD::InterBase::db::_login($dbh, $dsn, $dbuser, $dbpasswd, $attr) or return undef; $dbh; } package DBD::InterBase::db; use strict; use Carp; sub do { my($dbh, $statement, $attr, @params) = @_; my $rows; if (@params) { my $sth = $dbh->prepare($statement, $attr) or return undef; $sth->execute(@params) or return undef; $rows = $sth->rows; } else { $rows = DBD::InterBase::db::_do($dbh, $statement, $attr) or return undef; } ($rows == 0) ? "0E0" : $rows; } sub prepare { my ($dbh, $statement, $attribs) = @_; my $sth = DBI::_new_sth($dbh, {'Statement' => $statement }); DBD::InterBase::st::_prepare($sth, $statement, $attribs) or return undef; $sth; } # from Michael Arnett : sub tables { my $dbh = shift; my @tables; my @row; my $sth = $dbh->prepare(q{ SELECT rdb$relation_name FROM rdb$relations WHERE (rdb$system_flag IS NULL OR rdb$system_flag = 0) AND rdb$view_source IS NULL; }) or return undef; $sth->{ChopBlanks} = 1; $sth->execute; while (@row = $sth->fetchrow_array) { push(@tables, @row); } return @tables; } sub table_info { my $dbh = shift; my $sth = $dbh->prepare(q{ SELECT NULL TABLE_CAT, a.rdb$owner_name TABLE_SCHEM, a.rdb$relation_name TABLE_NAME, CAST('TABLE' AS CHAR(5)) TABLE_TYPE, a.rdb$description REMARKS FROM rdb$relations a WHERE a.rdb$system_flag=0 AND a.rdb$view_blr IS NULL UNION ALL SELECT NULL TABLE_CAT, b.rdb$owner_name TABLE_SCHEM, b.rdb$relation_name TABLE_NAME, CAST('VIEW' AS CHAR(5)) TABLE_TYPE, b.rdb$description REMARKS FROM rdb$relations b WHERE b.rdb$system_flag=0 AND b.rdb$view_blr IS NOT NULL }); $sth->execute() or return undef; return $sth; } sub ping { my($dbh) = @_; local $SIG{__WARN__} = sub { } if $dbh->{PrintError}; local $dbh->{RaiseError} = 0 if $dbh->{RaiseError}; my $ret = DBD::InterBase::db::_ping($dbh); return $ret; } # The get_info function was automatically generated by # DBI::DBD::Metadata::write_getinfo_pm v1.05. sub get_info { my($dbh, $info_type) = @_; require DBD::InterBase::GetInfo; my $v = $DBD::InterBase::GetInfo::info{int($info_type)}; $v = $v->($dbh) if ref $v eq 'CODE'; return $v; } # The type_info_all function was automatically generated by # DBI::DBD::Metadata::write_typeinfo_pm v1.05. sub type_info_all { my ($dbh) = @_; require DBD::InterBase::TypeInfo; return [ @$DBD::InterBase::TypeInfo::type_info_all ]; } 1; __END__ =head1 NAME DBD::InterBase - DBI driver for Firebird and InterBase RDBMS server =head1 SYNOPSIS use DBI; $dbh = DBI->connect("dbi:InterBase:db=$dbname", "sysdba", "masterkey"); # See the DBI module documentation for full details =head1 DESCRIPTION DBD::InterBase is a Perl module which works with the DBI module to provide access to Firebird and InterBase databases. =head1 MODULE DOCUMENTATION This documentation describes driver specific behavior and restrictions. It is not supposed to be used as the only reference for the user. In any case consult the DBI documentation first ! =head1 THE DBI CLASS =head2 DBI Class Methods =over 4 =item B To connect to a database with a minimum of parameters, use the following syntax: $dbh = DBI->connect("dbi:InterBase:dbname=$dbname", "sysdba", "masterkey"); This connects to the database $dbname at localhost as SYSDBA user with the default password. Multiline DSN is acceptable. Here is an example of connect statement which uses all possible parameters: $dsn =<< "DSN"; dbi:InterBase:dbname=$dbname; host=$host; port=$port; ib_dialect=$dialect; ib_role=$role; ib_charset=$charset; ib_cache=$cache DSN $dbh = DBI->connect($dsn, $username, $password); The $dsn is prefixed by 'dbi:InterBase:', and consists of key-value parameters separated by B. New line may be added after the semicolon. The following is the list of valid parameters and their respective meanings: parameter meaning optional? ----------------------------------------------------------------- database path to the database required dbname path to the database db path to the database hostname hostname / IP address optional host hostname / IP address port port number optional ib_dialect the SQL dialect to be used optional ib_role the role of the user optional ib_charset character set to be used optional ib_cache number of database cache buffers optional ib_dbkey_scope change default duration of RDB$DB_KEY optional B could be used interchangebly with B and B. To connect to a remote host, use the B parameter. Here is an example of DSN to connect to a remote Windows host: $dsn = "dbi:InterBase:db=C:/temp/test.gdb;host=rae.cumi.org;ib_dialect=3"; Database file alias introduced in Firebird 1.5 can be used too. In the following example, "billing" is defined in aliases.conf: $dsn = 'dbi:InterBase:hostname=192.168.88.5;db=billing;ib_dialect=3'; Firebird as of version 1.0 listens on port specified within the services file. To connect to port other than the default 3050, add the port number at the end of host name, separated by a slash. Example: $dsn = 'dbi:InterBase:db=/data/test.gdb;host=localhost/3060'; InterBase 6.0 introduces B to provide backward compatibility with databases created by older versions of InterBase. In short, SQL dialect controls how InterBase interprets: - double quotes - the DATE datatype - decimal and numeric datatypes - new 6.0 reserved keywords Valid values for B are 1, 2, and 3. The driver's default value is 1. B specifies the role of the connecting user. B is implemented by InterBase to make database administration easier when dealing with lots of users. A detailed reading can be found at: http://www.ibphoenix.com/ibp_sqlroles.html If B is not specified, the default database's cache size value will be used. The InterBase Operation Guide discusses in full length the importance of this parameter to gain the best performance. =item B @driver_names = DBI->available_drivers; Implemented by DBI, no driver-specific impact. =item B This method is not yet implemented. =item B DBI->trace($trace_level, $trace_file) Implemented by DBI, no driver-specific impact. =back =head2 DBI Dynamic Attributes See Common Methods. =head1 METHODS COMMON TO ALL DBI HANDLES =over 4 =item B $rv = $h->err; Supported by the driver as proposed by DBI. =item B $str = $h->errstr; Supported by the driver as proposed by DBI. =item B This method is not yet implemented. =item B $h->trace($trace_level, $trace_filename); Implemented by DBI, no driver-specific impact. =item B $h->trace_msg($message_text); Implemented by DBI, no driver-specific impact. =item B See B section for information about invoking C from func() method. =back =head1 ATTRIBUTES COMMON TO ALL DBI HANDLES =over 4 =item B (boolean, inherited) Implemented by DBI, no driver-specific impact. =item B (boolean, read-only) Supported by the driver as proposed by DBI. A database handle is active while it is connected and statement handle is active until it is finished. =item B (integer, read-only) Implemented by DBI, no driver-specific impact. =item B (integer, read-only) Implemented by DBI, no driver-specific impact. =item B (hash ref) Implemented by DBI, no driver-specific impact. =item B (boolean, inherited) Not used by this driver. =item B (boolean) Implemented by DBI, no driver-specific impact. =item B (boolean, inherited) Implemented by DBI, no driver-specific impact. =item B (boolean, inherited) Implemented by DBI, no driver-specific impact. =item B (boolean, inherited) Supported by the driver as proposed by DBI. =item B (integer, inherited) Supported by the driver as proposed by DBI.The default value is 80 bytes. =item B (boolean, inherited) Supported by the driver as proposed by DBI. =item B (boolean, inherited) Implemented by DBI, no driver-specific impact. =back =head1 DATABASE HANDLE OBJECTS =head2 Database Handle Methods =over 4 =item B @row_ary = $dbh->selectrow_array($statement, \%attr, @bind_values); Implemented by DBI, no driver-specific impact. =item B $ary_ref = $dbh->selectall_arrayref($statement, \%attr, @bind_values); Implemented by DBI, no driver-specific impact. =item B $ary_ref = $dbh->selectcol_arrayref($statement, \%attr, @bind_values); Implemented by DBI, no driver-specific impact. =item B $sth = $dbh->prepare($statement, \%attr); Supported by the driver as proposed by DBI. When AutoCommit is On, this method implicitly starts a new transaction, which will be automatically committed after the following execute() or the last fetch(), depending on the statement type. For select statements, commit automatically takes place after the last fetch(), or by explicitly calling finish() method if there are any rows remaining. For non-select statements, execute() will implicitly commits the transaction. =item B $sth = $dbh->prepare_cached($statement, \%attr); Implemented by DBI, no driver-specific impact. =item B $rv = $dbh->do($statement, \%attr, @bind_values); Supported by the driver as proposed by DBI. This should be used for non-select statements, where the driver doesn't take the conservative prepare - execute steps, thereby speeding up the execution time. But if this method is used with bind values, the speed advantage diminishes as this method calls prepare() for binding the placeholders. Instead of calling this method repeatedly with bind values, it would be better to call prepare() once, and execute() many times. See the notes for the execute method elsewhere in this document. Unlike the execute method, currently this method doesn't return the number of affected rows. =item B $rc = $dbh->commit; Supported by the driver as proposed by DBI. See also the notes about B elsewhere in this document. =item B $rc = $dbh->rollback; Supported by the driver as proposed by DBI. See also the notes about B elsewhere in this document. =item B $rc = $dbh->disconnect; Supported by the driver as proposed by DBI. =item B $rc = $dbh->ping; This driver supports the ping-method, which can be used to check the validity of a database-handle. This is especially required by C. =item B $sth = $dbh->table_info; Supported by the driver as proposed by DBI. =item B @names = $dbh->tables; Supported by the driver as proposed by DBI. =item B $type_info_all = $dbh->type_info_all; Supported by the driver as proposed by DBI. For further details concerning the InterBase specific data-types please read the L. =item B @type_info = $dbh->type_info($data_type); Implemented by DBI, no driver-specific impact. =item B $sql = $dbh->quote($value, $data_type); Implemented by DBI, no driver-specific impact. =back =head2 Database Handle Attributes =over 4 =item B (boolean) Supported by the driver as proposed by DBI. According to the classification of DBI, InterBase is a database, in which a transaction must be explicitly started. Without starting a transaction, every change to the database becomes immediately permanent. The default of AutoCommit is on, which corresponds to the DBI's default. When setting AutoCommit to off, a transaction will be started and every commit or rollback will automatically start a new transaction. For details see the notes about B elsewhere in this document. =item B (handle) Implemented by DBI, no driver-specific impact. =item B (string, read-only) Not yet implemented. =item B (integer) Implemented by DBI, not used by the driver. =item B (driver-specific, boolean) Set this attribute to TRUE to use InterBase's soft commit feature (default to FALSE). Soft commit retains the internal transaction handle when committing a transaction, while the default commit behavior always closes and invalidates the transaction handle. Since the transaction handle is still open, there is no need to start a new transaction upon every commit, so applications can gain performance improvement. Using soft commit is also desirable when dealing with nested statement handles under AutoCommit on. Switching the attribute's value from TRUE to FALSE will force hard commit thus closing the current transaction. =back =head1 STATEMENT HANDLE OBJECTS =head2 Statement Handle Methods =over 4 =item B Supported by the driver as proposed by DBI. The SQL data type passed as the third argument is ignored. =item B Not supported by this driver. =item B $rv = $sth->execute(@bind_values); Supported by the driver as proposed by DBI. =item B $ary_ref = $sth->fetchrow_arrayref; Supported by the driver as proposed by DBI. =item B @ary = $sth->fetchrow_array; Supported by the driver as proposed by DBI. =item B $hash_ref = $sth->fetchrow_hashref; Supported by the driver as proposed by DBI. =item B $tbl_ary_ref = $sth->fetchall_arrayref; Implemented by DBI, no driver-specific impact. =item B $rc = $sth->finish; Supported by the driver as proposed by DBI. =item B $rv = $sth->rows; Supported by the driver as proposed by DBI. It returns the number of B rows for select statements, otherwise it returns -1 (unknown number of affected rows). =item B $rc = $sth->bind_col($column_number, \$var_to_bind, \%attr); Supported by the driver as proposed by DBI. =item B $rc = $sth->bind_columns(\%attr, @list_of_refs_to_vars_to_bind); Supported by the driver as proposed by DBI. =item B $rows = $sth->dump_results($maxlen, $lsep, $fsep, $fh); Implemented by DBI, no driver-specific impact. =back =head2 Statement Handle Attributes =over 4 =item B (integer, read-only) Implemented by DBI, no driver-specific impact. =item B (integer, read-only) Implemented by DBI, no driver-specific impact. =item B (array-ref, read-only) Supported by the driver as proposed by DBI. =item B (array-ref, read-only) Implemented by DBI, no driver-specific impact. =item B (array-ref, read-only) Implemented by DBI, no driver-specific impact. =item B (array-ref, read-only) Supported by the driver as proposed by DBI, with the restriction, that the types are InterBase specific data-types which do not correspond to international standards. =item B (array-ref, read-only) Supported by the driver as proposed by DBI. =item B (array-ref, read-only) Supported by the driver as proposed by DBI. =item B (array-ref, read-only) Supported by the driver as proposed by DBI. =item B (string, read-only) Supported by the driver as proposed by DBI. =item B (string, read-only) Supported by the driver as proposed by DBI. =item B (integer, read-only) Not supported by the driver. =back =head1 TRANSACTION SUPPORT The transaction behavior is controlled with the attribute AutoCommit. For a complete definition of AutoCommit please refer to the DBI documentation. According to the DBI specification the default for AutoCommit is TRUE. In this mode, any change to the database becomes valid immediately. Any commit() or rollback() will be rejected. If AutoCommit is switched-off, immediately a transaction will be started. A rollback() will rollback and close the active transaction, then implicitly start a new transaction. A disconnect will issue a rollback. InterBase provides fine control over transaction behavior, where users can specify the access mode, the isolation level, the lock resolution, and the table reservation (for a specified table). For this purpose, C database handle method is available. Upon a successful C, these default parameter values will be used for every SQL operation: Access mode: read_write Isolation level: snapshot Lock resolution: wait Any of the above value can be changed using C. =over 4 =item B $dbh->func( -access_mode => 'read_write', -isolation_level => 'read_committed', -lock_resolution => 'wait', 'ib_set_tx_param' ); Valid value for C<-access_mode> is C, or C. Valid value for C<-lock_resolution> is C, or C. In Firebird 2.0, a timeout value for wait is introduced. This can be specified using hash ref as lock_resolution value: $dbh->func( -lock_resolution => { wait => 5 }, # wait for 5 seconds 'ib_set_tx_param' ); C<-isolation_level> may be: C, C, C. If C is to be used with C or C, then they should be inside an anonymous array: $dbh->func( -isolation_level => ['read_committed', 'record_version'], 'ib_set_tx_param' ); Table reservation is supported since C. Names of the tables to reserve as well as their reservation params/values are specified inside a hashref, which is then passed as the value of C<-reserving>. The following example reserves C with C lock and C with C lock and C access: $dbh->func( -access_mode => 'read_write', -isolation_level => 'read_committed', -lock_resolution => 'wait', -reserving => { foo_table => { lock => 'read', }, bar_table => { lock => 'read', access => 'protected', }, }, 'ib_set_tx_param' ); Possible table reservation parameters are: =over 4 =item C (optional) Valid values are C or C. =item C (required) Valid values are C or C. =back Under C mode, invoking this method doesn't only change the transaction parameters (as with C off), but also commits the current transaction. The new transaction parameters will be used in any newly started transaction. C can also be invoked with no parameter in which it resets transaction parameters to the default value. =back =head1 DATE, TIME, and TIMESTAMP FORMATTING SUPPORT C supports various formats for query results of DATE, TIME, and TIMESTAMP types. By default, it uses "%c" for TIMESTAMP, "%x" for DATE, and "%X" for TIME, and pass them to ANSI C's strftime() function to format your query results. These values are respectively stored in ib_timestampformat, ib_dateformat, and ib_timeformat attributes, and may be changed in two ways: =over =item * At $dbh level This replaces the default values. Example: $dbh->{ib_timestampformat} = '%m-%d-%Y %H:%M'; $dbh->{ib_dateformat} = '%m-%d-%Y'; $dbh->{ib_timeformat} = '%H:%M'; =item * At $sth level This overrides the default values only for the currently prepared statement. Example: $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($sql, $attr); =back Since locale settings affect the result of strftime(), if your application is designed to be portable across different locales, you may consider using these two special formats: 'TM' and 'ISO'. C returns a 9-element list, much like Perl's localtime(). The C format applies sprintf()'s pattern "%04d-%02d-%02d %02d:%02d:%02d.%04d" for TIMESTAMP, "%04d-%02d-%02d" for DATE, and "%02d:%02d:%02d.%04d" for TIME. C<$dbh-E{ib_time_all}> can be used to specify all of the three formats at once. Example: $dbh->{ib_time_all} = 'TM'; =head1 EVENT ALERT SUPPORT Event alerter is used to notify client applications whenever something is happened on the database. For this to work, a trigger should be created, which then calls POST_EVENT to post the event notification to the interested client. A client could behave in two ways: wait for the event synchronously, or register a callback which will be invoked asynchronously each time a posted event received. =over =item C $evh = $dbh->func(@event_names, 'ib_init_event'); Creates an event handle from a list of event names. =item C $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 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 be passed a hashref as its argument, this hashref contains pair(s) of posted event's name and its corresponding count. It is safe to call C 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 internally it is still there until the event handle goes out of scope (or undef-ed), or you call C to actually disassociate it from the event handle. =item C $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't need 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 $hash_ref = $dbh->func(@info, 'ib_database_info'); $hash_ref = $dbh->func([@info], 'ib_database_info'); Retrieve database information from current connection. =item C $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 STATEMENTS Here 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 TRANSACTION Use C<$dbh->func(..., 'set_tx_param')> instead. =item * DESCRIBE Provides information about columns that are retrieved by a DSQL statement, or about placeholders in a statement. This functionality is supported by the driver, and transparent for users. Column names are available via $sth->{NAME} attributes. =item * EXECUTE IMMEDIATE Calling do() method without bind value(s) will do the same. =item * CLOSE, OPEN, DECLARE CURSOR $sth->{CursorName} is automagically available upon executing a "SELECT .. FOR UPDATE" statement. A cursor is closed after the last fetch(), or by calling $sth->finish(). =item * PREPARE, EXECUTE, FETCH Similar functionalities are obtained by using prepare(), execute(), and fetch() methods. =back =head1 COMPATIBILITY WITH DBIx::* MODULES C is known to work with C 0.21, and C 0.87. Yuri Vasiliev > reported successful usage with Apache::AuthDBI (part of C 0.87 distribution). The driver is untested with C. Doesn't work with C. C 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, a transaction is started within prepare(), and committed automatically after the last fetch(), or within finish(). Within do(), a transaction is started right before the statement is executed, and gets committed right after the statement is executed. The transaction handle is stored within the database handle. The driver is smart enough not to override an active transaction handle with a new one. So, if you notice the snippet above, after the first fetchrow_array(), the do() is still using the same transaction context, but as soon as it has finished executing the statement, it B the transaction, whereas the next fetchrow_array() still needs the transaction context! So the secret to make this work is B. This can be done in two ways: =over 4 =item * Using AutoCommit = 0 If 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} = 1 This driver-specific attribute is available as of version 0.30. You may want to 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 also much 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 consult t/70nestedon.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 COLLATE clause, 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. The driver 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. The following example creates a generator named PROD_ID_GEN, and a trigger for table ORDERS which uses the generator to perform auto increment on field PRODUCE_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 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 a stored 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 SQL With Firebird 1 RCx and later, you can use C