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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.