eZPublish  4.4
eZDBSchemaInterface Class Referenceabstract

This class provide interface for DB schema library. More...

+ Inheritance diagram for eZDBSchemaInterface:

Public Member Functions

 appendSQLComments ($def, &$sql)
 
 data ($schema=false, $tableNameList=false, $params=array())
 
 escapeSQLString ($value)
 
 eZDBSchemaInterface ($params)
 
 insertSchema ($params=array())
 
 schema ($params=array())
 
 schemaName ()
 
 schemaType ()
 
 validate ()
 
 writeArraySchemaFile ($filename, $params=array())
 
 writeSerializedSchemaFile ($filename, $params=array())
 
 writeSQLSchemaFile ($filename, $params=array())
 
 writeUpgradeFile ($differences, $filename, $params=array())
 

Public Attributes

 $Data
 
 $DBInstance
 eZDB instance More...
 
 $Schema
 

Protected Member Functions

 fetchTableData ($tableInfo, $offset=false, $limit=false)
 
 generateAddFieldSql ($table_name, $field_name, $def, $params)
 
 generateAlterFieldSql ($table_name, $field_name, $def, $params)
 
 generateDataValueTextSQL ($fieldDef, $value)
 
 generateTableInsert ($tableName, $tableDef, $dataEntries, $params)
 
 generateTableInsertSQLList ($tableName, $tableDef, $dataEntries, $params, $withClosure=true)
 
 generateTableSchema ($tableName, $table, $params)
 
 generateTableSQLList ($tableName, $table, $params, $separateTypes)
 
 isMultiInsertSupported ()
 
 transformData (&$data, $toLocal)
 
 transformSchema (&$schema, $toLocal)
 

Private Member Functions

 generateDataFile ($schema, $data, $params)
 
 generateDropFieldSql ($table_name, $field_name, $params)
 
 generateSchemaFile ($schema, $params=array())
 
 generateUpgradeFile ($differences, $params=array())
 

Static Private Member Functions

 loadSchemaTransformationRules ($schemaType)
 

Detailed Description

This class provide interface for DB schema library.

Schema structure an array with Table structures, each key is the name of the table.

Table structure:

  • name - Name of table
  • fields - Array of Field structures, each key is the field name
  • indexes - Array of Index structures, each key is the index name
  • removed - Contains whether the table has been removed or not (Optional)
  • comments - An array with comment strings (Optional)

The removed entry will only be used when some comments have been added to the table. That way the comments can be added to the DROP TABLE statements.

Field structure:

  • length - A number which defines the length/size of the type or false
  • type - String containing the identifier of the Type, see Types below.
  • not_null - Is 1 if the type cannot be null, if 0 or not defined it can be null
  • default - The default value, the value depends on the type, false means no default value.

Index structure:

  • type - What kind of index, see Index Types.
  • fields - Array of field names the index is made on, or of sub-arrays where the field name is in the 'name' field

Index Types:

  • primary - A primary key, there can only be one primary key. This key will be named PRIMARY.
  • non-unique - A standard index
  • unique - A unique index

Field Types:

  • int - Integer, uses length to define number of digits.
  • float - Float, uses length to define number of digits.
  • auto_increment - Integer that auto increments (uses sequence+trigger).
  • varchar - String with variable length, uses length for max length.
  • char - String with fixed length, uses length.
  • longtext - String with 2^32 number of possible characters
  • mediumtext - String with 2^24 number of possible characters
  • shorttext - String with 2^16 number of possible characters

When stored as a PHP array the schema structure will be placed in a variable called $schema. The data structure will be placed in $data.

Member Function Documentation

eZDBSchemaInterface::appendSQLComments (   $def,
$sql 
)

Appends any comments found in $def to SQL text $sql as SQL comments.

Returns
true if any comments were added.

Referenced by generateUpgradeFile().

eZDBSchemaInterface::data (   $schema = false,
  $tableNameList = false,
  $params = array() 
)

Fetches the data for all tables and returns an array containing the data. NB: once the data is generated, it might be cached.

