From b574a9830684400f84d52d4f6d06a0f81115f099 Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 30 Aug 2007 01:53:53 +0000 Subject: [PATCH] Adding recent fixes to DboDb2 driver git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5613 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_db2.php | 38 ++++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_db2.php b/cake/libs/model/datasources/dbo/dbo_db2.php index bd85b57ad..d5efd07e2 100644 --- a/cake/libs/model/datasources/dbo/dbo_db2.php +++ b/cake/libs/model/datasources/dbo/dbo_db2.php @@ -28,7 +28,6 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ - /** * IBM DB2 for DBO * @@ -158,23 +157,28 @@ class DboDb2 extends DboSource { function _execute($sql) { // get result from db $result = db2_exec($this->connection, $sql); - - // build table/column map for this result - $map = array(); - $num_fields = db2_num_fields($result); - $index = 0; - $j = 0; - - while ($j < $num_fields) { - $columnName = strtolower(db2_field_name($result, $j)); - $tableName = substr($sql, 0, strpos($sql, '.' . $columnName)); - $tableName = substr($tableName, strrpos($tableName, ' ') + 1); - $map[$index++] = array($tableName, $columnName); - $j++; + + if(!is_bool($result)){ + // build table/column map for this result + $map = array(); + $num_fields = db2_num_fields($result); + $index = 0; + $j = 0; + $offset = 0; + + while ($j < $num_fields) { + $columnName = strtolower(db2_field_name($result, $j)); + $tmp = strpos($sql, '.' . $columnName, $offset); + $tableName = substr($sql, $offset, ($tmp-$offset)); + $tableName = substr($tableName, strrpos($tableName, ' ') + 1); + $map[$index++] = array($tableName, $columnName); + $j++; + $offset = strpos($sql, ' ', $tmp); + } + + $this->_resultMap[$result] = $map; } - $this->_resultMap[$result] = $map; - return $result; } /** @@ -217,7 +221,7 @@ class DboDb2 extends DboSource { while (db2_fetch_row($result)) { $fields[strtolower(db2_result($result, 'COLUMN_NAME'))] = array( - 'type' => db2_result($result, 'TYPE_NAME'), + 'type' => strtolower(db2_result($result, 'TYPE_NAME')), 'null' => db2_result($result, 'NULLABLE'), 'default' => db2_result($result, 'COLUMN_DEF')); }