Index: MDB2.php =================================================================== RCS file: /repository/pear/MDB2/MDB2.php,v retrieving revision 1.90 diff -u -r1.90 MDB2.php --- MDB2.php 1 Apr 2005 12:54:01 -0000 1.90 +++ MDB2.php 4 Apr 2005 15:55:50 -0000 @@ -1880,10 +1880,16 @@ '_wrapResult: result class does not exist '.$class_name); } $result =& new $class_name($this, $result, $limit, $offset); + if (!MDB2::isResultCommon($result)) { return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, '_wrapResult: result class is not extended from MDB2_Result_Common'); } + + if (empty($types)) { + $types = $result->getTypes(); + } + if (!empty($types)) { $error = $result->setResultTypes($types); if (PEAR::isError($error)) { @@ -2555,6 +2561,34 @@ } // }}} + //{{{ getTypes() + + /** + * Get column types. + * + * @access public + */ + function &getTypes() + { + $load = $this->db->loadModule('Reverse'); + if (MDB2::isError($load)) { + return $load; + } + + $info_array = $this->db->reverse->tableInfo($this->result); + if (MDB2::isError($info_array)) { + return $info_array; + } + $types = array(); + + foreach ($info_array as $info) { + $types[] = $info['mdb2_type']; + } + + return $types; + } + + // }}} // {{{ seek() /** @@ -3019,4 +3053,4 @@ $db->debug_output .= $message.$db->getOption('log_line_break'); } -?> \ No newline at end of file +?> Index: MDB2/Driver/mssql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/mssql.php,v retrieving revision 1.65 diff -u -r1.65 mssql.php --- MDB2/Driver/mssql.php 30 Mar 2005 01:33:40 -0000 1.65 +++ MDB2/Driver/mssql.php 4 Apr 2005 15:55:50 -0000 @@ -725,4 +725,4 @@ } -?> \ No newline at end of file +?> Index: MDB2/Driver/pgsql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/pgsql.php,v retrieving revision 1.62 diff -u -r1.62 pgsql.php --- MDB2/Driver/pgsql.php 25 Mar 2005 18:12:18 -0000 1.62 +++ MDB2/Driver/pgsql.php 4 Apr 2005 15:55:50 -0000 @@ -546,7 +546,6 @@ class MDB2_Result_pgsql extends MDB2_Result_Common { - // }}} // {{{ fetchRow() /** @@ -754,4 +753,4 @@ { } -?> \ No newline at end of file +?> Index: MDB2/Driver/Datatype/Common.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/Datatype/Common.php,v retrieving revision 1.23 diff -u -r1.23 Common.php --- MDB2/Driver/Datatype/Common.php 25 Mar 2005 18:12:18 -0000 1.23 +++ MDB2/Driver/Datatype/Common.php 4 Apr 2005 15:55:51 -0000 @@ -1501,4 +1501,4 @@ } } -?> \ No newline at end of file +?> Index: MDB2/Driver/Datatype/mssql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/Datatype/mssql.php,v retrieving revision 1.16 diff -u -r1.16 mssql.php --- MDB2/Driver/Datatype/mssql.php 22 Mar 2005 16:09:50 -0000 1.16 +++ MDB2/Driver/Datatype/mssql.php 4 Apr 2005 15:55:51 -0000 @@ -517,4 +517,4 @@ } } -?> \ No newline at end of file +?> Index: MDB2/Driver/Datatype/pgsql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/Datatype/pgsql.php,v retrieving revision 1.21 diff -u -r1.21 pgsql.php --- MDB2/Driver/Datatype/pgsql.php 4 Apr 2005 08:09:56 -0000 1.21 +++ MDB2/Driver/Datatype/pgsql.php 4 Apr 2005 15:55:51 -0000 @@ -747,4 +747,4 @@ } } -?> \ No newline at end of file +?> Index: MDB2/Driver/Reverse/mssql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/Reverse/mssql.php,v retrieving revision 1.11 diff -u -r1.11 mssql.php --- MDB2/Driver/Reverse/mssql.php 8 Mar 2005 07:14:18 -0000 1.11 +++ MDB2/Driver/Reverse/mssql.php 4 Apr 2005 15:55:51 -0000 @@ -141,6 +141,12 @@ if ($mode & MDB2_TABLEINFO_ORDERTABLE) { $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; } + + $type = $this->getMDB2Type($res[$i]['type'], $res[$i]['len']); + if (MDB2::isError($type)) + $res[$i]['mdb2_type'] = 'text'; + else + $res[$i]['mdb2_type'] = $type[0]; } // free the result only if we were called on a table @@ -254,5 +260,46 @@ array_push($array, $value); } } + + // }}} + // {{{ getMDB2Type() + function getMDB2Type($db_type, $length) + { + $db_type = preg_replace('/\d/','', strtolower($db_type) ); + + $type = array(); + switch ($db_type) { + case 'bit': + $type[0] = 'text'; + break; + case 'int': + $type[0] = 'integer'; + break; + case 'datetime': + $type[0] = 'timestamp'; + break; + case 'real': + case 'numeric': + $type[0] = 'float'; + break; + case 'money': + $type[0] = 'decimal'; + break; + case 'blob': + $type[0] = 'blob'; + break; + case 'text': + case 'char': + $type[0] = 'text'; + break; + default: + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + return $db->raiseError(MDB2_ERROR, null, null, + 'getTableFieldDefinition: unknown database attribute type'); + } + + return $type; + } + // }}} } -?> \ No newline at end of file +?> Index: MDB2/Driver/Reverse/pgsql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/Reverse/pgsql.php,v retrieving revision 1.18 diff -u -r1.18 pgsql.php --- MDB2/Driver/Reverse/pgsql.php 4 Apr 2005 08:09:59 -0000 1.18 +++ MDB2/Driver/Reverse/pgsql.php 4 Apr 2005 15:55:51 -0000 @@ -88,9 +88,19 @@ and attname = '$field_name' ORDER BY attnum ", null, MDB2_FETCHMODE_ASSOC); - if (PEAR::isError($column)) { + + if (PEAR::isError($column)) { return $column; } + $field_column = $column['attname']; + $type_column = $column['typname']; + $length = $column['attlen']; + if ($length == -1) { + $length = $column['atttypmod']-4; + } + + //$decimal = strtok('(), '); = eh? + $type = $this->getMDB2Type($type_column, $length); list($types, $length) = $db->datatype->mapNativeDatatype($column); if ($column['attnotnull'] == 't') { @@ -275,6 +285,12 @@ if ($mode & MDB2_TABLEINFO_ORDERTABLE) { $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; } + + $type = $this->getMDB2Type($res[$i]['type'], $res[$i]['len']); + if (MDB2::isError($type)) + $res[$i]['mdb2_type'] = 'text'; + else + $res[$i]['mdb2_type'] = $type[0]; } // free the result only if we were called on a table @@ -352,5 +368,77 @@ return trim($flags); } + + function getMDB2Type($db_type, $length) { + $db_type = preg_replace('/\d/','', strtolower($db_type) ); + + $type = array(); + switch ($db_type) { + case 'int': + $type[0] = 'integer'; + if ($length == '1') { + $type[1] = 'boolean'; + } + break; + case 'text': + case 'char': + case 'varchar': + case 'cidr': + case 'inet': + $type[0] = 'text'; + break; + case 'bool': + $type[0] = 'boolean'; + break; + case 'bpchar': + case 'bit': + $type[0] = 'text'; + + if ($length == '1') { + $type[1] = 'boolean'; + } elseif (strstr($db_type, 'text')) + $type[1] = 'clob'; + break; + case 'date': + $type[0] = 'date'; + break; + case 'datetime': + case 'timestamp': + $type[0] = 'timestamp'; + break; + case 'time': + $type[0] = 'time'; + break; + case 'float': + case 'double': + case 'real': + + $type[0] = 'float'; + break; + case 'decimal': + case 'money': + case 'numeric': + $type[0] = 'decimal'; + break; + case 'oid': + case 'tinyblob': + case 'mediumblob': + case 'longblob': + case 'blob': + $type[0] = 'blob'; + $type[1] = 'text'; + break; + case 'year': + $type[0] = 'integer'; + $type[1] = 'date'; + break; + default: + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + return $db->raiseError(MDB2_ERROR, null, null, + 'getTableFieldDefinition: unknown database attribute type'); + } + + return $type; + } } -?> \ No newline at end of file +?>