Skip to content

Commit

Permalink
fetch max string length (pg import)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmntf committed Jun 2, 2010
1 parent fa4d8d2 commit 5a1123f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 45 deletions.
42 changes: 19 additions & 23 deletions lib/Doctrine/Import/Pgsql.php
Expand Up @@ -94,28 +94,24 @@ class Doctrine_Import_Pgsql extends Doctrine_Import
AND indisprimary != 't'
)",
'listTableColumns' => "SELECT
a.attnum,
a.attname AS field,
t.typname AS type,
format_type(a.atttypid, a.atttypmod) AS complete_type,
a.attnotnull AS isnotnull,
(SELECT 't'
FROM pg_index
WHERE c.oid = pg_index.indrelid
AND a.attnum = ANY (pg_index.indkey)
AND pg_index.indisprimary = 't'
) AS pri,
(SELECT pg_attrdef.adsrc
FROM pg_attrdef
WHERE c.oid = pg_attrdef.adrelid
AND pg_attrdef.adnum=a.attnum
) AS default
FROM pg_attribute a, pg_class c, pg_type t
WHERE c.relname = %s
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid
ORDER BY a.attnum",
ordinal_position as attnum,
column_name as field,
udt_name as type,
data_type as complete_type,
is_nullable as isnotnull,
column_default as default,
(
SELECT 't'
FROM pg_index, pg_attribute a, pg_class c, pg_type t
WHERE c.relname = table_name AND a.attname = column_name
AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
AND c.oid = pg_index.indrelid AND a.attnum = ANY (pg_index.indkey)
AND pg_index.indisprimary = 't'
) as pri,
character_maximum_length as length
FROM information_schema.COLUMNS
WHERE table_name = %s
ORDER BY ordinal_position",
'listTableRelations' => "SELECT pg_catalog.pg_get_constraintdef(oid, true) as condef
FROM pg_catalog.pg_constraint r
WHERE r.conrelid =
Expand Down Expand Up @@ -185,7 +181,7 @@ public function listTableColumns($table)
'length' => $decl['length'],
'fixed' => (bool) $decl['fixed'],
'unsigned' => (bool) $decl['unsigned'],
'notnull' => ($val['isnotnull'] == true),
'notnull' => ($val['isnotnull'] == 'NO'),
'default' => $val['default'],
'primary' => ($val['pri'] == 't'),
);
Expand Down
40 changes: 18 additions & 22 deletions tests/Import/PgsqlTestCase.php
Expand Up @@ -49,28 +49,24 @@ public function testListTableColumnsExecutesSql()
$this->import->listTableColumns('table');

$this->assertEqual($this->adapter->pop(), "SELECT
a.attnum,
a.attname AS field,
t.typname AS type,
format_type(a.atttypid, a.atttypmod) AS complete_type,
a.attnotnull AS isnotnull,
(SELECT 't'
FROM pg_index
WHERE c.oid = pg_index.indrelid
AND a.attnum = ANY (pg_index.indkey)
AND pg_index.indisprimary = 't'
) AS pri,
(SELECT pg_attrdef.adsrc
FROM pg_attrdef
WHERE c.oid = pg_attrdef.adrelid
AND pg_attrdef.adnum=a.attnum
) AS default
FROM pg_attribute a, pg_class c, pg_type t
WHERE c.relname = 'table'
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid
ORDER BY a.attnum");
ordinal_position as attnum,
column_name as field,
udt_name as type,
data_type as complete_type,
is_nullable as isnotnull,
column_default as default,
(
SELECT 't'
FROM pg_index, pg_attribute a, pg_class c, pg_type t
WHERE c.relname = table_name AND a.attname = column_name
AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
AND c.oid = pg_index.indrelid AND a.attnum = ANY (pg_index.indkey)
AND pg_index.indisprimary = 't'
) as pri,
character_maximum_length as length
FROM information_schema.COLUMNS
WHERE table_name = 'table'
ORDER BY ordinal_position");
}
public function testListTableIndexesExecutesSql()
{
Expand Down

0 comments on commit 5a1123f

Please sign in to comment.