#32736 [Opn->Asn]: Select table.field returns wrong result index
| From: | derick@php.net | Date: | Mon, 18 Apr 2005 06:41:02 +0000 |
| Subject: | #32736 [Opn->Asn]: Select table.field returns wrong result index | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-77760@lists.php.net to get a copy of this message | ||
ID: 32736
Updated by: derick@php.net
Reported By: bart at mediawave dot nl
-Status: Open
+Status: Assigned
-Bug Type: SQLite related
+Bug Type: Feature/Change Request
Operating System: WinXP
PHP Version: 5.0.4
-Assigned To:
+Assigned To: wez
New Comment:
It can be, but don't count on it being changed... assigned to the
maintainer.
Previous Comments:
------------------------------------------------------------------------
[2005-04-17 22:57:02] bart at mediawave dot nl
Can this be changed to a feature / change request?
I've been looking around on the web. As far as I can see there are no
other SQL system that give results in such a way. This just makes it
unnecessarily difficult to write database independent code.
The only advantage I can think of for such a result is when tables that
have identical fieldnames need to be joined. But SQL (and SQLite)
already has aliases to solve that.
Maybe there should be a new SQLite result type constant for this?
------------------------------------------------------------------------
[2005-04-17 12:27:51] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Sorry, but this is how SQLite works.
------------------------------------------------------------------------
[2005-04-17 12:23:04] bart at mediawave dot nl
Description:
------------
With the SQLite functions:
The problem occurs when selecting fields in a tablename.fieldname
manner. Example:
SELECT test.myfield, test.otherfield FROM test
The result array will have ['tablename.fieldname'] as index. This
should be just ['fieldname'] as index.
Reproduce code:
---------------
<?php
$dbfile = 'db/test2db.db';
if (!file_exists($dbfile)) {
$setup = "
CREATE TABLE test (myfield varchar(50), otherfield varchar(50));
INSERT INTO test (myfield, otherfield) VALUES ('value1', 'value1');
INSERT INTO test (myfield, otherfield) VALUES ('value2', 'value2');
";
}
$connectionId = sqlite_open($dbfile, 0666, $sqliteerror);
if ($setup)
sqlite_exec($connectionId, $setup);
$sql = 'SELECT test.myfield, test.otherfield FROM test';
$resultId = sqlite_query($connectionId, $sql);
while ($result = sqlite_fetch_array($resultId, SQLITE_ASSOC))
print_r($result);
?>
Expected result:
----------------
Array
(
[myfield] => value1
[otherfield] => value1
)
Array
(
[myfield] => value2
[otherfield] => value2
)
Actual result:
--------------
Array
(
[test.myfield] => value1
[test.otherfield] => value1
)
Array
(
[test.myfield] => value2
[test.otherfield] => value2
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32736&edit=1