Commit faeab05b authored by Steve Müller's avatar Steve Müller Committed by Marco Pivetta

add ability to introspect namespace names on capable platforms

parent 45664da5
......@@ -2678,6 +2678,18 @@ abstract class AbstractPlatform
throw DBALException::notSupported(__METHOD__);
}
/**
* Returns the SQL statement for retrieving the namespaces defined in the database.
*
* @return string
*
* @throws \Doctrine\DBAL\DBALException If not supported on this platform.
*/
public function getListNamespacesSQL()
{
throw DBALException::notSupported(__METHOD__);
}
/**
* @param string $database
*
......
......@@ -222,6 +222,14 @@ class PostgreSqlPlatform extends AbstractPlatform
return 'SELECT datname FROM pg_database';
}
/**
* {@inheritDoc}
*/
public function getListNamespacesSQL()
{
return "SELECT nspname FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'";
}
/**
* {@inheritDoc}
*/
......
......@@ -1025,6 +1025,14 @@ class SQLServerPlatform extends AbstractPlatform
return 'SELECT * FROM SYS.DATABASES';
}
/**
* {@inheritDoc}
*/
public function getListNamespacesSQL()
{
return "SELECT name FROM SYS.SCHEMAS WHERE name NOT IN('guest', 'INFORMATION_SCHEMA', 'sys')";
}
/**
* {@inheritDoc}
*/
......
......@@ -115,6 +115,20 @@ abstract class AbstractSchemaManager
return $this->_getPortableDatabasesList($databases);
}
/**
* Returns a list of all namespaces in the current database.
*
* @return array
*/
public function listNamespaceNames()
{
$sql = $this->_platform->getListNamespacesSQL();
$namespaces = $this->_conn->fetchAll($sql);
return $this->getPortableNamespacesList($namespaces);
}
/**
* Lists the available sequences for this connection.
*
......@@ -651,6 +665,24 @@ abstract class AbstractSchemaManager
return $list;
}
/**
* Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition.
*
* @param array $namespaces The list of namespace names in the native DBMS data definition.
*
* @return array
*/
protected function getPortableNamespacesList(array $namespaces)
{
$namespacesList = array();
foreach ($namespaces as $namespace) {
$namespacesList[] = $this->getPortableNamespaceDefinition($namespace);
}
return $namespacesList;
}
/**
* @param array $database
*
......@@ -661,6 +693,18 @@ abstract class AbstractSchemaManager
return $database;
}
/**
* Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition.
*
* @param array $namespace The native DBMS namespace definition.
*
* @return mixed
*/
protected function getPortableNamespaceDefinition(array $namespace)
{
return $namespace;
}
/**
* @param array $functions
*
......
......@@ -283,6 +283,14 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
return $list;
}
/**
* {@inheritdoc}
*/
protected function getPortableNamespaceDefinition(array $namespace)
{
return $namespace['nspname'];
}
/**
* {@inheritdoc}
*/
......
......@@ -180,6 +180,14 @@ class SQLServerSchemaManager extends AbstractSchemaManager
return $database['name'];
}
/**
* {@inheritdoc}
*/
protected function getPortableNamespaceDefinition(array $namespace)
{
return $namespace['name'];
}
/**
* {@inheritdoc}
*/
......
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