Hi,

I am having problems with the output from a query. I am running perl on Win32, and I am connecting to an MS SQL database using the DBI ODBC driver.

I am doing a query by date. I use bind_columns to work with the results. I use a 'while (fetch())' to write out to a file.

My problem is the first row of my results isn't printed. Everything else prints out just fine. If I dump the array using "print OUTPUT "@rows";" the first row is there, so I know it is coming in my result set.

Is there a limitation on the number of columns I can return? Is there a better way to do this? I am programming and perl newbie.
This is essentially my script:

#!perl use strict; use DBI; my $g_date = '09/23/03'; open (OUTPUT, ">$somefile"); #create a header with column names print OUTPUT "seq,prcdate,frb,account,amount,checknum,tc,disp,run,batc +h,pkt,catcode,deviceid,volid,imagefile,status,typeid,bankId,itemNumbe +r,editStatus,exceptionReasonCode,documentId,postAccount,appCode,bundl +eImageOffset,bundleImageLength,archiveDeviceId,archiveVolId,archiveIm +ageFile,archiveImageOffset,archiveImageLength,userIdAmountEntry,AUX,P +C\n"; my $dbh = DBI ->connect ("DBI:ODBC:mydsn", "user", "password", { Raise +Error => 1, AutoCommit => 0 }); my $sql = "Select * from items where procdate = \'$g_date\' "; my $sth = $dbh->prepare($sql); $sth->execute()or die "\n\n Unable to execute SQL query!\n\n"; my ($seq,$prcdate,$frb,$account,$amount,$check,$tc,$disp,$run,$batch,$ +pkt,$catcode,$deviceid,$volid,$imagefile,$status,$typeid,$bankId,$ite +mNumber,$editStatus,$exceptionReasonCode,$documentId,$postAccount,$ap +pCode,$bundleImageOffset,$bundleImageLength,$archiveDeviceId,$archive +VolId,$archiveImageFile,$archiveImageOffset,$archiveImageLength,$user +IdAmountEntry,$AUX,$PC); my @rows = $sth->fetchrow_array; my $rowcount = @rows; if ($rowcount > 0) # don't do anything when no results { $sth-> bind_columns( undef, \$seq, \$prcdate, \$frb, \$account, + \$amount, \$check, \$tc, \$disp, \$run, \$batch, \$pkt, \$catcode, \ +$deviceid, \$volid, \$imagefile, \$status, \$typeid, \$bankId, \$item +Number, \$editStatus, \$exceptionReasonCode, \$documentId, \$postAcco +unt, \$appCode, \$bundleImageOffset, \$bundleImageLength, \$archiveDe +viceId, \$archiveVolId, \$archiveImageFile, \$archiveImageOffset, \$a +rchiveImageLength, \$userIdAmountEntry, \$AUX, \$PC); while( $sth->fetch() ) { print OUTPUT "$seq,$prcdate,$frb,$account,$amount,$check, +$tc,$disp,$run,$batch,$pkt,$catcode,$deviceid,$volid,$imagefile,$stat +us,$typeid,$bankId,$itemNumber,$editStatus,$exceptionReasonCode,$docu +mentId,$postAccount,$appCode,$bundleImageOffset,$bundleImageLength,$a +rchiveDeviceId,$archiveVolId,$archiveImageFile,$archiveImageOffset,$a +rchiveImageLength,$userIdAmountEntry,$AUX,$PC\n"; } } $dbh->disconnect(); close OUTPUT;

In reply to 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.