removed describeTable from base class, and fixed it up in pgsql
This commit is contained in:
parent
870c83c17d
commit
22a6e46b45
@ -61,7 +61,7 @@ class PgsqlSchema extends Schema
|
|||||||
|
|
||||||
public function getTableDef($name)
|
public function getTableDef($name)
|
||||||
{
|
{
|
||||||
$res = $this->conn->query('DESCRIBE ' . $name);
|
$res = $this->conn->query("select *, column_default as default, is_nullable as Null, udt_name as Type, column_name AS Field from INFORMATION_SCHEMA.COLUMNS where table_name = '$name'");
|
||||||
|
|
||||||
if (PEAR::isError($res)) {
|
if (PEAR::isError($res)) {
|
||||||
throw new Exception($res->getMessage());
|
throw new Exception($res->getMessage());
|
||||||
@ -75,12 +75,12 @@ class PgsqlSchema extends Schema
|
|||||||
$row = array();
|
$row = array();
|
||||||
|
|
||||||
while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
|
while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
|
||||||
|
// var_dump($row);
|
||||||
$cd = new ColumnDef();
|
$cd = new ColumnDef();
|
||||||
|
|
||||||
$cd->name = $row['Field'];
|
$cd->name = $row['field'];
|
||||||
|
|
||||||
$packed = $row['Type'];
|
$packed = $row['type'];
|
||||||
|
|
||||||
if (preg_match('/^(\w+)\((\d+)\)$/', $packed, $match)) {
|
if (preg_match('/^(\w+)\((\d+)\)$/', $packed, $match)) {
|
||||||
$cd->type = $match[1];
|
$cd->type = $match[1];
|
||||||
@ -89,14 +89,13 @@ class PgsqlSchema extends Schema
|
|||||||
$cd->type = $packed;
|
$cd->type = $packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cd->nullable = ($row['Null'] == 'YES') ? true : false;
|
$cd->nullable = ($row['null'] == 'YES') ? true : false;
|
||||||
$cd->key = $row['Key'];
|
$cd->key = $row['Key'];
|
||||||
$cd->default = $row['Default'];
|
$cd->default = $row['default'];
|
||||||
$cd->extra = $row['Extra'];
|
$cd->extra = $row['Extra'];
|
||||||
|
|
||||||
$td->columns[] = $cd;
|
$td->columns[] = $cd;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $td;
|
return $td;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,66 +84,6 @@ class Schema
|
|||||||
return self::$_single;
|
return self::$_single;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a TableDef object for the table
|
|
||||||
* in the schema with the given name.
|
|
||||||
*
|
|
||||||
* Throws an exception if the table is not found.
|
|
||||||
*
|
|
||||||
* @param string $name Name of the table to get
|
|
||||||
*
|
|
||||||
* @return TableDef tabledef for that table.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public function getTableDef($name)
|
|
||||||
{
|
|
||||||
if(common_config('db','type') == 'pgsql') {
|
|
||||||
$res = $this->conn->query("select column_default as default, is_nullable as Null, udt_name as Type, column_name AS Field from INFORMATION_SCHEMA.COLUMNS where table_name = '$name'");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$res = $this->conn->query('DESCRIBE ' . $name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PEAR::isError($res)) {
|
|
||||||
throw new Exception($res->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$td = new TableDef();
|
|
||||||
|
|
||||||
$td->name = $name;
|
|
||||||
$td->columns = array();
|
|
||||||
|
|
||||||
$row = array();
|
|
||||||
|
|
||||||
while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
|
|
||||||
//lower case the keys, because the php postgres driver is case insentive for column names
|
|
||||||
foreach($row as $k=>$v) {
|
|
||||||
$row[strtolower($k)] = $row[$k];
|
|
||||||
}
|
|
||||||
|
|
||||||
$cd = new ColumnDef();
|
|
||||||
|
|
||||||
$cd->name = $row['field'];
|
|
||||||
|
|
||||||
$packed = $row['type'];
|
|
||||||
|
|
||||||
if (preg_match('/^(\w+)\((\d+)\)$/', $packed, $match)) {
|
|
||||||
$cd->type = $match[1];
|
|
||||||
$cd->size = $match[2];
|
|
||||||
} else {
|
|
||||||
$cd->type = $packed;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cd->nullable = ($row['null'] == 'YES') ? true : false;
|
|
||||||
$cd->key = $row['Key'];
|
|
||||||
$cd->default = $row['default'];
|
|
||||||
$cd->extra = $row['Extra'];
|
|
||||||
|
|
||||||
$td->columns[] = $cd;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $td;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a ColumnDef object for a single column.
|
* Gets a ColumnDef object for a single column.
|
||||||
|
Loading…
Reference in New Issue
Block a user