From c4ee2b20bee567e1c41888bb46bfc8d5f98e8951 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 10 Mar 2010 21:25:44 +1300 Subject: throw an error that looks like mysql errors.. :-S --- lib/pgsqlschema.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/pgsqlschema.php') diff --git a/lib/pgsqlschema.php b/lib/pgsqlschema.php index 91bc09667..a4ebafae4 100644 --- a/lib/pgsqlschema.php +++ b/lib/pgsqlschema.php @@ -1,3 +1,4 @@ + 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'"); + $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)) { throw new Exception($res->getMessage()); @@ -72,6 +74,9 @@ class PgsqlSchema extends Schema $td->name = $name; $td->columns = array(); + if ($res->numRows() == 0 ) { + throw new Exception('no such table'); //pretend to be the msyql error. yeah, this sucks. + } $row = array(); while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) { @@ -359,6 +364,7 @@ class PgsqlSchema extends Schema try { $td = $this->getTableDef($tableName); + } catch (Exception $e) { if (preg_match('/no such table/', $e->getMessage())) { return $this->createTable($tableName, $columns); -- cgit v1.2.3-54-g00ecf From 7398353c441699acc8b6ed38e221e40e30196208 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 10 Mar 2010 21:54:30 +1300 Subject: primary keys and unique indexes working in postgres --- lib/pgsqlschema.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/pgsqlschema.php') diff --git a/lib/pgsqlschema.php b/lib/pgsqlschema.php index a4ebafae4..825241902 100644 --- a/lib/pgsqlschema.php +++ b/lib/pgsqlschema.php @@ -171,12 +171,10 @@ class PgsqlSchema extends Schema } if (count($primary) > 0) { // it really should be... - $sql .= ",\nconstraint primary key (" . implode(',', $primary) . ")"; + $sql .= ",\n primary key (" . implode(',', $primary) . ")"; } - foreach ($uniques as $u) { - $sql .= ",\nunique index {$name}_{$u}_idx ($u)"; - } + foreach ($indices as $i) { $sql .= ",\nindex {$name}_{$i}_idx ($i)"; @@ -184,6 +182,10 @@ class PgsqlSchema extends Schema $sql .= "); "; + + foreach ($uniques as $u) { + $sql .= "\n CREATE index {$name}_{$u}_idx ON {$name} ($u); "; + } $res = $this->conn->query($sql); if (PEAR::isError($res)) { -- cgit v1.2.3-54-g00ecf From 75e2be3b71cc5b6114a10e1b5f1e0c9e3074af19 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 10 Mar 2010 22:02:56 +1300 Subject: map the mysql-ish column types to ones postgres likes --- lib/pgsqlschema.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'lib/pgsqlschema.php') diff --git a/lib/pgsqlschema.php b/lib/pgsqlschema.php index 825241902..86ffbeb2a 100644 --- a/lib/pgsqlschema.php +++ b/lib/pgsqlschema.php @@ -216,6 +216,22 @@ class PgsqlSchema extends Schema return true; } + /** + * Translate the (mostly) mysql-ish column types into somethings more standard + * @param string column type + * + * @return string postgres happy column type + */ + private function _columnTypeTranslation($type) { + $map = array( + 'datetime' => 'timestamp' + ); + if(!empty($map[$type])) { + return $map[$type]; + } + return $type; + } + /** * Adds an index to a table. * @@ -485,11 +501,12 @@ class PgsqlSchema extends Schema private function _columnSql($cd) { $sql = "{$cd->name} "; - + $type = $this->_columnTypeTranslation($cd->type); +var_dump($type); if (!empty($cd->size)) { - $sql .= "{$cd->type}({$cd->size}) "; + $sql .= "{$type}({$cd->size}) "; } else { - $sql .= "{$cd->type} "; + $sql .= "{$type} "; } if (!empty($cd->default)) { -- cgit v1.2.3-54-g00ecf From 49f1b1e8b290de22381a0e25b2b612bd6ddaf79d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 10 Mar 2010 22:03:36 +1300 Subject: removed a stay bit of debug --- lib/pgsqlschema.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/pgsqlschema.php') diff --git a/lib/pgsqlschema.php b/lib/pgsqlschema.php index 86ffbeb2a..afb498f4a 100644 --- a/lib/pgsqlschema.php +++ b/lib/pgsqlschema.php @@ -502,7 +502,7 @@ class PgsqlSchema extends Schema { $sql = "{$cd->name} "; $type = $this->_columnTypeTranslation($cd->type); -var_dump($type); + if (!empty($cd->size)) { $sql .= "{$type}({$cd->size}) "; } else { -- cgit v1.2.3-54-g00ecf From fe7b063b85647264f1988fba966502a1b0287511 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 11 Mar 2010 18:07:00 -0800 Subject: Remove stray whitespace at file start that snuck into last update --- lib/pgsqlschema.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/pgsqlschema.php') diff --git a/lib/pgsqlschema.php b/lib/pgsqlschema.php index afb498f4a..715065d77 100644 --- a/lib/pgsqlschema.php +++ b/lib/pgsqlschema.php @@ -1,4 +1,3 @@ -