summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrenda Wallace <shiny@cpan.org>2010-01-10 05:21:23 +0000
committerBrenda Wallace <shiny@cpan.org>2010-01-30 21:12:06 +1300
commit870c83c17de9710800163570cdc5321591e73c34 (patch)
tree3f1a07ea7d8fb2172c7dc8cb31409a58385792d8
parente765a9657b0491c6d4fd6436c9cd489342a465c9 (diff)
getTableDef() mostly working in postgres
-rw-r--r--lib/schema.php19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/schema.php b/lib/schema.php
index 164387ff3..c1636c21d 100644
--- a/lib/schema.php
+++ b/lib/schema.php
@@ -97,7 +97,12 @@ class Schema
public function getTableDef($name)
{
- $res = $this->conn->query('DESCRIBE ' . $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());
@@ -111,12 +116,16 @@ class Schema
$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'];
+ $cd->name = $row['field'];
- $packed = $row['Type'];
+ $packed = $row['type'];
if (preg_match('/^(\w+)\((\d+)\)$/', $packed, $match)) {
$cd->type = $match[1];
@@ -125,9 +134,9 @@ class Schema
$cd->type = $packed;
}
- $cd->nullable = ($row['Null'] == 'YES') ? true : false;
+ $cd->nullable = ($row['null'] == 'YES') ? true : false;
$cd->key = $row['Key'];
- $cd->default = $row['Default'];
+ $cd->default = $row['default'];
$cd->extra = $row['Extra'];
$td->columns[] = $cd;