Commit b6f07859 by Qiang Xue

Added support for getting all tables for pgsql.

parent e683bd3d
......@@ -129,6 +129,35 @@ class Schema extends \yii\db\Schema
}
/**
* Returns all table names in the database.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* If not empty, the returned table names will be prefixed with the schema name.
* @return array all table names in the database.
*/
protected function findTableNames($schema = '')
{
if ($schema === '') {
$schema = $this->defaultSchema;
}
$sql = <<<EOD
SELECT table_name, table_schema FROM information_schema.tables
WHERE table_schema=:schema AND table_type='BASE TABLE'
EOD;
$command = $this->db->createCommand($sql);
$command->bindParam(':schema', $schema);
$rows = $command->queryAll();
$names = array();
foreach ($rows as $row) {
if ($schema === $this->defaultSchema) {
$names[] = $row['table_name'];
} else {
$names[] = $row['table_schema'] . '.' . $row['table_name'];
}
}
return $names;
}
/**
* Collects the foreign key column details for the given table.
* @param TableSchema $table the table metadata
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment