DatabaseSchema: ezcDbSchemaCommonSqlWriter
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcDbSchemaCommonSqlWriter
|
An abstract class that implements some common functionality required by multiple database backends. [
source]
Implemented Interfaces
Descendents
| Child Class |
Description |
| ezcDbSchemaMysqlWriter |
Handler for storing database schemas and applying differences that uses MySQL as backend.
|
| ezcDbSchemaPgsqlWriter |
Handler for storing database schemas and applying differences that uses PostgreSQL as backend.
|
| ezcDbSchemaOracleWriter |
Handler for storing database schemas and applying differences that uses Oracle as backend.
|
| ezcDbSchemaSqliteWriter |
Handler for storing database schemas and applying differences that uses SQLite as backend.
|
Member Variables
|
protected array(string) |
$queries
Stores a list of queries that is generated by the various Database writing backends. |
|
protected ezcDbSchema |
$schema
Stores the schema definition where the generators operate on. |
Method Summary
|
public array(string) |
convertToDDL(
$dbSchema )
Returns an array with SQL DDL statements that creates the database definition in $dbSchema |
|
protected abstract void |
generateAddFieldSql(
$tableName, $fieldName, $fieldDefinition )
Adds a "alter table" query to add the field $fieldName to $tableName with the definition $fieldDefinition. |
|
protected abstract 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 abstract 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 |
generateCreateTableSqlStatement(
$tableName )
Returns a "CREATE TABLE" SQL statement part for the table $tableName. |
|
protected string |
generateDefault(
$type, $value )
Returns an appropriate default value for $type with $value. |
|
protected void |
generateDiffSchemaAsSql(
)
Generates queries to upgrade an existing database with the changes stored in $this->diffSchema. |
|
protected void |
generateDiffSchemaTableAsSql(
$tableName, $tableDiff )
Generates queries to upgrade a the table $tableName with the differences in $tableDiff. |
|
protected abstract void |
generateDropFieldSql(
$tableName, $fieldName )
Adds a "alter table" query to drop the field $fieldName from $tableName. |
|
protected abstract 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 abstract void |
generateDropTableSql(
$tableName )
Adds a "drop table" query for the table $tableName to the internal list of queries. |
|
protected abstract string |
generateFieldSql(
$fieldName, $fieldDefinition )
Returns a column definition for $fieldName with definition $fieldDefinition. |
|
protected void |
generateSchemaAsSql(
)
Creates SQL DDL statements from a schema definitin. |
|
public int |
getWriterType(
)
Returns what type of schema writer this class implements. |
|
public boolean |
isQueryAllowed(
$db, $query, $query
)
Checks if the query is allowed. |
|
public void |
saveToDb(
$db, $dbSchema )
Creates the tables contained in $schema in the database that is related to $db |
Methods
convertToDDL
Returns an array with SQL DDL statements that creates the database definition in $dbSchema
Converts the schema definition contained in $dbSchema to DDL SQL. This SQL can be used to create tables in an existing database according to the definition. The SQL queries are returned as an array.
Parameters
generateAddFieldSql
void generateAddFieldSql(
string
$tableName, string
$fieldName,
ezcDbSchemaField
$fieldDefinition )
Adds a "alter table" query to add the field $fieldName to $tableName with the definition $fieldDefinition.
Parameters
| Name |
Type |
Description |
$tableName |
string |
|
$fieldName |
string |
|
$fieldDefinition |
ezcDbSchemaField |
|
Redefined in descendants as
generateAddIndexSql
void generateAddIndexSql(
string
$tableName, string
$indexName,
ezcDbSchemaIndex
$indexDefinition )
Adds a "alter table" query to add the index $indexName to the table $tableName with definition $indexDefinition to the internal list of queries
Parameters
| Name |
Type |
Description |
$tableName |
string |
|
$indexName |
string |
|
$indexDefinition |
ezcDbSchemaIndex |
|
Redefined in descendants as
generateChangeFieldSql
void generateChangeFieldSql(
string
$tableName, string
$fieldName,
ezcDbSchemaField
$fieldDefinition )
Adds a "alter table" query to change the field $fieldName to $tableName with the definition $fieldDefinition.
Parameters
| Name |
Type |
Description |
$tableName |
string |
|
$fieldName |
string |
|
$fieldDefinition |
ezcDbSchemaField |
|
Redefined in descendants as
generateCreateTableSql
void generateCreateTableSql(
string
$tableName,
ezcDbSchemaTable
$tableDefinition )
Adds a "create table" query for the table $tableName with definition $tableDefinition to the internal list of queries.
Parameters
Redefined in descendants as
generateCreateTableSqlStatement
string generateCreateTableSqlStatement(
string
$tableName )
Returns a "CREATE TABLE" SQL statement part for the table $tableName.
Parameters
| Name |
Type |
Description |
$tableName |
string |
|
Redefined in descendants as
generateDefault
string generateDefault(
string
$type, mixed
$value )
Returns an appropriate default value for $type with $value.
Parameters
| Name |
Type |
Description |
$type |
string |
|
$value |
mixed |
|
Redefined in descendants as
generateDiffSchemaAsSql
void generateDiffSchemaAsSql(
)
Generates queries to upgrade an existing database with the changes stored in $this->diffSchema.
This method generates queries to migrate a database to a new version with the changes that are stored in the $this->diffSchema 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.
generateDiffSchemaTableAsSql
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.
Parameters
Redefined in descendants as
generateDropFieldSql
void generateDropFieldSql(
string
$tableName, string
$fieldName )
Adds a "alter table" query to drop the field $fieldName from $tableName.
Parameters
| Name |
Type |
Description |
$tableName |
string |
|
$fieldName |
string |
|
Redefined in descendants as
generateDropIndexSql
void generateDropIndexSql(
string
$tableName, string
$indexName )
Adds a "alter table" query to remote the index $indexName from the table $tableName to the internal list of queries.
Parameters
| Name |
Type |
Description |
$tableName |
string |
|
$indexName |
string |
|
Redefined in descendants as
generateDropTableSql
void generateDropTableSql(
string
$tableName )
Adds a "drop table" query for the table $tableName to the internal list of queries.
Parameters
| Name |
Type |
Description |
$tableName |
string |
|
Redefined in descendants as
generateFieldSql
Returns a column definition for $fieldName with definition $fieldDefinition.
Parameters
Redefined in descendants as
generateSchemaAsSql
void generateSchemaAsSql(
)
Creates SQL DDL statements from a schema definitin.
Loops over the tables in the schema definition in $this->schema and creates SQL SSL statements for this which it stores internally into the $this->queries array.
getWriterType
int getWriterType(
)
Returns what type of schema writer this class implements.
This method always returns ezcDbSchema::DATABASE
Redefined in descendants as
isQueryAllowed
boolean isQueryAllowed(
$db,
$query, string
$query
)
Checks if the query is allowed.
Perform testing if table exist for DROP TABLE query to avoid stoping execution while try to drop not existent table.
Parameters
Redefined in descendants as
saveToDb
Creates the tables contained in $schema in the database that is related to $db
This method takes the table definitions from $schema and will create the tables according to this definition in the database that is references by the $db handler. If tables with the same name as contained in the definitions already exist they will be removed and recreated with the new definition.
Parameters
Redefined in descendants as
Last updated: Mon, 10 Nov 2008