Posted on 2006-12-27 19:56:36-08 by jcasadonte
full_column_names pragma problem

After upgrading to the latest version of DBD-SQLite (for either the 2.x or 3.x version) I have encountered a problem in my previously working code. Initially I upgraded from DBD-SQLite v0.23 to v.31, and then I tried converting to SQLite 3.x using DBD-SQLite 1.12 (which according to the CHANGES doc is SQLite version 3.3.5, but it is reporting as version 3.3.3).

When I execute the following query:

SELECT E.*, P.Name FROM Edition AS E, Publisher AS P WHERE E.GameID = 126 AND E.PublisherID = P.PublisherID ORDER BY E.Name, E.EditionID

I am receiving the following:

$data->{'EditionID'}: {264}
$data->{'GameID'}: {260}
$data->{'Name'}: {Tresham Games}
$data->{'Own'}: {1}
$data->{'PublisherID'}: {88}

instead of the expected:

$data->{'E.EditionID'}: {264}
$data->{'E.GameID'}: {260}
$data->{'E.Name'}: {1825 Unit 3}
$data->{'E.Own'}: {1}
$data->{'E.PublisherID'}: {88}
$data->{'P.Name'}: {Tresham Games}

I have tried setting the full_column_names pragma on via:

my $dbh = DBI->connect($db);
...
$dbh->do('PRAGMA short_column_names=0');
$dbh->do('PRAGMA full_column_names=1');

But this has had no effect on what is being returned to me. I did check, and the pragmas are indeed being set properly inside of the engine (AFAICT). Any ideas? Thanks!

joe
Direct Responses: 3923 | Write a response
Posted on 2006-12-28 00:53:58-08 by jcasadonte in response to 3913
Re: full_column_names pragma problem

One of the nice folks on the SQLite mailing list pointed this out to me. It seems like it is the cause of the problems....

See "drop table name from field name" below...

SV * sqlite_st_FETCH_attrib (SV *sth, imp_sth_t *imp_sth, SV *keysv) { char *key = SvPV_nolen(keysv); SV *retsv = NULL; int i,n; if (!DBIc_ACTIVE(imp_sth)) { return NULL; } /* warn("fetch: %s\n", key); */ i = DBIc_NUM_FIELDS(imp_sth); if (strEQ(key, "NAME")) { AV *av = newAV(); /* warn("Fetch NAME fields: %d\n", i); */ av_extend(av, i); retsv = sv_2mortal(newRV(sv_2mortal((SV*)av))); for (n = 0; n < i; n++) { /* warn("Fetch col name %d\n", n); */ const char *fieldname = sqlite3_column_name(imp_sth->stmt, n); if (fieldname) { /* warn("Name [%d]: %s\n", n, fieldname); */ char *dot = instr(fieldname, "."); if (dot) /* drop table name from field name */ fieldname = ++dot;

The correct behavior would, I think, be to pass along whatever SQLite passes back, and let end-user control it via the aforementioned pragmas. More information on the pragmas can be had at:

http://www.sqlite.org/pragma.html

joe
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.