DbMeta supports schemas through the weeDbMetaSchemaProvider interface.
A schema is an instance of weeDbMetaSchema and contains methods to fetch database objects related to this schema.
Schemas are supported in PostgreSQL and Oracle.
You can use the following snippet to retrieve the list of schemas. The list is ordered by name.
<?php $aSchemas = $oDb->meta()->schemas();
Additionally, may you require nothing more, you can obtain an array containing
only the names of these schemas through the schemasNames method.
<?php
$aSchemasNames = $oTable->schemasNames();
You can use the schemaExists method of the DbMeta object to check whether a schema exist.
<?php $bSchemaExists = $oDb->meta()->schemaExists('some_schema');
You can retrieve a schema object in order to get more information about it and the objects it contains.
If the schema does not exist in the database, an UnexpectedValueException is thrown.
To retrieve this object, use the schema method.
<?php
try {
$oSchema = $oDb->meta()->schema('some_schema');
} catch (UnexpectedValueException $e) {
// The schema "some_schema" does not exist in the database.
}
All schema-enabled database drivers allow you to retrieve their objects' schema's name.
You can retrieve the name of an object's schema by using the schemaName method.
<?php
$sSchemaName = $oDbObjectInSchema->schemaName();
The only class that does not implement this method is of course the schema itself.
It should be noted that all the DbMeta classes representing database objects in schema-enabled database drivers
will return a fully-qualified name when you use the method quotedName on them.
Let's take a look with an example:
<?php // The underlying database is PostgreSQL. $sName = $oDb->meta()->schema('some_schema')->table('some_table')->quotedName(); // $sName = '"some_schema"."some_table"';
As you can see, you do not have to worry about the schema when you use this method. You can be sure that it will return a fully-qualified name that can be used without any ambiguity.