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

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

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

Previous Comments:

[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 @
postedJan 21, '11 at 1:59p
activeJan 21, '11 at 1:59p

1 user in discussion

Peter Bex: 1 post



site design / logo © 2022 Grokbase