Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Bug #18203 Type introspection breaks with associative arrays if names are identical
Submitted: 2011-01-20 17:16 UTC
From: sjamaan Assigned: danielc
Status: Closed Package: MDB2 (version 2.4.1)
PHP Version: 5.3.1 OS: NetBSD/amd64 5.0
Roadmaps: 2.5.0b4    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 49 - 3 = ?

 
 [2011-01-20 17:16 UTC] sjamaan (Peter Bex)
Description: ------------ 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", true); $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

Comments

 [2011-01-20 18:53 UTC] sjamaan (Peter Bex)
 [2011-01-21 20:00 UTC] sjamaan (Peter Bex)
 [2011-01-21 20:01 UTC] sjamaan (Peter Bex)
I just added a second patch that applies the same change to other database types than postgres.
 [2011-03-06 17:33 UTC] quipo (Lorenzo Alberton)
-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!
 [2011-12-16 22:44 UTC] danielc (Daniel Convissor)
-Status: Closed +Status: Open -Assigned To: quipo +Assigned To: danielc
The changes are incomplete. There is a call to setResultTypesAssoc() in MDB2_Driver_Common::_wrapResult(). That function does not exist. Also, the changes only covered some methods. For example, it seems to have missed MDB2_BufferedResult_oci8::fetchRow(), and possibly others.
 [2011-12-20 01:37 UTC] danielc (Daniel Convissor)
-Status: Assigned +Status: Closed
Fixed in revisions 321234 and 321210. They'll be in the next release (which will either be 2.5.0b4 or 2.5.0RC1). This is related to bug #9502.