Handler for storing database schemas and applying differences that uses Oracle as backend.
Source for this file: /DatabaseSchema/src/handlers/oracle/writer.php
ezcDbSchemaCommonSqlWriter | --ezcDbSchemaOracleWriter
Version: | //autogentag// |
From ezcDbSchemaCommonSqlWriter | |
---|---|
protected |
ezcDbSchemaCommonSqlWriter::$queries
|
protected |
ezcDbSchemaCommonSqlWriter::$schema
|
public void |
applyDiffToDb(
$db
, $dbSchemaDiff
)
Applies the differences defined in $dbSchemaDiff to the database referenced by $db. |
public array(string) |
convertDiffToDDL(
$dbSchemaDiff
, [ $db
= null] )
Returns the differences definition in $dbSchema as database specific SQL DDL queries. |
protected string |
convertFromGenericType(
$fieldDefinition
)
Converts the generic field type contained in $fieldDefinition to a database specific field definition. |
protected void |
generateAddFieldSql(
$tableName
, $fieldName
, $fieldDefinition
)
Adds a "alter table" query to add the field $fieldName to $tableName with the definition $fieldDefinition. |
protected void |
generateAddIndexSql(
$tableName
, $indexName
, $indexDefinition
)
Adds a "alter table" query to add the index $indexName to the table $tableName with definition $indexDefinition to the internal list of queries |
protected void |
generateAdditionalDropSequenceStatements(
$dbSchemaDiff
, $db
)
Generate additional drop sequence statements |
protected void |
generateChangeFieldSql(
$tableName
, $fieldName
, $fieldDefinition
)
Adds a "alter table" query to change the field $fieldName to $tableName with the definition $fieldDefinition. |
protected void |
generateCreateTableSql(
$tableName
, $tableDefinition
)
Adds a "create table" query for the table $tableName with definition $tableDefinition to the internal list of queries. |
protected string |
generateDefault(
$type
, $value
)
Returns an appropriate default value for $type with $value. |
protected void |
generateDiffSchemaTableAsSql(
$tableName
, $tableDiff
)
Generates queries to upgrade a the table $tableName with the differences in $tableDiff. |
protected void |
generateDropFieldSql(
$tableName
, $fieldName
)
Adds a "alter table" query to drop the field $fieldName from $tableName. |
protected void |
generateDropIndexSql(
$tableName
, $indexName
)
Adds a "alter table" query to remote the index $indexName from the table $tableName to the internal list of queries. |
protected void |
generateDropTableSql(
$tableName
)
Adds a "drop table" query for the table $tableName to the internal list of queries. |
protected string |
generateFieldSql(
$fieldName
, $fieldDefinition
, $autoincrementField
)
Returns a column definition for $fieldName with definition $fieldDefinition. |
public int |
getDiffWriterType(
)
Returns what type of schema difference writer this class implements. |
public boolean |
isQueryAllowed(
$db
, $query
)
Checks if query allowed. |
From ezcDbSchemaCommonSqlWriter | |
---|---|
public array(string) |
ezcDbSchemaCommonSqlWriter::convertToDDL()
Returns an array with SQL DDL statements that creates the database definition in $dbSchema |
protected abstract void |
ezcDbSchemaCommonSqlWriter::generateAddFieldSql()
Adds a "alter table" query to add the field $fieldName to $tableName with the definition $fieldDefinition. |
protected abstract void |
ezcDbSchemaCommonSqlWriter::generateAddIndexSql()
Adds a "alter table" query to add the index $indexName to the table $tableName with definition $indexDefinition to the internal list of queries |
protected abstract void |
ezcDbSchemaCommonSqlWriter::generateChangeFieldSql()
Adds a "alter table" query to change the field $fieldName to $tableName with the definition $fieldDefinition. |
protected void |
ezcDbSchemaCommonSqlWriter::generateCreateTableSql()
Adds a "create table" query for the table $tableName with definition $tableDefinition to the internal list of queries. |
protected string |
ezcDbSchemaCommonSqlWriter::generateCreateTableSqlStatement()
Returns a "CREATE TABLE" SQL statement part for the table $tableName. |
protected string |
ezcDbSchemaCommonSqlWriter::generateDefault()
Returns an appropriate default value for $type with $value. |
protected void |
ezcDbSchemaCommonSqlWriter::generateDiffSchemaAsSql()
Generates queries to upgrade an existing database with the changes stored in $this->diffSchema. |
protected void |
ezcDbSchemaCommonSqlWriter::generateDiffSchemaTableAsSql()
Generates queries to upgrade a the table $tableName with the differences in $tableDiff. |
protected abstract void |
ezcDbSchemaCommonSqlWriter::generateDropFieldSql()
Adds a "alter table" query to drop the field $fieldName from $tableName. |
protected abstract void |
ezcDbSchemaCommonSqlWriter::generateDropIndexSql()
Adds a "alter table" query to remote the index $indexName from the table $tableName to the internal list of queries. |
protected abstract void |
ezcDbSchemaCommonSqlWriter::generateDropTableSql()
Adds a "drop table" query for the table $tableName to the internal list of queries. |
protected abstract string |
ezcDbSchemaCommonSqlWriter::generateFieldSql()
Returns a column definition for $fieldName with definition $fieldDefinition. |
protected void |
ezcDbSchemaCommonSqlWriter::generateSchemaAsSql()
Creates SQL DDL statements from a schema definitin. |
public int |
ezcDbSchemaCommonSqlWriter::getWriterType()
Returns what type of schema writer this class implements. |
public boolean |
ezcDbSchemaCommonSqlWriter::isQueryAllowed()
Checks if the query is allowed. |
public void |
ezcDbSchemaCommonSqlWriter::saveToDb()
Creates the tables contained in $schema in the database that is related to $db |
Applies the differences defined in $dbSchemaDiff to the database referenced by $db.
This method uses convertDiffToDDL to create SQL for the differences and then executes the returned SQL statements on the database handler $db.
Name | Type | Description |
---|---|---|
$db |
ezcDbHandler | |
$dbSchemaDiff |
ezcDbSchemaDiff |
Method | Description |
---|---|
ezcDbSchemaDiffDbWriter::applyDiffToDb() |
Applies the differences contained in $schemaDiff to the database handler $db |
Returns the differences definition in $dbSchema as database specific SQL DDL queries.
Name | Type | Description |
---|---|---|
$dbSchemaDiff |
ezcDbSchemaDiff | |
$db |
ezcDbHandler |
Method | Description |
---|---|
ezcDbSchemaDiffDbWriter::convertDiffToDDL() |
Returns an array with SQL DDL statements from the differences from $schemaDiff |
Converts the generic field type contained in $fieldDefinition to a database specific field definition.
Name | Type | Description |
---|---|---|
$fieldDefinition |
ezcDbSchemaField |
Adds a "alter table" query to add the field $fieldName to $tableName with the definition $fieldDefinition.
Name | Type | Description |
---|---|---|
$tableName |
string | |
$fieldName |
string | |
$fieldDefinition |
ezcDbSchemaField |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateAddFieldSql() |
Adds a "alter table" query to add the field $fieldName to $tableName with the definition $fieldDefinition. |
Adds a "alter table" query to add the index $indexName to the table $tableName with definition $indexDefinition to the internal list of queries
Name | Type | Description |
---|---|---|
$tableName |
string | |
$indexName |
string | |
$indexDefinition |
ezcDbSchemaIndex |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateAddIndexSql() |
Adds a "alter table" query to add the index $indexName to the table $tableName with definition $indexDefinition to the internal list of queries |
Generate additional drop sequence statements
Some sequences might not be dropped automatically, this method generates additional DROP SEQUENCE queries for those.
Since Oracle only allows sequence identifiers up to 30 characters sequences for long table / column names may be shortened. In this case the sequence name does not started with the table name any more, thus does not get dropped together with the table automatically.
This method requires a DB connection to check which sequences have been defined in the database, because the information about fields is not available otherwise.
Name | Type | Description |
---|---|---|
$dbSchemaDiff |
ezcDbSchemaDiff | |
$db |
ezcDbHandler |
Adds a "alter table" query to change the field $fieldName to $tableName with the definition $fieldDefinition.
Name | Type | Description |
---|---|---|
$tableName |
string | |
$fieldName |
string | |
$fieldDefinition |
ezcDbSchemaField |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateChangeFieldSql() |
Adds a "alter table" query to change the field $fieldName to $tableName with the definition $fieldDefinition. |
Adds a "create table" query for the table $tableName with definition $tableDefinition to the internal list of queries.
Adds additional CREATE queries for sequences and triggers to implement autoincrement fields that not supported in Oracle directly.
Name | Type | Description |
---|---|---|
$tableName |
string | |
$tableDefinition |
ezcDbSchemaTable |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateCreateTableSql() |
Adds a "create table" query for the table $tableName with definition $tableDefinition to the internal list of queries. |
Returns an appropriate default value for $type with $value.
Name | Type | Description |
---|---|---|
$type |
string | |
$value |
mixed |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateDefault() |
Returns an appropriate default value for $type with $value. |
Generates queries to upgrade a the table $tableName with the differences in $tableDiff.
This method generates queries to migrate a table to a new version with the changes that are stored in the $tableDiff property. It will call different subfunctions for the different types of changes, and those functions will add queries to the internal list of queries that is stored in $this->queries.
Name | Type | Description |
---|---|---|
$tableName |
string | |
$tableDiff |
ezcDbSchemaTableDiff |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateDiffSchemaTableAsSql() |
Generates queries to upgrade a the table $tableName with the differences in $tableDiff. |
Adds a "alter table" query to drop the field $fieldName from $tableName.
Name | Type | Description |
---|---|---|
$tableName |
string | |
$fieldName |
string |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateDropFieldSql() |
Adds a "alter table" query to drop the field $fieldName from $tableName. |
Adds a "alter table" query to remote the index $indexName from the table $tableName to the internal list of queries.
Name | Type | Description |
---|---|---|
$tableName |
string | |
$indexName |
string |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateDropIndexSql() |
Adds a "alter table" query to remote the index $indexName from the table $tableName to the internal list of queries. |
Adds a "drop table" query for the table $tableName to the internal list of queries.
Name | Type | Description |
---|---|---|
$tableName |
string |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateDropTableSql() |
Adds a "drop table" query for the table $tableName to the internal list of queries. |
Returns a column definition for $fieldName with definition $fieldDefinition.
Name | Type | Description |
---|---|---|
$fieldName |
string | |
$fieldDefinition |
ezcDbSchemaField | |
$autoincrementField |
string |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::generateFieldSql() |
Returns a column definition for $fieldName with definition $fieldDefinition. |
Returns what type of schema difference writer this class implements.
This method always returns ezcDbSchema::DATABASE
Method | Description |
---|---|
ezcDbSchemaDiffWriter::getDiffWriterType() |
Returns what type of schema difference writer this class implements. |
Checks if query allowed.
Perform testing if table exist for DROP TABLE query to avoid stoping execution while try to drop not existent table.
Name | Type | Description |
---|---|---|
$db |
ezcDbHandler | |
$query |
string |
Method | Description |
---|---|
ezcDbSchemaCommonSqlWriter::isQueryAllowed() |
Checks if the query is allowed. |
Method | Description |
---|---|
ezcDbSchemaDbWriter::isQueryAllowed() |
Checks if the query is allowed. |