Details
Description
SQLite is unlike other PDO drivers in that when the result set is returned from a SELECT statement as an associative array of columns => values, and the query contained correlation names, the correlation names are included in the array keys:
SELECT f.column1 FROM table1 AS f
Returns a result set where the key is "f.column1" whereas in other RDBMS's the key is "column1".
ADODB solves this by creating a distinct driver called "sqlitepo" that strips the leading prefix from the array key during the fetch operation.
http://www.xaraya.com/documentation/phpxref/nav.html?xaradodb/drivers/adodb-sqlitepo.inc.php.source.html
We need to do something similar, by extending the following functions in Zend_Db_Adapter_Pdo_Sqlite:
- fetchAssoc()
- fetchAll() when fetch mode is FETCH_ASSOC
SQLite supports pragma statements to control this behavior.
See http://www.sqlite.org/pragma.html
For example, the following statements should help:
However, there are bug reports that these pragmas don't have the desired effect. And in fact that's what I'm seeing too in the unit tests.
I'm going to implement the pragma statements in the _connect() method of the Pdo_Sqlite adapter class, knowing that at least in the current version of SQLite, it does not work. Perhaps in a future version, it will be fixed.
I'm adding unit tests to tests/Zend/Db/Adapter/Pdo/SqliteTest.php for the cases that fail because they insist on returning result sets with keys like "table"."column".
We can't strip the table portion out of the keys as they do in ADODB, because this is a PDO Adapter. The result set is returned in a PDOStatement, not a Zend_Db_Statement.