Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Getting error when selecting from database

by Anonymous Monk
on Jun 12, 2002 at 21:58 UTC ( [id://174030]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am selecting a column from a database and trying to print it to the screen. I keep getting the following error:
DBD::ODBC::st fetchrow_array failed: [Microsoft][ODBC Microsoft Access + Driver ring data, right truncated on column number 1 (summary) (SQL-01004)(DB +D: st_f h/SQLFetch (long truncated) err=1) at uab.pl line 23.
This is the code I am using to get the data:
$dbh = DBI->connect('dbi:ODBC:StockDB') || die "Error opening DB: $DBI +::errstr\n"; $sth = $dbh->prepare("SELECT NOTES FROM QTABLE"); $sth->execute() or die "Couldn't execute query: $DBI::errstr\n"; while (my @row = $sth ->fetchrow_array){ print "@row\n"; } $sth->finish();
Any Suggestions? Thanks, Aspiring Monk

Replies are listed 'Best First'.
Re: Getting error when selecting from database
by Kanji (Parson) on Jun 12, 2002 at 22:29 UTC

    You don't say what type of column NOTES is, but if it's potentially large (like a BLOB, (LONG)TEXT or MEMO field) then you need to play with DBI->connect's LongTruncOk and/or LongReadLen attributes.

    $dbh = DBI->connect( 'dbi:ODBC:StockDB', '', '', { LongTruncOk => 1, LongReadLen => 1024 * 64, # 64K }, ) || ...

        --k.


      It is a memo field. It's pretty long.
Re: Getting error when selecting from database
by dree (Monsignor) on Jun 12, 2002 at 22:31 UTC
Re: Getting error when selecting from database
by DamnDirtyApe (Curate) on Jun 12, 2002 at 22:30 UTC

    I've never come across this problem before myself, but a quick scan of the DBI documentation reveals this:

    By default, LongTruncOk is false and so fetching a long value that needs to be truncated will cause the fetch to fail. (Applications should always be sure to check for errors after a fetch loop in case an error, such as a divide by zero or long field truncation, caused the fetch to terminate prematurely.)

    Hopefully that'll set you on the right path.

    Update: A couple more things: here's the DBI documentation, and also a guide on how to read the friendly manual.


    _______________
    D a m n D i r t y A p e
    Home Node | Email
Re: Getting error when selecting from database
by ehdonhon (Curate) on Jun 12, 2002 at 22:33 UTC

    Right before you do your connect, try adding this:

    DBI->trace( 1, 'DBI-TRACE' );

    That will put a debugging file named DBI-TRACE in your current directory with useful information. You can increment the 1 higher to get more debugging info. Maybe that will help you track down whatever is going wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://174030]
Approved by ehdonhon
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-18 15:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found