Schema
API reference › yii › db › oci › Schema
Schema is the class for retrieving metadata from an Oracle database.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$columnSchemaClass | class-string<yii\ | Default: \. Available since 2.0.11. | Schema |
$db | yii\ | The database connection Default: null. | yii\ |
$defaultSchema | string | The default schema name used for the current session. Default: null. | yii\ |
$exceptionMap | array | Map of DB errors and corresponding exceptions If left part is found in DB error message exception class from the right part is used. Default: ['ORA-00001: unique constraint' => \. | Schema |
$lastInsertID read-only | string | The row ID of the last row inserted, or the last value retrieved from the sequence object. | Schema |
$queryBuilder read-only | yii\ | The query builder for this connection. | yii\ |
$schemaChecks read-only | yii\[][] | Check constraints for all tables in the database. | yii\ |
$schemaDefaultValues read-only | yii\[] | Default value constraints for all tables in the database. | yii\ |
$schemaForeignKeys read-only | yii\[][] | Foreign keys for all tables in the database. | yii\ |
$schemaIndexes read-only | yii\[][] | Indexes for all tables in the database. | yii\ |
$schemaNames read-only | string[] | All schema names in the database, except system schemas. | yii\ |
$schemaPrimaryKeys read-only | yii\[] | Primary keys for all tables in the database. | yii\ |
$schemaUniques read-only | yii\[][] | Unique constraints for all tables in the database. | yii\ |
$serverVersion read-only | string | Server version as a string. | yii\ |
$systemSchemaNames | list<string> | List of schema names that should be excluded from getSchemaNames(). Default: []. | yii\ |
$tableNames read-only | string[] | All table names in the database. | yii\ |
$tableSchemas read-only | yii\[] | The metadata for all tables in the database. | yii\ |
$transactionIsolationLevel write-only | string | The transaction isolation level to use for this transaction. | yii\ |
$columnQuoteCharacter protected | string| | Character used to quote column names. Default: '"'. Available since 2.0.14. | yii\ |
$tableQuoteCharacter protected | string| | Default: '"'. Available since 2.0.14. | Schema |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
convertException() | Converts a DB exception to a more concrete one if possible. | yii\ |
createColumnSchemaBuilder() | Create a column schema builder instance giving the type and value precision. | Schema |
createQueryBuilder() | Creates a query builder for the database. | Schema |
createSavepoint() | Creates a new savepoint. | yii\ |
findUniqueIndexes() | Returns all unique indexes for the given table. | Schema |
getLastInsertID() | Schema | |
getPdoType() | Determines the PDO type for the given PHP data value. | yii\ |
getQueryBuilder() | yii\ | |
getRawTableName() | Returns the actual name of a given table name. | yii\ |
getSchemaChecks() | Returns check constraints for all tables in the database. | yii\ |
getSchemaDefaultValues() | Returns default value constraints for all tables in the database. | yii\ |
getSchemaForeignKeys() | Returns foreign keys for all tables in the database. | yii\ |
getSchemaIndexes() | Returns indexes for all tables in the database. | yii\ |
getSchemaNames() | Returns all schema names in the database, except system schemas. | yii\ |
getSchemaPrimaryKeys() | Returns primary keys for all tables in the database. | yii\ |
getSchemaUniques() | Returns unique constraints for all tables in the database. | yii\ |
getServerVersion() | Returns a server version as a string comparable by version_compare(). | yii\ |
getTableChecks() | Obtains the check constraints information for the named table. | yii\ |
getTableDefaultValues() | Obtains the default value constraints information for the named table. | yii\ |
getTableForeignKeys() | Obtains the foreign keys information for the named table. | yii\ |
getTableIndexes() | Obtains the indexes information for the named table. | yii\ |
getTableNames() | Returns all table names in the database. | yii\ |
getTablePrimaryKey() | Obtains the primary key for the named table. | yii\ |
getTableSchema() | Obtains the metadata for the named table. | yii\ |
getTableSchemas() | Returns the metadata for all tables in the database. | yii\ |
getTableUniques() | Obtains the unique constraints information for the named table. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | Schema |
insert() | Executes the INSERT command, returning primary key values. | Schema |
isReadQuery() | Returns a value indicating whether a SQL statement is for read purpose. | yii\ |
quoteColumnName() | Quotes a column name for use in a query. | yii\ |
quoteSimpleColumnName() | Quotes a simple column name for use in a query. | yii\ |
quoteSimpleTableName() | Quotes a simple table name for use in a query. | yii\ |
quoteTableName() | Quotes a table name for use in a query. | yii\ |
quoteValue() | Quotes a string value for use in a query. | yii\ |
refresh() | Refreshes the schema. | yii\ |
refreshTableSchema() | Refreshes the particular table schema. | yii\ |
releaseSavepoint() | Releases an existing savepoint. | Schema |
resolveRawTableName() | Resolves the table name and schema name (if any) without loading database metadata. | yii\ |
rollBackSavepoint() | Rolls back to a previously created savepoint. | yii\ |
setTransactionIsolationLevel() | Sets the isolation level of the current transaction. | yii\ |
supportsSavepoint() | yii\ | |
unquoteSimpleColumnName() | Unquotes a simple column name. | yii\ |
unquoteSimpleTableName() | Unquotes a simple table name. | yii\ |
createColumn() protected | Creates ColumnSchema instance. | Schema |
createColumnSchema() protected | Creates a column schema for the database. | yii\ |
extractColumnSize() protected | Extracts size, precision and scale information from column’s DB type. | Schema |
extractColumnType() protected | Extracts the data types for the given column. | Schema |
findColumns() protected | Collects the table column metadata. | Schema |
findConstraints() protected | Finds constraints and fills them into TableSchema object passed. | Schema |
findSchemaNames() protected | Returns all schema names in the database, including the default one but not system schemas. | Schema |
findTableNames() protected | Returns all table names in the database. | Schema |
getCacheKey() protected | Returns the cache key for the specified table name. | yii\ |
getCacheTag() protected | Returns the cache tag name. | yii\ |
getColumnPhpType() protected | Extracts the PHP type from abstract DB type. | yii\ |
getSchemaMetadata() protected | Returns the metadata of the given type for all tables in the given schema. | yii\ |
getTableMetadata() protected | Returns the metadata of the given type for the given table. | yii\ |
getTableNameParts() protected | Splits full table name into parts. | yii\ |
getTableSequenceName() protected | Sequence name of table. | Schema |
loadTableChecks() protected | Schema | |
loadTableDefaultValues() protected | Schema | |
loadTableForeignKeys() protected | Schema | |
loadTableIndexes() protected | Schema | |
loadTablePrimaryKey() protected | Schema | |
loadTableSchema() protected | Loads the metadata for the specified table. | Schema |
loadTableUniques() protected | Schema | |
normalizePdoRowKeyCase() protected | Changes row’s array key case to lower if PDO’s one is set to uppercase. | yii\ |
resolveTableName() protected | Resolves the table name and schema name (if any). | Schema |
setTableMetadata() protected | Sets the metadata of the given type for the given table. | yii\ |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
TYPE_PK | 'pk' | yii\ | |
TYPE_UPK | 'upk' | yii\ | |
TYPE_BIGPK | 'bigpk' | yii\ | |
TYPE_UBIGPK | 'ubigpk' | yii\ | |
TYPE_CHAR | 'char' | yii\ | |
TYPE_STRING | 'string' | yii\ | |
TYPE_TEXT | 'text' | yii\ | |
TYPE_TINYINT | 'tinyint' | yii\ | |
TYPE_SMALLINT | 'smallint' | yii\ | |
TYPE_INTEGER | 'integer' | yii\ | |
TYPE_BIGINT | 'bigint' | yii\ | |
TYPE_FLOAT | 'float' | yii\ | |
TYPE_DOUBLE | 'double' | yii\ | |
TYPE_DECIMAL | 'decimal' | yii\ | |
TYPE_DATETIME | 'datetime' | yii\ | |
TYPE_TIMESTAMP | 'timestamp' | yii\ | |
TYPE_TIME | 'time' | yii\ | |
TYPE_DATE | 'date' | yii\ | |
TYPE_BINARY | 'binary' | yii\ | |
TYPE_BOOLEAN | 'boolean' | yii\ | |
TYPE_MONEY | 'money' | yii\ | |
TYPE_JSON | 'json' | yii\ | |
SCHEMA_CACHE_VERSION | 1 | Schema cache version, to detect incompatibilities in cached values when the data format of the cache changes. | yii\ |
Property details
Section titled “Property details”$tableQuoteCharacter
Section titled “$tableQuoteCharacter ”protected string|string[] $tableQuoteCharacter = '"'An array of 2 characters can be used in case starting and ending characters are different.
Since
2.0.14
Method details
Section titled “Method details”createColumnSchemaBuilder()
Section titled “createColumnSchemaBuilder() ”public function createColumnSchemaBuilder(mixed $type, mixed $length = null): yii\db\ColumnSchemaBuilderCreate a column schema builder instance giving the type and value precision.
This method may be overridden by child classes to create a DBMS-specific column schema builder.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | mixed | Type of the column. See ColumnSchemaBuilder::$type. |
$length | mixed | Length or precision of the column. See ColumnSchemaBuilder::$length. |
Returns
yii\db\ColumnSchemaBuilder: Column schema builder instance
Since
2.0.6
createQueryBuilder()
Section titled “createQueryBuilder() ”public function createQueryBuilder(): yii\db\TQueryBuilderCreates a query builder for the database.
This method may be overridden by child classes to create a DBMS-specific query builder.
Returns
yii\db\TQueryBuilder: Query builder instance
findUniqueIndexes()
Section titled “findUniqueIndexes() ”public function findUniqueIndexes(yii\db\TableSchema $table): arrayReturns all unique indexes for the given table.
Each array element is of the following structure:
[ 'IndexName1' => ['col1' [, ...]], 'IndexName2' => ['col2' [, ...]],]Parameters
| Parameter | Type | Description |
|---|---|---|
$table | yii\ | The table metadata. |
Returns
array: All unique indexes for the given table.
Since
2.0.4
getLastInsertID()
Section titled “getLastInsertID() ”public function getLastInsertID(string $sequenceName = ''): stringParameters
| Parameter | Type | Description |
|---|---|---|
$sequenceName | string | Name of the sequence object (required by some DBMS) |
Returns
string: The row ID of the last row inserted, or the last value retrieved from the sequence object
Throws
yii\base\InvalidCallException: if the DB connection is not active
See also
- https://www.php.net/manual/en/function.PDO-lastInsertId.php (-> Oracle does not support this Returns the ID of the last inserted row or sequence value.)
init()
Section titled “init() ”public function init(): mixedInitializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
Returns
mixed
insert()
Section titled “insert() ”public function insert(mixed $table, mixed $columns): array|falseExecutes the INSERT command, returning primary key values.
Merges primary-key and BLOB locator entries into one Oracle RETURNING clause.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table that new rows will be inserted into. |
$columns | mixed | The column data (name => value) to be inserted into the table. |
Returns
array|false: Primary key values or false if the command fails
Since
2.0.4
releaseSavepoint()
Section titled “releaseSavepoint() ”public function releaseSavepoint(mixed $name): mixedReleases an existing savepoint.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The savepoint name |
Returns
mixed
createColumn()
Section titled “createColumn() ”protected function createColumn(array $column): yii\db\oci\TCreates ColumnSchema instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
$column | array |
Returns
yii\db\oci\T
extractColumnSize()
Section titled “extractColumnSize() ”protected function extractColumnSize(yii\db\oci\ColumnSchema $column, string $dbType, string $precision, string $scale, string $length): mixedExtracts size, precision and scale information from column’s DB type.
Parameters
| Parameter | Type | Description |
|---|---|---|
$column | ColumnSchema | |
$dbType | string | The column’s DB type |
$precision | string | Total number of digits. This parameter is available since version 2.0.4. |
$scale | string | Number of digits on the right of the decimal separator. This parameter is available since version 2.0.4. |
$length | string | Length for character types. This parameter is available since version 2.0.4. |
Returns
mixed
extractColumnType()
Section titled “extractColumnType() ”protected function extractColumnType(yii\db\oci\ColumnSchema $column, string $dbType, string $precision, string $scale, string $length): mixedExtracts the data types for the given column.
Parameters
| Parameter | Type | Description |
|---|---|---|
$column | ColumnSchema | |
$dbType | string | DB type |
$precision | string | Total number of digits. This parameter is available since version 2.0.4. |
$scale | string | Number of digits on the right of the decimal separator. This parameter is available since version 2.0.4. |
$length | string | Length for character types. This parameter is available since version 2.0.4. |
Returns
mixed
findColumns()
Section titled “findColumns() ”protected function findColumns(yii\db\TableSchema $table): boolCollects the table column metadata.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | yii\ | The table schema. |
Returns
bool: Whether the table exists.
findConstraints()
Section titled “findConstraints() ”protected function findConstraints(yii\db\TableSchema $table): mixedFinds constraints and fills them into TableSchema object passed.
findSchemaNames()
Section titled “findSchemaNames() ”protected function findSchemaNames(): arrayReturns all schema names in the database, including the default one but not system schemas.
This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.
Returns
array: All schema names in the database, except system schemas.
Throws
yii\base\NotSupportedException: if this method is not supported by the DBMS.
Since
2.0.4
See also
findTableNames()
Section titled “findTableNames() ”protected function findTableNames(mixed $schema = ''): arrayReturns all table names in the database.
This method should be overridden by child classes in order to support this feature because the default implementation simply throws an exception.
Parameters
| Parameter | Type | Description |
|---|---|---|
$schema | mixed | The schema of the tables. Defaults to empty string, meaning the current or default schema. |
Returns
array: All table names in the database. The names have NO schema name prefix.
Throws
yii\base\NotSupportedException: if this method is not supported by the DBMS.
getTableSequenceName()
Section titled “getTableSequenceName() ”protected function getTableSequenceName(string $tableName): string|nullSequence name of table.
Resolves the sequence backing the table’s primary key, supporting two storage idioms:
IDENTITYcolumns (Oracle12.1+): returns the system-generatedISEQ$$_*sequence fromUSER_TAB_IDENTITY_COLS. Surfaced so framework machinery that reads\yii\db\TableSchema::$sequenceName(notably\yii\test\ActiveFixture::resetTable()) continues to work for tables created withSchema::TYPE_PK.- Legacy trigger + sequence pairs (pre-
22.0): falls back to theUSER_DEPENDENCIES/USER_TRIGGERSjoin so applications that have not yet migrated their tables continue to expose the user-named sequence.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | Table name. |
Returns
string|null: Whether the sequence exists.
loadTableChecks()
Section titled “loadTableChecks() ”protected function loadTableChecks(mixed $tableName)Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | mixed |
loadTableDefaultValues()
Section titled “loadTableDefaultValues() ”protected function loadTableDefaultValues(mixed $tableName)Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | mixed |
Throws
yii\base\NotSupportedException: if this method is called.
loadTableForeignKeys()
Section titled “loadTableForeignKeys() ”protected function loadTableForeignKeys(mixed $tableName)Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | mixed |
loadTableIndexes()
Section titled “loadTableIndexes() ”protected function loadTableIndexes(mixed $tableName)Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | mixed |
loadTablePrimaryKey()
Section titled “loadTablePrimaryKey() ”protected function loadTablePrimaryKey(mixed $tableName)Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | mixed |
loadTableSchema()
Section titled “loadTableSchema() ”protected function loadTableSchema(mixed $name): yii\db\TableSchema|nullLoads the metadata for the specified table.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | Table name |
Returns
yii\db\TableSchema|null: DBMS-dependent table metadata, null if the table does not exist.
loadTableUniques()
Section titled “loadTableUniques() ”protected function loadTableUniques(mixed $tableName)Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | mixed |
resolveTableName()
Section titled “resolveTableName() ”protected function resolveTableName(mixed $name): yii\db\TableSchemaResolves the table name and schema name (if any).
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The table name |
Returns
yii\db\TableSchema: TableSchema with resolved table, schema, etc. names.
Throws
yii\base\NotSupportedException: if this method is not supported by the DBMS.
Since
2.0.13