Skip Menu |

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 12347
Status: resolved
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: shenkin [...] schrodinger.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.07
Fixed in: (no value)



Subject: SEGV when accessing $sth->{TYPE}->[$i] for a VIEW
This seems similar to Case 8564, but maybe isn't exactly the same. I get the SEGV reproducibly on the first attempt to get TYPE, but only for a VIEW, not for a TABLE. I have no problem getting NAME, as 8564 reports. But 8564 seems to indicate that the symptom doesn't occur reproducibly, so perhaps I've just not seen it yet. In case this is the same bug (after all, they both involve access to metadata), perhaps having a reproducible case will facilitate debugging. Here is a Perl program, the program output, and a stack trace following the SEGV. As in Case 8564, I'm using DBD::SQLite, which implies sqlite version 3.0.8. I've also reported this issue to the sqlite-users list. Show quoted text
> uname -a
Linux florence 2.4.20-24.7smp #1 SMP Mon Dec 1 13:18:03 EST 2003 i686 unknown Show quoted text
> perl -v
This is perl, v5.8.6 built for i686-linux-thread-multi Thanks, -Peter Shenkin. Show quoted text
---------- program ------------------- # $Id: dump_sqlite.pl,v 1.4 2005/04/14 21:01:14 shenkin Exp $ # Dump an sqlite DB to stdout # Usage: "dump_sqlite <sqlite file name> use strict; use Carp; use DBI; # get db name from cmdline: my $dbfile = $ARGV[0]; # make sure db is there: if( not -e $dbfile ) { confess "dumpdb: could not find sqlite file $dbfile\n"; } # connect to db: my $dbh = my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "", { AutoCommit=>0,RaiseError=>1 } ) or confess "Could not connect to database $dbfile\n"; print "Connected to database $dbfile\n" . " Binary values are shown as 'BLOB' and NULL values as 'NULL'\n"; print "DBI->installed_versions:\n"; DBI->installed_versions; # NB: "all_properties" is a view: my $sth = $dbh->prepare(" SELECT * FROM all_properties" ); print "sth->{NUM_OF_FIELDS}= $sth->{NUM_OF_FIELDS}\n"; print "sth->{NAME}->[1]= $sth->{NAME}->[1]\n"; print "sth->{TYPE}->[1]= $sth->{TYPE}->[1]\n";
---------- program output ------------------- Connected to database testform-node1_raw.sqlite Binary values are shown as 'BLOB' and NULL values as 'NULL' DBI->installed_versions: Perl : 5.008006 (i686-linux-thread-multi) OS : linux (2.4.20-28.7) DBI : 1.47 DBD::Sponge : 11.10 DBD::SQLite : 1.07 DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlClient.pm in @INC DBD::File : 0.32 DBD::ExampleP : 11.12 DBD::DBM : 0.02 sth->{NUM_OF_FIELDS}= 3 sth->{NAME}->[1]= name Segmentation fault (core dumped)
---------- stack trace ------------------- #0 0x080bdac5 in Perl_newSVpv () #1 0x40230996 in sqlite_st_FETCH_attrib () from /zone1/shenkin/bld/main/Linux-x86-g.ifort/mmshare-v1.5/lib/Linux-x86/perl5/site_perl/5.8.6/i686-linux-thread-multi/auto/DBD/SQLite/SQLite.so #2 0x40222a91 in XS_DBD__SQLite__st_FETCH_attrib () from /zone1/shenkin/bld/main/Linux-x86-g.ifort/mmshare-v1.5/lib/Linux-x86/perl5/site_perl/5.8.6/i686-linux-thread-multi/auto/DBD/SQLite/SQLite.so #3 0x4020103c in XS_DBI_dispatch () from /zone1/shenkin/bld/main/Linux-x86-g.ifort/mmshare-v1.5/lib/Linux-x86/perl5/site_perl/5.8.6/i686-linux-thread-multi/auto/DBI/DBI.so #4 0x080b3ee4 in Perl_pp_entersub () #5 0x080ad680 in Perl_runops_standard () #6 0x08063939 in S_call_body () #7 0x080634b6 in Perl_call_sv () #8 0x080a49e1 in S_magic_methpack () #9 0x080a4add in Perl_magic_getpack () #10 0x080a29a0 in Perl_mg_get () #11 0x080b45f3 in Perl_vivify_ref () #12 0x080b1866 in Perl_pp_helem () #13 0x080ad680 in Perl_runops_standard () #14 0x08063048 in S_run_body () #15 0x08062d59 in perl_run () #16 0x0805fc45 in main () #17 0x400c11c4 in __libc_start_main () from /lib/libc.so.6
Still see this with DBD::SQLite 1.11
From: Nigel Metheringham <nigel.metheringham [...] dev.intechnology.co.uk>
In dbdimp.c, around line 674:- else if (strEQ(key, "TYPE")) { AV *av = newAV(); av_extend(av, i); retsv = sv_2mortal(newRV(sv_2mortal((SV*)av))); for (n = 0; n < i; n++) { const char *fieldtype = sqlite3_column_decltype(imp_sth->stmt, n); int type = sqlite3_column_type(imp_sth->stmt, n); /* warn("got type: %d = %s\n", type, fieldtype); */ type = type_to_odbc_type(type); /* av_store(av, n, newSViv(type)); */ av_store(av, n, newSVpv(fieldtype, 0)); } } sqlite3_column_decltype returns NULL for a (View) column which is the result of a function - ie count(*). Suggest that this is worked round by forcing a null result to "UNKNOWN", "INTEGER" (good guess for sqlite functions) or "VARCHAR" (pretty much what sqlite uses everywhere).
Subject: Workround patch
From: Nigel Metheringham <nigel.metheringham [...] dev.intechnology.co.uk>
changing the av_store line to if (fieldtype == NULL) { av_store(av, n, newSVpv("INTEGER", 0)); } else { av_store(av, n, newSVpv(fieldtype, 0)); } does pretty much the same thing. In particular it stops DBIx::Class core dumping with views :-/
Will be fixed in 1.13.