Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | List of all members
eZDBSchemaInterface Class Referenceabstract
Database schema abstraction layer

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

Inheritance diagram for eZDBSchemaInterface:

## Public Member Functions
| __construct ( $params)
| schema ( $params=array())
| data ( $schema=false, $tableNameList=false, $params=array())
| validate ()
| writeUpgradeFile ( $differences, $filename, $params=array())
| writeSQLSchemaFile ( $filename, $params=array())
| writeSerializedSchemaFile ( $filename, $params=array())
| writeArraySchemaFile ( $filename, $params=array())
| insertSchema ( $params=array())
| escapeSQLString ( $value)
| appendSQLComments ( $def, &$sql)
| schemaType ()
| schemaName ()

## Public Attributes
| $DBInstance
| eZDB instance More...
| $Schema
| $Data

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

## Private Member Functions
| generateDataFile ( $schema, $data, $params)
| generateSchemaFile ( $schema, $params=array())
| generateUpgradeFile ( $differences, $params=array())
| generateDropFieldSql ( $table_name, $field_name, $params)

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

## Constructor & Destructor Documentation

## ◆ __construct()

eZDBSchemaInterface::__construct | ( |  | $params | ) |

Constructor

Parameters

  array | $params |

Reimplemented in eZSQLiteSchema.

Definition at line 68 of file ezdbschemainterface.php.

## Member Function Documentation

## ◆ appendSQLComments()

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

## ◆ data()

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

  $schema | A schema definition array which defines tables to fetch from. If `false` it will call schema() to fetch it.
  $tableNameList | An 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.

References $Data, fetchTableData(), schema(), transformData(), and transformSchema().

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

## ◆ escapeSQLString()

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 eZSQLiteSchema, eZPgsqlSchema, and eZMysqlSchema.

Definition at line 823 of file ezdbschemainterface.php.

Referenced by generateDataValueTextSQL().

## ◆ fetchTableData()

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

  $tableInfo | Table structure from schema definition.
  $offset | Which offset to start from or `false` to start at top
  $limit | How 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().

## ◆ generateAddFieldSql()

eZDBSchemaInterface::generateAddFieldSql | ( |  | $table_name,
|  |  | $field_name,
|  |  | $def,
|  |  | $params
| ) |  |
| protected pure virtual

Implemented in eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

Definition at line 840 of file ezdbschemainterface.php.

Referenced by generateUpgradeFile().

## ◆ generateAlterFieldSql()

eZDBSchemaInterface::generateAlterFieldSql | ( |  | $table_name,
|  |  | $field_name,
|  |  | $def,
|  |  | $params
| ) |  |
| protected pure virtual

Implemented in eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

Definition at line 832 of file ezdbschemainterface.php.

Referenced by generateUpgradeFile().

## ◆ generateDataFile()

eZDBSchemaInterface::generateDataFile | ( |  | $schema,
|  |  | $data,
|  |  | $params
| ) |  |
| private

Parameters

  schema | database schema

Returns
  schema for file output

Reimplemented in eZLintSchema.

Definition at line 466 of file ezdbschemainterface.php.

References generateTableInsert().

Referenced by writeSQLSchemaFile().

## ◆ generateDataValueTextSQL()

eZDBSchemaInterface::generateDataValueTextSQL | ( |  | $fieldDef,
|  |  | $value
| ) |  |
| protected

Reimplemented in eZLintSchema.

Definition at line 792 of file ezdbschemainterface.php.

References escapeSQLString().

Referenced by generateTableInsertSQLList().

## ◆ generateDropFieldSql()

eZDBSchemaInterface::generateDropFieldSql | ( |  | $table_name,
|  |  | $field_name,
|  |  | $params
| ) |  |
| private

Reimplemented in eZPgsqlSchema, and eZLintSchema.

Definition at line 847 of file ezdbschemainterface.php.

Referenced by generateUpgradeFile().

## ◆ generateSchemaFile()

eZDBSchemaInterface::generateSchemaFile | ( |  | $schema,
|  |  | $params = `array()`
| ) |  |
| private

Parameters

  schema | database schema

Returns
  schema for file output

Reimplemented in eZPgsqlSchema, and eZLintSchema.

Definition at line 497 of file ezdbschemainterface.php.

References generateTableSchema().

Referenced by writeSQLSchemaFile().

## ◆ generateTableInsert()

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.

References generateTableInsertSQLList().

Referenced by generateDataFile().

## ◆ generateTableInsertSQLList()

eZDBSchemaInterface::generateTableInsertSQLList | ( |  | $tableName,
|  |  | $tableDef,
|  |  | $dataEntries,
|  |  | $params,
|  |  | $withClosure = `true`
| ) |  |
| protected

Reimplemented in eZPgsqlSchema.

Definition at line 669 of file ezdbschemainterface.php.

References generateDataValueTextSQL(), and isMultiInsertSupported().

