Path

ez components / documentation / api reference / 2007.1.1 / databaseschema


eZ Components 2007.1.1

DatabaseSchema: ezcDbSchema

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

Class: ezcDbSchema

ezcDbSchema is the main class for schema operations. [source]
ezcDbSchema represents the schema itself and provide proxy methods to the handlers that are able to load/save schemas from/to files, databases or other sources/destinations, depending on available schema handlers.
A database schema is a definition of all the tables inside a database, including field definitions and indexes.

Constants

DATABASE = 2 Used by reader and writer classes to inform that it implements a database based handler.
FILE = 1 Used by reader and writer classes to inform that it implements a file based handler.

Member Variables

public ezcDbSchemaOptions $options
Contains the options that are used by creating new schemas.
public array(string) $supportedTypes = array(
'integer', 'boolean', 'float', 'decimal', 'timestamp', 'time', 'date',
'text', 'blob', 'clob'
)

A list of all the supported database filed types

Method Summary

public array(string) convertToDDL( $db )
Returns the $db specific SQL queries that would create the tables defined in the schema.
public static void createFromDb( $db )
Factory method to create a ezcDbSchema object from the database $db.
public static void createFromFile( $format, $file )
Factory method to create a ezcDbSchema object from the file $file with the format $format.
public static ezcDbSchemaField createNewField( $fieldType, $fieldLength, $fieldNotNull, $fieldDefault, $fieldAutoIncrement, $fieldUnsigned )
Returns an object to represent a table's field in the schema.
public static ezcDbSchemaIndex createNewIndex( $fields, $primary, $unique )
Returns an object to represent a table's field in the schema.
public static ezcDbSchemaIndexField createNewIndexField( [$sorting = null] )
Returns an object to represent a table's field in the schema.
public static ezcDbSchemaTable createNewTable( $fields, $indexes )
Returns an object to represent a table in the schema.
public ezcDbSchema __construct( $schema, [$data = array()] )
Constructs a new ezcDbSchema object with schema definition $schema.
public array getData( )
Returns the internal data.
public array(string=>ezcDbSchemaTable) &getSchema( )
Returns the internal schema by reference.
public static void setOptions( $options )
Associates an option object with this static class.
public void writeToDb( $db )
Creates the tables defined in the schema into the database specified through $db.
public void writeToFile( $format, $file )
Writes the schema to the file $file in format $format.

Methods

convertToDDL

array(string) convertToDDL( $db )
Returns the $db specific SQL queries that would create the tables defined in the schema.

Parameters

Name Type Description
$db ezcDbHandler  

Throws

ClassDescription
ezcDbSchemaInvalidWriterClassException if the handler associated with the $format is not a database schema writer.

createFromDb

void createFromDb( $db )
Factory method to create a ezcDbSchema object from the database $db.

Parameters

Name Type Description
$db ezcDbHandler  

Throws

ClassDescription
ezcDbSchemaInvalidReaderClassException if the handler associated with the $format is not a database schema reader.

createFromFile

void createFromFile( string $format, string $file )
Factory method to create a ezcDbSchema object from the file $file with the format $format.

Parameters

Name Type Description
$format string  
$file string  

Throws

ClassDescription
ezcDbSchemaInvalidReaderClassException if the handler associated with the $format is not a file schema reader.

createNewField

ezcDbSchemaField createNewField( string $fieldType, integer $fieldLength, bool $fieldNotNull, mixed $fieldDefault, bool $fieldAutoIncrement, bool $fieldUnsigned )
Returns an object to represent a table's field in the schema.

Parameters

Name Type Description
$fieldType string  
$fieldLength integer  
$fieldNotNull bool  
$fieldDefault mixed  
$fieldAutoIncrement bool  
$fieldUnsigned bool  

createNewIndex

ezcDbSchemaIndex createNewIndex( array(string=>ezcDbSchemaIndexField) $fields, bool $primary, bool $unique )
Returns an object to represent a table's field in the schema.

Parameters

Name Type Description
$fields array(string=>ezcDbSchemaIndexField)  
$primary bool  
$unique bool  

createNewIndexField

ezcDbSchemaIndexField createNewIndexField( [ $sorting = null] )
Returns an object to represent a table's field in the schema.

Parameters

Name Type Description
$sorting  

createNewTable

ezcDbSchemaTable createNewTable( array(string=>ezcDbSchemaField) $fields, array(string=>ezcDbSchemaIndex) $indexes )
Returns an object to represent a table in the schema.

Parameters

Name Type Description
$fields array(string=>ezcDbSchemaField)  
$indexes array(string=>ezcDbSchemaIndex)  

__construct

ezcDbSchema __construct( $schema, [array $data = array()] )
Constructs a new ezcDbSchema object with schema definition $schema.

Parameters

Name Type Description
$schema array(ezcDbSchemaTable)  
$data array  

getData

array getData( )
Returns the internal data.
This data is not used anywhere though.

getSchema

array(string=>ezcDbSchemaTable) &getSchema( )
Returns the internal schema by reference.

setOptions

void setOptions( ezcDbSchemaOptions $options )
Associates an option object with this static class.

Parameters

Name Type Description
$options ezcDbSchemaOptions  

writeToDb

void writeToDb( $db )
Creates the tables defined in the schema into the database specified through $db.

Parameters

Name Type Description
$db ezcDbHandler  

Throws

ClassDescription
ezcDbSchemaInvalidWriterClassException if the handler associated with the $format is not a database schema writer.

writeToFile

void writeToFile( string $format, string $file )
Writes the schema to the file $file in format $format.

Parameters

Name Type Description
$format string Available formats are at least: 'array' and 'xml'.
$file string  

Throws

ClassDescription
ezcDbSchemaInvalidWriterClassException if the handler associated with the $format is not a file schema writer.

Last updated: Wed, 28 Nov 2007