Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: viper.xz [...] gmail.com
Cc:
AdminCc:

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



Subject: Incorrect Implementation of column names within sqlite_st_FETCH_attrib
Description: Current implementation of fetch_hashref currently strips the table names from the hash values. This should be removed as this implementation overrides the SQL implementation of how column names are displayed and prevents manual setting of column names that contain a '.'. e.g. SELECT 1 as 'a.a', 1 as 'b.a'; SQL Implementation: PRAGMA full_column_names = 0 | 1; PRAGMA short_column_names = 0 | 1; (Full column names require full_column_names=1 and short_column_names=0). File: dbdimp.c Function: sqlite_st_FETCH_attrib Snippet: 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; av_store(av, n, newSVpv(fieldname, 0)); } The following lines should be removed: char *dot = instr(fieldname, "."); if (dot) /* drop table name from field name */ fieldname = ++dot;
From: viper.xz [...] gmail.com
Let me try and explain this better (as this is quite a bad bug). Quick Example using sqlite command line tool (showing correct implementation): Show quoted text
sqlite> .headers on sqlite> CREATE TABLE test (a); sqlite> INSERT INTO test VALUES (1); sqlite> SELECT * FROM test;
a 1 Now we try enable full table headers. Show quoted text
sqlite> PRAGMA full_column_names = 1; sqlite> PRAGMA short_column_names = 0; sqlite> SELECT * FROM test;
test.a 1 Notice how the field name returned now contains the table name. If we were to execute the SELECT * FROM test; using DBD::SQLite's fetch_hashref AFTER first executing the two PRAGMA commands we would expect it to return the following: { "test.a" => 1 } HOWEVER, it currently returns. { "a" => 1 } This causes problems if you have two fields with the same name in two tables and want to be able to see the complete field name, or if you manually define a field name using AS that contains a '.'. The cause of the problem lies in dbdimp.c where the lines: Show quoted text
> char *dot = instr(fieldname, "."); > if (dot) /* drop table name from field name */ > fieldname = ++dot;
manually remove any information preceeding the `.` (in this case `test.`) from the field names returned. Removing those lines from dbdimp.c fix this problem and should not have any adverse effects on existing code as sqlite returns only the end part of the field names by default unless the two PRAGMA queries have first been initiated. I am currently having to remove these lines manually from releases of DBD::SQLite that I install and I would like to see this bug fixed ASAP as it overrides functionality within SQLite, with an incorrect perl implementation.
Your change has been applied and should appear in 1.19_08. Regression test rt_31324_full_names.t was also added.