my @rows = $sth->fetchrow_array; <--- Reads the first row. You never print it, though. Remove this line. my $rowcount = @rows; <--- Actually, that returns the number of *fields*, since @rows actually contains the first row. Remove this line. if ($rowcount > 0) <--- You can't keep this. You don't even need it. You could reorganize the structure to do something equivalent, but there's no need for that either.
Also, since RaiseError => 1, checking the return value of method calls is useless, since they'll never return an error. (They'll throw an exception instead.) I turned this off below.
In your dies, it would be rather useful if you printed the error message.
You're missing $sth->finish(). I thought disconnect gave a warning if this was missing.
And finally, there's no reason to not use placeholders instead of inlining the date.
so:
my $dbh = DBI->connect( "DBI:ODBC:mydsn", "user", "password", { RaiseError => 0, AutoCommit => 0 } ); my $sql = "Select * from items where procdate = ?"; my $sth = $dbh->prepare($sql); or die "\n\n Unable to prepare SQL query: $DBI::errstr\n\n"; $sth->execute($g_date) or die "\n\n Unable to execute SQL query: $DBI::errstr\n\n"; my ( $seq, $prcdate, $frb, $account, $amount, $check, $tc, $disp, $run, $batch, $pkt, $catcode, $deviceid, $volid, $imagefile, $status, $typeid, $bankId, $itemNumber, $editStatus, $exceptionReasonCode, $documentId, $postAccount, $appCode, $bundleImageOffset, $bundleImageLength, $archiveDeviceId, $archiveVolId, $archiveImageFile, $archiveImageOffset, $archiveImageLength, $userIdAmountEntry, $AUX, $PC ); $sth->bind_columns( undef, \$seq, \$prcdate, \$frb, \$account, \$amount, \$check, \$tc, \$disp, \$run, \$batch, \$pkt, \$catcode, \$deviceid, \$volid, \$imagefile, \$status, \$typeid, \$bankId, \$itemNumber, \$editStatus, \$exceptionReasonCode, \$documentId, \$postAccount, \$appCode, \$bundleImageOffset, \$bundleImageLength, \$archiveDeviceId, \$archiveVolId, \$archiveImageFile, \$archiveImageOffset, \$archiveImageLength, \$userIdAmountEntry, \$AUX, \$PC ) or die "\n\n Unable to bind columns: $DBI::errstr\n\n"; while ($sth->fetch()) { print OUTPUT ( join(',', $seq, $prcdate, $frb, $account, $amount, $check, $tc, $disp, $run, $batch, $pkt, $catcode, $deviceid, $volid, $imagefile, $status, $typeid, $bankId, $itemNumber, $editStatus, $exceptionReasonCode, $documentId, $postAccount, $appCode, $bundleImageOffset, $bundleImageLength, $archiveDeviceId, $archiveVolId, $archiveImageFile, $archiveImageOffset, $archiveImageLength, $userIdAmountEntry, $AUX, $PC ), $/ ); } $sth->finish(); $dbh->disconnect();
So many variables! Consider not binding anything and optionally use fetch_hashref isntead of fetch:
my $dbh = DBI->connect( "DBI:ODBC:mydsn", "user", "password", { RaiseError => 0, AutoCommit => 0 } ); my $sql = "Select * from items where procdate = ?"; my $sth = $dbh->prepare($sql); or die "\n\n Unable to prepare SQL query: $DBI::errstr\n\n"; $sth->execute($g_date) or die "\n\n Unable to execute SQL query: $DBI::errstr\n\n"; my $row; print OUTPUT (join(',', @$row), $/) while ($row = $sth->fetch()); $sth->finish(); $dbh->disconnect();
In reply to Re: ODBC DBI Problems
by ikegami
in thread ODBC DBI Problems
by geet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |