Browse Source

Merge pull request #517 from gevik/pgsql-small-fix

Pgsql small fix  (update 2)
tags/2.0.0-beta
Alexander Makarov 12 years ago
parent
commit
42d332f8be
  1. 19
      framework/yii/db/pgsql/Schema.php

19
framework/yii/db/pgsql/Schema.php

@ -73,7 +73,7 @@ class Schema extends \yii\db\Schema
); );
/** /**
* Creates a query builder for the MySQL database. * Creates a query builder for the PostgreSQL database.
* @return QueryBuilder query builder instance * @return QueryBuilder query builder instance
*/ */
public function createQueryBuilder() public function createQueryBuilder()
@ -143,14 +143,9 @@ class Schema extends \yii\db\Schema
$sql = <<<SQL $sql = <<<SQL
select select
ct.conname as containst,
c.relname as table_name,
ns.nspname as table_schema,
current_database() as table_catalog,
(select string_agg(attname,',') attname from pg_attribute where attrelid=ct.conrelid and attnum = any(ct.conkey)) as columns, (select string_agg(attname,',') attname from pg_attribute where attrelid=ct.conrelid and attnum = any(ct.conkey)) as columns,
fc.relname as foreign_table_name, fc.relname as foreign_table_name,
fns.nspname as foreign_table_schema, fns.nspname as foreign_table_schema,
current_database() as foreign_table_catalog,
(select string_agg(attname,',') attname from pg_attribute where attrelid=ct.confrelid and attnum = any(ct.confkey)) as foreign_columns (select string_agg(attname,',') attname from pg_attribute where attrelid=ct.confrelid and attnum = any(ct.confkey)) as foreign_columns
from from
pg_constraint ct pg_constraint ct
@ -169,7 +164,12 @@ SQL;
foreach ($constraints as $constraint) { foreach ($constraints as $constraint) {
$columns = explode(',', $constraint['columns']); $columns = explode(',', $constraint['columns']);
$fcolumns = explode(',', $constraint['foreign_columns']); $fcolumns = explode(',', $constraint['foreign_columns']);
$citem = array($constraint['foreign_table_name']); if ($constraint['foreign_table_schema'] !== $this->defaultSchema) {
$foreign_table = $constraint['foreign_table_schema'] . '.' . $constraint['foreign_table_name'];
} else {
$foreign_table = $constraint['foreign_table_name'];
}
$citem = array($foreign_table);
foreach ($columns as $idx => $column) { foreach ($columns as $idx => $column) {
$citem[] = array($fcolumns[$idx] => $column); $citem[] = array($fcolumns[$idx] => $column);
} }
@ -243,10 +243,6 @@ ORDER BY
SQL; SQL;
$columns = $this->db->createCommand($sql)->queryAll(); $columns = $this->db->createCommand($sql)->queryAll();
if (empty($columns)) {
return false;
}
foreach ($columns as $column) { foreach ($columns as $column) {
$column = $this->loadColumnSchema($column); $column = $this->loadColumnSchema($column);
$table->columns[$column->name] = $column; $table->columns[$column->name] = $column;
@ -289,4 +285,5 @@ SQL;
$column->phpType = $this->getColumnPhpType($column); $column->phpType = $this->getColumnPhpType($column);
return $column; return $column;
} }
} }

Loading…
Cancel
Save