Permalink
Browse files

Changed getTableColumns to return object with "Default" property instead

of "default", as MySQL does.
Changed corresponding test.
Added conversion between PostgreSQL's null to PHP's null value,
default field containing "NULL::character varying" will be used as
string otherwise.
  • Loading branch information...
1 parent 8fe0592 commit dd5ee04d13d49a11a5abcd216496d0e0e2b49848 @gpongelli gpongelli committed Apr 27, 2012
@@ -327,7 +327,7 @@ public function getTableColumns($table, $typeOnly = true)
END AS "null",
CASE WHEN pg_catalog.pg_get_expr(adef.adbin, adef.adrelid, true) IS NOT NULL
THEN pg_catalog.pg_get_expr(adef.adbin, adef.adrelid, true)
- END as "default",
+ END as "Default",
CASE WHEN pg_catalog.col_description(a.attrelid, a.attnum) IS NULL
THEN \'\'
ELSE pg_catalog.col_description(a.attrelid, a.attnum)
@@ -361,6 +361,15 @@ public function getTableColumns($table, $typeOnly = true)
}
}
+ /* Change Postgresql's NULL::* type with PHP's null one */
+ foreach ($fields as $field)
+ {
+ if (preg_match("/^NULL::*/", $field->Default))
+ {
+ $field->Default = null;
+ }
+ }
+
return $result;
}
@@ -331,28 +331,28 @@ public function testGetTableColumns()
$id->column_name = 'id';
$id->type = 'integer';
$id->null = 'NO';
- $id->default = 'nextval(\'jos_dbtest_id_seq\'::regclass)';
+ $id->Default = 'nextval(\'jos_dbtest_id_seq\'::regclass)';
$id->comments = '';
$title = new stdClass;
$title->column_name = 'title';
$title->type = 'character varying(50)';
$title->null = 'NO';
- $title->default = null;
+ $title->Default = null;
$title->comments = '';
$start_date = new stdClass;
$start_date->column_name = 'start_date';
$start_date->type = 'timestamp without time zone';
$start_date->null = 'NO';
- $start_date->default = null;
+ $start_date->Default = null;
$start_date->comments = '';
$description = new stdClass;
$description->column_name = 'description';
$description->type = 'text';
$description->null = 'NO';
- $description->default = null;
+ $description->Default = null;
$description->comments = '';
$this->assertThat(

0 comments on commit dd5ee04

Please sign in to comment.