Parameters
$schemaA schema definition array which defines tables to fetch from. If false it will call schema() to fetch it.
$tableNameListAn array with tables to include, will further narrow tables in $schema. Use false to fetch all tables.
Note
You shouldn't need to reimplement this method since the default code will do simple SELECT queries
See Also
fetchTableData()

Referenced by insertSchema(), writeArraySchemaFile(), writeSerializedSchemaFile(), and writeSQLSchemaFile().

eZDBSchemaInterface::escapeSQLString (   $value)
pure virtual

This escapes the string according to the current database type and returns it.

Note
The default just returns the value so it must be reimplemented.

Implemented in eZPgsqlSchema, and eZMysqlSchema.

Referenced by generateDataValueTextSQL().

eZDBSchemaInterface::eZDBSchemaInterface (   $params)
eZDBSchemaInterface::fetchTableData (   $tableInfo,
  $offset = false,
  $limit = false 
)
protected

Fetches all rows for table defined in $tableInfo and returns this structure:

  • fields - Array with fields that were fetched from table, the order of the fields are the same as the order of the data
  • rows - Array with all rows, each row is an indexed array with the data.
Parameters
$tableInfoTable structure from schema definition.
$offsetWhich offset to start from or false to start at top
$limitHow many rows to fetch or false for no limit.
Note
You shouldn't need to reimplement this method since the default code will do simple SELECT queries
See Also
data()

Referenced by data().

eZDBSchemaInterface::generateAddFieldSql (   $table_name,
  $field_name,
  $def,
  $params 
)
protectedpure virtual

Implemented in eZPgsqlSchema, eZLintSchema, and eZMysqlSchema.

Referenced by generateUpgradeFile().

eZDBSchemaInterface::generateAlterFieldSql (   $table_name,
  $field_name,
  $def,
  $params 
)
protectedpure virtual

Implemented in eZPgsqlSchema, eZLintSchema, and eZMysqlSchema.

Referenced by generateUpgradeFile().

eZDBSchemaInterface::generateDataFile (   $schema,
  $data,
  $params 
)
private
Parameters
schemadatabase schema
Returns
schema for file output

Referenced by writeSQLSchemaFile().

eZDBSchemaInterface::generateDataValueTextSQL (   $fieldDef,
  $value 
)
protected
eZDBSchemaInterface::generateDropFieldSql (   $table_name,
  $field_name,
  $params 
)
private

Referenced by generateUpgradeFile().

eZDBSchemaInterface::generateSchemaFile (   $schema,
  $params = array() 
)
private
Parameters
schemadatabase schema
Returns
schema for file output

Referenced by writeSQLSchemaFile().

eZDBSchemaInterface::generateTableInsert (   $tableName,
  $tableDef,
  $dataEntries,
  $params 
)
protected
Note
Calls generateTableInsertSQLList and joins the SQLs to a string

Referenced by generateDataFile().

eZDBSchemaInterface::generateTableInsertSQLList (   $tableName,
  $tableDef,
  $dataEntries,
  $params,
  $withClosure = true 
)
protected
eZDBSchemaInterface::generateTableSchema (   $tableName,
  $table,
  $params 
)
protectedpure virtual

Generates the necessary SQLs to create the table and returns them all in a string.

Parameters
$tableNameThe table name
$tableThe table structure, see class definition for more details
Note
The SQLs will be ended with a semi-colon.
See Also
generateTableSQLList()

Implemented in eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

Referenced by generateSchemaFile(), and generateUpgradeFile().

eZDBSchemaInterface::generateTableSQLList (   $tableName,
  $table,
  $params,
  $separateTypes 
)
protectedpure virtual

Generates the necessary SQLs to create the table and returns them all in an array.

Parameters
$tableNameThe table name
$tableThe table structure, see class definition for more details
$paramsAn associative array with optional parameters which controls the output of SQLs
$separateTypesIf true then the returned array must be an associative array containing the SQL arrays split into multiple groups. The groups are:
  • sequences - List of sequences
  • tables - List of tables
  • trigger - List of triggers
  • indexes - List of indexes
  • constraints - List of constraints/primary keys
  • other - Other SQLs that doesn't fit into the above
