Home » Database » MDB2 » Bug #6835
getTableFieldDefinition() only works in compatibility mode lower-case
Details
| Submitted | 2006-02-19 08:56 UTC |
|---|---|
| From | gramlich at eosc dot de |
| Assigned | lsmith |
| Status | Closed |
| Package | MDB2 |
| PHP Version | 4.3.8 |
| Roadmaps | (Not assigned) |
Comments
[2006-02-19 08:56 UTC] gramlich at eosc dot de
Description:
------------
file MDB2/Driver/Reverse/mysql.php
mysql.php,v 1.41
function getTableFieldDefinition($table, $field_name)
Function returns error (line 136), if (options['portability'] & MDB2_PORTABILITY_FIX_CASE) == 0
or if (options['portability'] & MDB2_PORTABILITY_FIX_CASE) == 1 and ($db->options['field_case'] != CASE_LOWER).
Reason: The assignment in line 80
$columns = $db->queryAll("SHOW COLUMNS FROM $table", null, MDB2_FETCHMODE_ASSOC);
creates an array, with sub-array keys that depend on the FIX_CASE.
I.e. $column['Field'] or $column['FIELD'] or $column['field'] may be set.
But only $column['field'] is respected in line 85.
Problem continues in the following lines, as keys are expected in lower case.
----------
FIX:
change lines 80-83 to
// START FIX
// This workaround forces lower case column keys in associated array
// Store present configuration
$presentOptions['portability'] = $db->options['portability'];
$presentOptions['field_case'] = $db->options['field_case'];
$db->options['portability'] = $db->options['portability'] | MDB2_PORTABILITY_FIX_CASE;
$db->options['field_case'] = CASE_LOWER;
// Query structure as before.
$columns = $db->queryAll("SHOW COLUMNS FROM $table", null, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($columns)) {
return $columns;
}
// Restore options
$db->options['portability'] = $presentOptions['portability'];
$db->options['field_case'] = $presentOptions['field_case'];
// END FIX
[2006-02-22 20:33 UTC] gramlich at eosc dot de
Hi Lucas
here we go.
Linebreaks occur here, should I send it as an attachment by mail?
--- mysqlOrig.php 2006-02-19 09:41:32.000000000 +0100
+++ mysql.php 2006-02-19 09:48:18.000000000 +0100
@@ -77,10 +77,22 @@
if (PEAR::isError($result)) {
return $result;
}
+ // START FIX
+ // This workaround forces lower case column keys in associated array
+ // Store present configuration
+ $presentOptions['portability'] = $db->options['portability'];
+ $presentOptions['field_case'] = $db->options['field_case'];
+ $db->options['portability'] = $db->options['portability'] | MDB2_PORTABILITY_FIX_CASE;
+ $db->options['field_case'] = CASE_LOWER;
+ // Query structure as before.
$columns = $db->queryAll("SHOW COLUMNS FROM $table", null, MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($columns)) {
return $columns;
}
+ // Restore options
+ $db->options['portability'] = $presentOptions['portability'];
+ $db->options['field_case'] = $presentOptions['field_case'];
+ // END FIX
foreach ($columns as $column) {
$column['name'] = $column['field'];
unset($column['field']);