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

Bug #9283 Lack of support for MySQL's BINARY/VARBINARY makes the Driver explode
Submitted: 2006-11-08 22:08 UTC
From: tom at whyscream dot net Assigned: quipo
Status: Closed Package: MDB2_Driver_mysql (version 1.3.0)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2006-11-08 22:08 UTC] tom at whyscream dot net (Tom Hendrikx)
Description: ------------ The MySQL column types BINARY and VARBINARY are currently not supported by MDB2_Driver_mysql. After some research I found out that they don't exist in MDB2_Driver_Datatype_mysql::mapNativeDatatype(). When someone tries to use map the datatype ob such a column, the method returns a PEAR_Error, which is not handled properly by other code, f.i. MDB2_Driver_Reverse_mysql::tableInfo(), which never expects an object returned by mapNativeDatatype(). This makes the script end with a fatal error. I fixed it by mapping BINARY and VARBINARY equal to BLOB columns, and by making tableInfo() check for the PEAR_Error. Not sure if (VAR)BINARY treating as BLOB is really fair, but my main issue was keeping the driver from exploding. See patch below. Both issues also exist in the mysqli driver, and the problematic pattern in MDB2_Driver_Reverse_mysql::tableInfo() also exists in the pgsql and sqlite driver (and probably others as well), so when unknown column types will be mapped, the same problem will arise. Test script: --------------- Patch for mysql driver: Index: MDB2/Driver/Datatype/mysql.php =================================================================== @@ -432,7 +432,9 @@ case 'tinyblob': case 'mediumblob': case 'longblob': case 'blob': + case 'binary': + case 'varbinary': $type[] = 'blob'; $length = null; break; Index: MDB2/Driver/Reverse/mysql.php =================================================================== @@ -97,7 +97,11 @@ $column = array_change_key_case($column, $db->options['field_case']); } if ($field_name == $column['name']) { - list($types, $length, $unsigned, $fixed) = $db->datatype->mapNativeDatatype($column); + $mapped_datatype = $db->datatype->mapNativeDatatype($column); + if(PEAR::IsError($mapped_datatype)) { + return $mapped_datatype; + } + list($types, $length, $unsigned, $fixed) = $mapped_datatype; $notnull = false; if (empty($column['null']) || $column['null'] !== 'YES') { $notnull = true; =================================================================== Expected result: ---------------- Return interesting data, or a PEAR_Error to handle. Actual result: -------------- Following nice fatal error: Fatal error: Cannot use object of type MDB2_Error as array in <...>/php/MDB2/Driver/Reverse/mysql.php on line 104

Comments

 [2006-11-16 09:36 UTC] quipo (Lorenzo Alberton)
This bug has been fixed in CVS. 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.