eZ Publish  [trunk]
eZDBSchemaInterface Class Reference

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

+ Inheritance diagram for eZDBSchemaInterface:

List of all members.

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
 $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.

Definition at line 61 of file ezdbschemainterface.php.


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.

Definition at line 858 of file ezdbschemainterface.php.

Referenced by generateUpgradeFile().

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

Fetches the data for all tables and returns an array containing the data. Empty tables are skipped. NB: once the data is generated, it might be cached. Use the 'force_read' parameter to force regeneration of the data

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()

Reimplemented in eZLintSchema.

Definition at line 107 of file ezdbschemainterface.php.

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.

Definition at line 823 of file ezdbschemainterface.php.

Referenced by generateDataValueTextSQL().

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()
Todo:
scan only once for fields of type char, not once per row

Definition at line 179 of file ezdbschemainterface.php.

Referenced by data().

eZDBSchemaInterface::generateAddFieldSql ( table_name,
field_name,
def,
params 
) [protected, pure virtual]

Implemented in eZPgsqlSchema, eZLintSchema, and eZMysqlSchema.

Definition at line 840 of file ezdbschemainterface.php.

Referenced by generateUpgradeFile().

eZDBSchemaInterface::generateAlterFieldSql ( table_name,
field_name,
def,
params 
) [protected, pure virtual]

Implemented in eZPgsqlSchema, eZLintSchema, and eZMysqlSchema.

Definition at line 832 of file ezdbschemainterface.php.

Referenced by generateUpgradeFile().

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

Reimplemented in eZLintSchema.

Definition at line 466 of file ezdbschemainterface.php.

Referenced by writeSQLSchemaFile().

eZDBSchemaInterface::generateDataValueTextSQL ( fieldDef,
value 
) [protected]

Reimplemented in eZLintSchema.

Definition at line 792 of file ezdbschemainterface.php.

Referenced by generateTableInsertSQLList().

eZDBSchemaInterface::generateDropFieldSql ( table_name,
field_name,
params 
) [private]

Reimplemented in eZPgsqlSchema, and eZLintSchema.

Definition at line 847 of file ezdbschemainterface.php.

Referenced by generateUpgradeFile().

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

Reimplemented in eZPgsqlSchema, and eZLintSchema.

Definition at line 497 of file ezdbschemainterface.php.

Referenced by writeSQLSchemaFile().

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

Reimplemented in eZLintSchema.

Definition at line 661 of file ezdbschemainterface.php.

Referenced by generateDataFile().

eZDBSchemaInterface::generateTableInsertSQLList ( tableName,
tableDef,
dataEntries,
params,
withClosure = true 
) [protected]

Reimplemented in eZPgsqlSchema.

Definition at line 669 of file ezdbschemainterface.php.

Referenced by generateTableInsert(), and insertSchema().

eZDBSchemaInterface::generateTableSchema ( tableName,
table,
params 
) [protected, pure 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.

Definition at line 651 of file ezdbschemainterface.php.

Referenced by generateSchemaFile(), and generateUpgradeFile().

eZDBSchemaInterface::generateTableSQLList ( tableName,
table,
params,
separateTypes 
) [protected, pure 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.

Definition at line 635 of file ezdbschemainterface.php.

Referenced by insertSchema().

eZDBSchemaInterface::generateUpgradeFile ( differences,
params = array() 
) [private]

Reimplemented in eZLintSchema.

Definition at line 520 of file ezdbschemainterface.php.

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

Definition at line 380 of file ezdbschemainterface.php.

Returns:
true if the schema system supports multi inserts. The default is to return false.

Reimplemented in eZMysqlSchema, and eZLintSchema.

Definition at line 882 of file ezdbschemainterface.php.

Referenced by generateTableInsertSQLList().

eZDBSchemaInterface::loadSchemaTransformationRules ( schemaType) [static, private]
Returns:
array of transformation rules on success, false otherwise

Definition at line 914 of file ezdbschemainterface.php.

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.

Definition at line 88 of file ezdbschemainterface.php.

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.

Definition at line 905 of file ezdbschemainterface.php.

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

Implemented in eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

Definition at line 894 of file ezdbschemainterface.php.

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.

Definition at line 1317 of file ezdbschemainterface.php.

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.

Definition at line 1046 of file ezdbschemainterface.php.

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

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.

Reimplemented in eZLintSchema.

Definition at line 159 of file ezdbschemainterface.php.

eZDBSchemaInterface::writeArraySchemaFile ( filename,
params = array() 
)

Write PHP schema definition to file using PHP array structures.

Parameters:
filename

Definition at line 323 of file ezdbschemainterface.php.

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

Write PHP schema definition to file using PHP serialized format.

Parameters:
filename

Definition at line 283 of file ezdbschemainterface.php.

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

Definition at line 243 of file ezdbschemainterface.php.

eZDBSchemaInterface::writeUpgradeFile ( differences,
filename,
params = array() 
) [pure virtual]

Write upgrade sql to file

Parameters:
differencesarray
filename

Definition at line 217 of file ezdbschemainterface.php.


Member Data Documentation

eZDBSchemaInterface::$Data

Definition at line 1374 of file ezdbschemainterface.php.

eZDBSchemaInterface::$DBInstance

eZDB instance

Definition at line 1372 of file ezdbschemainterface.php.

eZDBSchemaInterface::$Schema

Definition at line 1373 of file ezdbschemainterface.php.


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