Referenced by generateTableInsert(), eZPgsqlSchema\generateTableInsertSQLList(), and insertSchema().

## ◆ generateTableSchema()

eZDBSchemaInterface::generateTableSchema | ( |  | $tableName,
|  |  | $table,
|  |  | $params
| ) |  |
| protected pure virtual

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

Parameters

  $tableName | The table name
  $table | The table structure, see class definition for more details

Note
  The SQLs will be ended with a semi-colon.

See also
  generateTableSQLList()

Implemented in eZSQLiteSchema, eZMysqlSchema, eZLintSchema, and eZPgsqlSchema.

Definition at line 651 of file ezdbschemainterface.php.

Referenced by generateSchemaFile(), and generateUpgradeFile().

## ◆ generateTableSQLList()

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

  $tableName | The table name
  $table | The table structure, see class definition for more details
  $params | An associative array with optional parameters which controls the output of SQLs
  $separateTypes | If `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 eZSQLiteSchema, eZMysqlSchema, and eZPgsqlSchema.

Definition at line 635 of file ezdbschemainterface.php.

Referenced by insertSchema().

## ◆ generateUpgradeFile()

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

Reimplemented in eZLintSchema.

Definition at line 520 of file ezdbschemainterface.php.

References appendSQLComments(), generateAddFieldSql(), generateAlterFieldSql(), generateDropFieldSql(), and generateTableSchema().

Referenced by writeUpgradeFile().

## ◆ insertSchema()

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

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

Parameters

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

References data(), generateTableInsertSQLList(), generateTableSQLList(), schema(), and eZDebug\writeError().

## ◆ isMultiInsertSupported()

eZDBSchemaInterface::isMultiInsertSupported | ( |  | ) |
| protected

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

Reimplemented in eZSQLiteSchema, eZMysqlSchema, and eZLintSchema.

Definition at line 882 of file ezdbschemainterface.php.

Referenced by generateTableInsertSQLList().

## ◆ loadSchemaTransformationRules()

eZDBSchemaInterface::loadSchemaTransformationRules | ( |  | $schemaType | ) |
| static private

Returns
  array of transformation rules on success, false otherwise

Definition at line 914 of file ezdbschemainterface.php.

References eZDebug\writeError(), and eZDebug\writeWarning().

Referenced by transformData(), and transformSchema().

## ◆ schema()

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

  $params | supported options are 'meta_data' and 'format'

Returns
  DB schema array

Implemented in eZSQLiteSchema, eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

Definition at line 88 of file ezdbschemainterface.php.

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

## ◆ schemaName()

eZDBSchemaInterface::schemaName | ( |  | ) |
| pure virtual

Returns
  Displayable name for schema type as string. Examples: 'MySQL', 'PostgreSQL', 'Oracle'

See also
  schemaType()

Implemented in eZSQLiteSchema, eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

Definition at line 905 of file ezdbschemainterface.php.

## ◆ schemaType()

eZDBSchemaInterface::schemaType | ( |  | ) |
| pure virtual

Returns
  Identifier for schema type as string. Examples: 'mysql', 'postgresql', 'oracle'

See also
  schemaName()

Implemented in eZSQLiteSchema, eZPgsqlSchema, eZMysqlSchema, and eZLintSchema.

Definition at line 894 of file ezdbschemainterface.php.

Referenced by transformData(), and transformSchema().

## ◆ transformData()

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.

References loadSchemaTransformationRules(), schemaType(), and eZDebugSetting\writeDebug().

Referenced by data(), and writeSQLSchemaFile().

## ◆ transformSchema()

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.

References loadSchemaTransformationRules(), schemaType(), eZDebugSetting\writeDebug(), and eZDebug\writeWarning().

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

## ◆ validate()

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.

Reimplemented in eZLintSchema.

Definition at line 159 of file ezdbschemainterface.php.

## ◆ writeArraySchemaFile()

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.

References data(), and schema().

## ◆ writeSerializedSchemaFile()

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.

References data(), and schema().

## ◆ writeSQLSchemaFile()

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.

References data(), generateDataFile(), generateSchemaFile(), schema(), transformData(), and transformSchema().

## ◆ writeUpgradeFile()

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

Write upgrade sql to file

Parameters

  differences | array
  filename |

Definition at line 217 of file ezdbschemainterface.php.

References generateUpgradeFile().

## Member Data Documentation

## ◆ $Data

eZDBSchemaInterface::$Data

Definition at line 1374 of file ezdbschemainterface.php.

Referenced by data().

## ◆ $DBInstance

eZDBSchemaInterface::$DBInstance

eZDB instance

Definition at line 1372 of file ezdbschemainterface.php.

## ◆ $Schema

eZDBSchemaInterface::$Schema

Definition at line 1373 of file ezdbschemainterface.php.

Referenced by eZMysqlSchema\schema(), eZPgsqlSchema\schema(), and eZSQLiteSchema\schema().

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

- ezdbschemainterface.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.