Edit report at http://pear.php.net/bugs/bug.php?id=18203&edit=1

ID: 18203
Updated by: l.alberton@quipo.it
Reported By: peter dot bex at solide-ict dot nl
Summary: Type introspection breaks with associative arrays if
names are identical
-Status: Open
+Status: Closed
Type: Bug
Package: MDB2
Operating System: NetBSD/amd64 5.0
Package Version: 2.4.1
PHP Version: 5.3.1
-Assigned To:
+Assigned To: quipo
Roadmap Versions:
New Comment:

-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: quipo
This bug has been fixed in SVN.

If this was a documentation problem, the fix will appear on pear.php.net
by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should
be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.


Thanks a lot for the patch!

Previous Comments:

[2011-01-21 15:01:11] sjamaan

I just added a second patch that applies the same change to other
database types than postgres.


[2011-01-21 15:00:47] sjamaan

Added #patch


[2011-01-20 13:53:11] sjamaan

Added #patch bug:18203;patch:assoc_fix.patch;revision:1295531591;.


[2011-01-20 12:16:06] sjamaan

When retrieving a result using fetchRow in FETCHMODE_ASSOC, the returned
array types are incorrect if the query contained several columns with
the same name.

This is caused by the fact that when setResultTypes is called, the types
array contains numeric keys. So for example if you obtain an integer,
another integer with the same name and a textfield, you have three
items. The associative array will contain two entries (one of the
identical fields and one textfield), which are mapped to the entries
with the corresponding index, after converting string keys to numbers.

This happens mostly when doing SELECT * on joined tables, but even
though it's bad practice to select *, mdb2 shouldn't fail this hard on
such things.

The attached patch fixes the problem for me.

Test script:
// Assuming $connection is a previously set up MDB2 connection
$res = $connection->query("SELECT 1 as id, 2 as id, 'foo' as title",
$record = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
var_dump($record); // Prints 'id' => int 2, 'title' => int 0

Expected result:
I expect 'id' => int 2, 'title' => string 'foo' to be printed.

Actual result:
'id' => int 2, 'title' => int 0


Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
postedMar 6, '11 at 11:31a
activeMar 6, '11 at 11:31a

1 user in discussion

L Alberton: 1 post



site design / logo © 2022 Grokbase