Each group can be omitted and will be run in order.
Note
Each SQL in the array will be without a semi-colon
See Also
generateTableSchema()

Implemented in eZPgsqlSchema, and eZMysqlSchema.

Referenced by insertSchema().

eZDBSchemaInterface::generateUpgradeFile (   $differences,
  $params = array() 
)
private

Referenced by writeUpgradeFile().

eZDBSchemaInterface::insertSchema (   $params = array())

Insert PHP schema to the current database instance by running one SQL at a time.

Parameters
$paramsOptional parameter which controls what to insert:
  • schema - Whether to insert the schema or not, default is true.
  • data - Whether to insert the data or not, default is false
Returns
false if the schema could not be inserted, true if successful
eZDBSchemaInterface::isMultiInsertSupported ( )
protected
Returns
true if the schema system supports multi inserts. The default is to return false.

Referenced by generateTableInsertSQLList().

eZDBSchemaInterface::loadSchemaTransformationRules (   $schemaType)
staticprivate
Returns
array of transformation rules on success, false otherwise

Referenced by transformData(), and transformSchema().

eZDBSchemaInterface::schema (   $params = array())
pure virtual

Gets SQL db schema definition by analyzing the current DB instance and return it in array format. NB: once the schema is generated, it might be cached.

Parameters
$paramssupported options are 'meta_data' and 'format'
Returns
DB schema array

Implemented in eZPgsqlSchema, eZLintSchema, and eZMysqlSchema.

Referenced by data(), insertSchema(), writeArraySchemaFile(), writeSerializedSchemaFile(), and writeSQLSchemaFile().

eZDBSchemaInterface::schemaName ( )
pure virtual
Returns
Displayable name for schema type as string. Examples: 'MySQL', 'PostgreSQL', 'Oracle'
See Also
schemaType()

Implemented in eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

eZDBSchemaInterface::schemaType ( )
pure virtual
Returns
Identifier for schema type as string. Examples: 'mysql', 'postgresql', 'oracle'
See Also
schemaName()

Implemented in eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

Referenced by transformData(), and transformSchema().

eZDBSchemaInterface::transformData ( $data,
  $toLocal 
)
protected
Returns
true on success, false otherwise

Transforms database data to the given direction, applying the transformation rules.

Referenced by data(), and writeSQLSchemaFile().

eZDBSchemaInterface::transformSchema ( $schema,
  $toLocal 
)
protected
Returns
true on success, false otherwise

Transforms database schema to the given direction, applying the transformation rules.

Referenced by data(), eZMysqlSchema\schema(), eZPgsqlSchema\schema(), and writeSQLSchemaFile().

eZDBSchemaInterface::validate ( )

Validates the current schema and returns true if it is correct or false if something must be fixed.

Note
This should not be reimplemented by normal handlers, only schema checkers.
eZDBSchemaInterface::writeArraySchemaFile (   $filename,
  $params = array() 
)

Write PHP schema definition to file using PHP array structures.

Parameters
filename
eZDBSchemaInterface::writeSerializedSchemaFile (   $filename,
  $params = array() 
)

Write PHP schema definition to file using PHP serialized format.

Parameters
filename
eZDBSchemaInterface::writeSQLSchemaFile (   $filename,
  $params = array() 
)

Write SQL schema definition to file. The generated schema is always in 'local' format, as 'generic' SQL does not exist.

Parameters
filename
eZDBSchemaInterface::writeUpgradeFile (   $differences,
  $filename,
  $params = array() 
)
pure virtual

Write upgrade sql to file

Parameters
differencesarray
filename

Member Data Documentation

eZDBSchemaInterface::$Data

Referenced by data().

eZDBSchemaInterface::$DBInstance

eZDB instance

eZDBSchemaInterface::$Schema

The documentation for this class was generated from the following file: