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

The follow code fails to produce any data, and the tracing doesn't show any errors. What am I doing wrong?

#! perl -slw use strict; use DBI; use DBD::SQLite; my $dbh = DBI->connect( 'dbi:SQLite:dbname=test.fasta.db','','' ) or die DBI::errstr; $dbh->trace( 15 ); my $sth = $dbh->prepare( 'select * from fasta' ) or die DBI->errstr; $sth->trace( 15 ); while( 1 ) { my $data = $sth->fetchrow_arrayref or die $sth->errstr; print "$data : @{ $data }"; } __END__ c:\test>sqltest DBI::db=HASH(0x4054ca0) trace level set to 0x0/15 (DBI @ 0x0/0) in + DBI 1.609-ithread (pid 5936) -> prepare for DBD::SQLite::db (DBI::db=HASH(0x4054d48)~0x4054ca0 +'select * from fasta') thr#a8e58 New 'DBI::st' (for DBD::SQLite::st, parent=DBI::db=HASH(0x4054ca0) +, id=undef) dbih_setup_handle(DBI::st=HASH(0x4170708)=>DBI::st=HASH(0x4170678) +, DBD::SQLite::st, 3d70738, Null!) dbih_make_com(DBI::db=HASH(0x4054ca0), 3c5be08, DBD::SQLite::st, 2 +32, 0) thr#a8e58 dbih_setup_attrib(DBI::st=HASH(0x4170678), Err, DBI::db=HASH(0x405 +4ca0)) SCALAR(0x3d705e8) (already defined) dbih_setup_attrib(DBI::st=HASH(0x4170678), State, DBI::db=HASH(0x4 +054ca0)) SCALAR(0x3d706a8) (already defined) dbih_setup_attrib(DBI::st=HASH(0x4170678), Errstr, DBI::db=HASH(0x +4054ca0)) SCALAR(0x3d70648) (already defined) dbih_setup_attrib(DBI::st=HASH(0x4170678), TraceLevel, DBI::db=HAS +H(0x4054ca0)) 15 (already defined) dbih_setup_attrib(DBI::st=HASH(0x4170678), FetchHashKeyName, DBI:: +db=HASH(0x4054ca0)) 'NAME' (already defined) dbih_setup_attrib(DBI::st=HASH(0x4170678), HandleSetErr, DBI::db=H +ASH(0x4054ca0)) undef (not defined) dbih_setup_attrib(DBI::st=HASH(0x4170678), HandleError, DBI::db=HA +SH(0x4054ca0)) undef (not defined) dbih_setup_attrib(DBI::st=HASH(0x4170678), ReadOnly, DBI::db=HASH( +0x4054ca0)) undef (not defined) dbih_setup_attrib(DBI::st=HASH(0x4170678), Profile, DBI::db=HASH(0 +x4054ca0)) undef (not defined) sqlite trace: prepare statement: select * from fasta at dbdimp.c line +823 <- prepare= DBI::st=HASH(0x4170708) at C:\test\sqltest.pl line 11 -> trace in DBD::_::common for DBD::SQLite::st (DBI::st=HASH(0x417 +0708)~0x4170678 15) thr#a8e58 <- trace= 15 at C:\test\sqltest.pl line 14 -> fetchrow_arrayref for DBD::SQLite::st (DBI::st=HASH(0x4170708)~ +0x4170678) thr#a8e58 sqlite trace: numFields == 3, nrow == -1 at dbdimp.c line 1065 <- fetchrow_arrayref= undef row-1 at C:\test\sqltest.pl line 17 -> errstr in DBD::_::common for DBD::SQLite::st (DBI::st=HASH(0x41 +70708)~0x4170678) thr#a8e58 <- errstr= ( undef ) [1 items] at C:\test\sqltest.pl line 17 Use of uninitialized value in die at C:\test\sqltest.pl line 17. Died at C:\test\sqltest.pl line 17. -> DESTROY for DBD::SQLite::st (DBI::st=HASH(0x4170678)~INNER) thr +#a8e58 sqlite trace: destroy statement: select * from fasta at dbdimp.c line +1202 <- DESTROY= undef at C:\test\sqltest.pl line 17 via at C:\test\sq +ltest.pl line 17 -> DESTROY for DBD::SQLite::db (DBI::db=HASH(0x4054ca0)~INNER) thr +#a8e58 <- DESTROY= undef at C:\test\sqltest.pl line 17 via at C:\test\sq +ltest.pl line 17

But if I open the db with the sqlite3 executable, it runs the same query and produces output:

c:\test>sqlite3 test.fasta.db SQLite version 3.7.3 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> select * from fasta limit 10; >seq000001:|Some other descriptive text here|GAGCGAGCC >seq000002:|Some other descriptive text here|CTCGCGGGC >seq000003:|Some other descriptive text here|CATGTCCTG >seq000004:|Some other descriptive text here|GCCAAGTTT >seq000005:|Some other descriptive text here|CCTACGACT >seq000006:|Some other descriptive text here|GATGTCAGT >seq000007:|Some other descriptive text here|ACATCGCGA >seq000008:|Some other descriptive text here|ACGGCCATA >seq000009:|Some other descriptive text here|ATCGTCCCC >seq000010:|Some other descriptive text here|CCCGTGTCA sqlite> select count(*) from fasta; 1058202

Is there anything obviously wrong in my code; or visible in the trace?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re: DBD::SQLite failing to return data?
by erix (Prior) on Nov 11, 2010 at 00:04 UTC

    no execute (after prepare)?

      that was my initial thought also. so what happens if you execute?
      the hardest line to type correctly is: stty erase ^H

      Bingo. It's been too long... Many thanks.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        also are you wanting the data fetch loop to always exit using die?..as there's an endless loop.
        the hardest line to type correctly is: stty erase ^H