|
| Table of Contents
SYNOPSIS perldoc DBD::InterBase::FAQ DESCRIPTION This document serves to answer the most frequently asked questions regarding the uses of DBD::InterBase . Current version refers to
DBD::InterBase version 0.30 available on SourceForge.
SQL Operations
Why do some operations performing positioned update and delete fail when AutoCommit is on?
$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 AutoCommit is on, 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 commits the transaction, whereas the next fetchrow_array() still needs the transaction context! So the secret to make this work is to keep the transaction open. This can be done in two ways:
Nested statement handles break under AutoCommit mode.
{ $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.
Why do placeholders fail to bind, generating unknown datatype error message?
$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 DBD::InterBase . The
driver just passes SQL statements through the engine.
How to do automatic increment for a specific field?
$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");
How can I perform LIMIT clause as I usually do in MySQL?
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( "EXECUTE PROCEDURE paging_forum(5,5) RETURNING_VALUES :id, :title, :ctime, :author");With Firebird 1 RCx and later, you can use SELECT FIRST :
SELECT FIRST 10 SKIP 30 * FROM table_forum; FIRST x and SKIP x are both optional. FIRST limits the number of
rows to return, SKIP should be self-explanatory.
Uses of attributes
How can I use the date/time formatting attributes?
$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);
Can I set the date/time formatting attributes between prepare and fetch?
Can I change ib_dialect after DBI->connect ?
Why do execute(), do() method and rows() method always return -1 upon
a successful operation?
Sources for Help
I can't find the answer for my question here, where should I direct my question?
The Development Project
How can I join the development project?
Is there a mailing list for DBD::InterBase?
Where can I get the latest release of DBD::InterBase ?
AUTHORS AND COPYRIGHT Copyright (C) 2000-2002, Edwin Pratomo edpratomo@cpan.org. Daniel Ritz daniel.ritz@gmx.ch also writes necessary updates. Michael Samanov samanov@yahoo.com contributed some important correction. |
$Revision: 1.4 $, $Date: 2001/02/08 12:14:00 $, $Author: edwin $ |