Perl + Interbase. Выборка из нескольких таблиц одновременно.

Простая с виду программа доставляет массу хлопот:
use DBI;
my $db_name = '/interbase/db/sprav.gdb';
my $db_user = 'SYSDBA';
my $db_pass = 'masterkey';
$dbh = DBI->connect("dbi:InterBase(AutoCommit=>1):dbname=$db_name;ib_dialect=3;ib_charset=win1251", $db_user, $db_pass) || die($DBI::errstr);
$sth = $dbh->prepare("select uid from users");
while ($uid=$sth->fetchrow) {
  $sth2 = $dbh->prepare("select count(goods_id) from goods where uid='$uid'");
  $cnt = $sth2->fetchrow;
  print "$uid - $cnt \n";

на выходе имеем:
DBD::InterBase::st fetchrow failed: Unknown cursor
Припоминаю, что были у меня траблы когда я одновременно фетчил из двух мест (таблиц). Может не поддерживается такой возможности dbi:InterBase.
Добавьте в начало скрипта (после соединения с базой, естественно) строчку:

$dbh->{AutoCommit} = 0;
Помогло. И какое это оказывает влияние ?

For example, the following code snippet fails:
$sth = $dbh->prepare(
"SELECT * FROM ORDERS WHERE user_id < 5 FOR UPDATE OF comment");
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!

TopList Rambler's Top100