PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB2_Driver_mysql » Bug #9283

Lack of support for MySQL's BINARY/VARBINARY makes the Driver explode

Details

Submitted2006-11-08 22:08 UTC
Fromtom at whyscream dot net
Assignedquipo
StatusClosed
PackageMDB2_Driver_mysql
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2006-11-08 22:08 UTC] tom at whyscream dot net

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