Index: MDB2.php =================================================================== RCS file: /repository/pear/MDB2/MDB2.php,v retrieving revision 1.133 diff -u -r1.133 MDB2.php --- MDB2.php 17 Oct 2005 09:23:21 -0000 1.133 +++ MDB2.php 17 Oct 2005 19:50:30 -0000 @@ -1962,6 +1962,9 @@ '_wrapResult: result class is not extended from MDB2_Result_Common'); return $err; } + if (empty($types)) { + $types = $result->getTypes(); + } if (!empty($types)) { $err = $result->setResultTypes($types); if (PEAR::isError($err)) { @@ -2628,6 +2631,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() /** @@ -3277,4 +3308,4 @@ $db->debug_output.= $message.$db->getOption('log_line_break'); } -?> \ 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.17 diff -u -r1.17 mssql.php --- MDB2/Driver/Reverse/mssql.php 29 Sep 2005 15:08:45 -0000 1.17 +++ MDB2/Driver/Reverse/mssql.php 17 Oct 2005 19:50:33 -0000 @@ -151,6 +151,12 @@ } } + $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 if ($got_string) { @mssql_free_result($id); @@ -265,5 +271,47 @@ 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; + } + // }}} } ?> Index: MDB2/Driver/Reverse/pgsql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/Reverse/pgsql.php,v retrieving revision 1.27 diff -u -r1.27 pgsql.php --- MDB2/Driver/Reverse/pgsql.php 16 Oct 2005 09:39:50 -0000 1.27 +++ MDB2/Driver/Reverse/pgsql.php 17 Oct 2005 19:50:33 -0000 @@ -95,6 +95,14 @@ if (PEAR::isError($column)) { return $column; } + $field_column = $column['attname']; + $type_column = $column['typname']; + $length = $column['attlen']; + if ($length == -1) { + $length = $column['atttypmod'] - 4; + } + $type = $this->getMDB2Type($type_column, $length); + list($types, $length) = $db->datatype->mapNativeDatatype($column); $notnull = false; if (array_key_exists('attnotnull', $column) && $column['attnotnull'] == 't') { @@ -322,6 +330,11 @@ $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 if ($got_string) { @@ -407,5 +420,82 @@ return trim($flags); } + + // }}} + // {{{ function getMDB2Type() + + 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 +?>