Path

ez components / documentation / api reference / 2007.2.1 / databaseschema


eZ Components 2007.2.1

DatabaseSchema: ezcDbSchemaMysqlWriter

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcDbSchemaMysqlWriter

Handler for storing database schemas and applying differences that uses MySQL as backend. [source]

Implemented Interfaces

Parents

ezcDbSchemaCommonSqlWriter
   |
   --ezcDbSchemaMysqlWriter

Inherited Member Variables

From ezcDbSchemaCommonSqlWriter:
protected  ezcDbSchemaCommonSqlWriter::$queries
protected  ezcDbSchemaCommonSqlWriter::$schema

Method Summary

public void applyDiffToDb( $db, $dbSchemaDiff )
Applies the differences defined in $dbSchemaDiff to the database referenced by $db.
public array(string) convertDiffToDDL( $dbSchemaDiff, $dbSchema )
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.
public array(string) convertToDDL( $dbSchema, $dbSchema )
Returns the definition in $dbSchema as database specific SQL DDL queries.
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 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 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 )
Returns a column definition for $fieldName with definition $fieldDefinition.
public int getDiffWriterType( )
Returns what type of schema difference writer this class implements.
public int getWriterType( )
Returns what type of schema writer this class implements.
public void saveToDb( $db, $dbSchema )
Creates tables defined in $dbSchema in the database referenced by $db.

Inherited Methods

From ezcDbSchemaCommonSqlWriter :
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.

Methods

applyDiffToDb

void applyDiffToDb( $db, ezcDbSchemaDiff $dbSchemaDiff )
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.

Parameters

Name Type Description
$db ezcDbHandler  
$dbSchemaDiff ezcDbSchemaDiff  

convertDiffToDDL

array(string) convertDiffToDDL( ezcDbSchemaDiff $dbSchemaDiff, ezcDbSchema $dbSchema )
Returns the differences definition in $dbSchema as database specific SQL DDL queries.

Parameters

Name Type Description
$dbSchema ezcDbSchema  
$dbSchemaDiff ezcDbSchemaDiff  

convertFromGenericType

string convertFromGenericType( ezcDbSchemaField $fieldDefinition )
Converts the generic field type contained in $fieldDefinition to a database specific field definition.

Parameters

Name Type Description
$fieldDefinition ezcDbSchemaField  

convertToDDL

array(string) convertToDDL( ezcDbSchema $dbSchema, ezcDbSchema $dbSchema )
Returns the definition in $dbSchema as database specific SQL DDL queries.

Parameters

Name Type Description
$dbSchema ezcDbSchema  
$dbSchema ezcDbSchema  

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  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateAddFieldSql() Adds a "alter table" query to add the field $fieldName to $tableName with the definition $fieldDefinition.

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  

Redefinition of

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

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  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateChangeFieldSql() Adds a "alter table" query to change the field $fieldName to $tableName with the definition $fieldDefinition.

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

Name Type Description
$tableName string  
$tableDefinition ezcDbSchemaTable  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateCreateTableSql() Adds a "create table" query for the table $tableName with definition $tableDefinition to the internal list of queries.

generateCreateTableSqlStatement

string generateCreateTableSqlStatement( string $tableName )
Returns a "CREATE TABLE" SQL statement part for the table $tableName.

Parameters

Name Type Description
$tableName string  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateCreateTableSqlStatement() Returns a "CREATE TABLE" SQL statement part for the table $tableName.

generateDiffSchemaTableAsSql

void generateDiffSchemaTableAsSql( string $tableName, ezcDbSchemaTableDiff $tableDiff )
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

Name Type Description
$tableName string  
$tableDiff string  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateDiffSchemaTableAsSql() Generates queries to upgrade a the table $tableName with the differences in $tableDiff.

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  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateDropFieldSql() Adds a "alter table" query to drop the field $fieldName from $tableName.

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  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateDropIndexSql() Adds a "alter table" query to remote the index $indexName from the table $tableName to the internal list of queries.

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  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateDropTableSql() Adds a "drop table" query for the table $tableName to the internal list of queries.

generateFieldSql

string generateFieldSql( string $fieldName, ezcDbSchemaField $fieldDefinition )
Returns a column definition for $fieldName with definition $fieldDefinition.

Parameters

Name Type Description
$fieldName string  
$fieldDefinition ezcDbSchemaField  

Redefinition of

Method Description
ezcDbSchemaCommonSqlWriter::generateFieldSql() Returns a column definition for $fieldName with definition $fieldDefinition.

getDiffWriterType

int getDiffWriterType( )
Returns what type of schema difference writer this class implements.
This method always returns ezcDbSchema::DATABASE

getWriterType

int getWriterType( )
Returns what type of schema writer this class implements.
This method always returns ezcDbSchema::DATABASE

saveToDb

void saveToDb( $db, ezcDbSchema $dbSchema )
Creates tables defined in $dbSchema in the database referenced by $db.
This method uses convertToDDL to create SQL for the schema definition and then executes the return SQL statements on the database handler $db.

Parameters

Name Type Description
$db ezcDbHandler  
$dbSchema ezcDbSchema  

Last updated: Thu, 31 Jan 2008