Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

Public Member Functions | Public Attributes | Private Member Functions | List of all members
eZPgsqlSchema Class Reference
Database schema abstraction layer

Handles schemas for PostgreSQL. More...

Inheritance diagram for eZPgsqlSchema:

## Public Member Functions
| schema ( $params=array())
| parseType ( $type_info, &$length_info)
| isTypeLengthSupported ( $pgType)
| convertFromStandardType ( $type, &$length)
| convertToStandardType ( $type, &$length)
| parseDefault ( $default, &$autoinc)
| generateTableSchema ( $table, $table_def, $params)
| generateTableSQLList ( $table, $table_def, $params, $separateTypes)
| generateTableInsertSQLList ( $tableName, $tableDef, $dataEntries, $params, $withClosure=true)
| generateSchemaFile ( $schema, $params=array())
| escapeSQLString ( $value)
| schemaType ()
| schemaName ()
| reservedKeywordList ()
Public Member Functions inherited from eZDBSchemaInterface
| __construct ( $params)
| 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())
| appendSQLComments ( $def, &$sql)

## Public Attributes
const | SHOW_TABLES_QUERY
const | FETCH_TABLE_OID_QUERY
const | FETCH_TABLE_DEF_QUERY
const | FETCH_INDEX_DEF_QUERY
const | FETCH_INDEX_COL_NAMES_QUERY
Public Attributes inherited from eZDBSchemaInterface
| $DBInstance
| eZDB instance More...
| $Schema
| $Data

## Private Member Functions
| fetchTableFields ( $table, $params)
| fetchTableIndexes ( $table, $params)
| primaryKeyIndexName ( $tableName, $indexName, $fields)
| generateAddIndexSql ( $table_name, $index_name, $def, $params, $withClosure=true)
| generateDropIndexSql ( $table_name, $index_name, $def, $withClosure=true)
| generateFieldDef ( $table_name, $field_name, $def, $add_default_not_null=true, $params)
| generateDefaultDef ( $table_name, $field_name, $def, $params)
| generateNullDef ( $table_name, $field_name, $def, $params)
| generateAddFieldSql ( $table_name, $field_name, $def, $params)
| generateDropFieldSql ( $table_name, $field_name, $params)
| generateAlterFieldSql ( $table_name, $field_name, $def, $params)
| generateTableArrays ( $table, $table_def, $params, $withClosure=true)
| generateDropTable ( $table)

## Additional Inherited Members
Protected Member Functions inherited from eZDBSchemaInterface
| fetchTableData ( $tableInfo, $offset=false, $limit=false)
| generateTableInsert ( $tableName, $tableDef, $dataEntries, $params)
| generateDataValueTextSQL ( $fieldDef, $value)
| isMultiInsertSupported ()
| transformSchema (&$schema, $toLocal)
| transformData (&$data, $toLocal)

## Detailed Description

Handles schemas for PostgreSQL.

Definition at line 18 of file ezpgsqlschema.php.

## Member Function Documentation

## ◆ convertFromStandardType()

eZPgsqlSchema::convertFromStandardType | ( |  | $type,
|  | & | $length
| ) |  |

Definition at line 327 of file ezpgsqlschema.php.

Referenced by generateFieldDef().

## ◆ convertToStandardType()

eZPgsqlSchema::convertToStandardType | ( |  | $type,
|  | & | $length
| ) |  |

Definition at line 378 of file ezpgsqlschema.php.

Referenced by parseType().

## ◆ escapeSQLString()

eZPgsqlSchema::escapeSQLString | ( |  | $value | ) |
| 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.

Implements eZDBSchemaInterface.

Definition at line 894 of file ezpgsqlschema.php.

## ◆ fetchTableFields()

eZPgsqlSchema::fetchTableFields | ( |  | $table,
|  |  | $params
| ) |  |
| private

Definition at line 113 of file ezpgsqlschema.php.

References FETCH_TABLE_DEF_QUERY, FETCH_TABLE_OID_QUERY, parseDefault(), and parseType().

Referenced by schema().

## ◆ fetchTableIndexes()

eZPgsqlSchema::fetchTableIndexes | ( |  | $table,
|  |  | $params
| ) |  |
| private

Definition at line 224 of file ezpgsqlschema.php.

References FETCH_INDEX_COL_NAMES_QUERY, FETCH_INDEX_DEF_QUERY, FETCH_TABLE_OID_QUERY, primaryKeyIndexName(), and eZDebug\writeError().

Referenced by schema().

## ◆ generateAddFieldSql()

eZPgsqlSchema::generateAddFieldSql | ( |  | $table_name,
|  |  | $field_name,
|  |  | $def,
|  |  | $params
| ) |  |
| private virtual

Implements eZDBSchemaInterface.

Definition at line 675 of file ezpgsqlschema.php.

References generateFieldDef().

## ◆ generateAddIndexSql()

eZPgsqlSchema::generateAddIndexSql | ( |  | $table_name,
|  |  | $index_name,
|  |  | $def,
|  |  | $params,
|  |  | $withClosure = `true`
| ) |  |
| private

Parameters

  $table_name | The table name
  $index_name | The index name
  $def | The index structure, see eZDBSchemaInterface for more details
  $params | An associative array with optional parameters which controls the output of SQLs
  $withClosure | If `true` then the SQLs will contain semi-colons to close them.

Definition at line 464 of file ezpgsqlschema.php.

References primaryKeyIndexName(), reservedKeywordList(), and eZDebug\writeError().

Referenced by generateTableArrays().

## ◆ generateAlterFieldSql()

eZPgsqlSchema::generateAlterFieldSql | ( |  | $table_name,
|  |  | $field_name,
|  |  | $def,
|  |  | $params
| ) |  |
| private virtual

Implements eZDBSchemaInterface.

Definition at line 707 of file ezpgsqlschema.php.

References generateFieldDef().

## ◆ generateDefaultDef()

eZPgsqlSchema::generateDefaultDef | ( |  | $table_name,
|  |  | $field_name,
|  |  | $def,
|  |  | $params
| ) |  |
| private

Definition at line 600 of file ezpgsqlschema.php.

## ◆ generateDropFieldSql()

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

Reimplemented from eZDBSchemaInterface.

Definition at line 692 of file ezpgsqlschema.php.

References reservedKeywordList().

## ◆ generateDropIndexSql()

eZPgsqlSchema::generateDropIndexSql | ( |  | $table_name,
|  |  | $index_name,
|  |  | $def,
|  |  | $withClosure = `true`
| ) |  |
| private

Definition at line 528 of file ezpgsqlschema.php.

References primaryKeyIndexName().

## ◆ generateDropTable()

eZPgsqlSchema::generateDropTable | ( |  | $table | ) |
| private

Definition at line 889 of file ezpgsqlschema.php.

## ◆ generateFieldDef()

eZPgsqlSchema::generateFieldDef | ( |  | $table_name,
|  |  | $field_name,
|  |  | $def,
|  |  | $add_default_not_null = `true`,
|  |  | $params
| ) |  |
| private

Definition at line 545 of file ezpgsqlschema.php.

References convertFromStandardType(), isTypeLengthSupported(), and reservedKeywordList().

Referenced by generateAddFieldSql(), generateAlterFieldSql(), and generateTableArrays().

## ◆ generateNullDef()

eZPgsqlSchema::generateNullDef | ( |  | $table_name,
|  |  | $field_name,
|  |  | $def,
|  |  | $params
| ) |  |
| private

Definition at line 654 of file ezpgsqlschema.php.

## ◆ generateSchemaFile()

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

Parameters

  schema | database schema

Returns
  schema for file output

Reimplemented from eZDBSchemaInterface.

Definition at line 832 of file ezpgsqlschema.php.

References generateTableArrays().

## ◆ generateTableArrays()

eZPgsqlSchema::generateTableArrays | ( |  | $table,
|  |  | $table_def,
|  |  | $params,
|  |  | $withClosure = `true`
| ) |  |
| private

Parameters

  $table | The table name
  $table_def | The table structure, see eZDBSchemaInterface for more details
  $params | An associative array with optional parameters which controls the output of SQLs
  $withClosure | If `true` then the SQLs will contain semi-colons to close them.

Definition at line 752 of file ezpgsqlschema.php.

References generateAddIndexSql(), and generateFieldDef().

Referenced by generateSchemaFile(), generateTableSchema(), and generateTableSQLList().

## ◆ generateTableInsertSQLList()

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

This calls eZDBSchemaInterface::generateTableInsertSQLList() and adds a setval SQL if the table has auto increments.

Reimplemented from eZDBSchemaInterface.

Definition at line 815 of file ezpgsqlschema.php.

References eZDBSchemaInterface\generateTableInsertSQLList().

## ◆ generateTableSchema()

eZPgsqlSchema::generateTableSchema | ( |  | $tableName,
|  |  | $table,
|  |  | $params
| ) |  |
| 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()

Implements eZDBSchemaInterface.

Definition at line 723 of file ezpgsqlschema.php.

References generateTableArrays().

## ◆ generateTableSQLList()

eZPgsqlSchema::generateTableSQLList | ( |  | $tableName,
|  |  | $table,
|  |  | $params,
|  |  | $separateTypes
| ) |  |
| 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()

Implements eZDBSchemaInterface.

Definition at line 732 of file ezpgsqlschema.php.

References generateTableArrays().

## ◆ isTypeLengthSupported()

eZPgsqlSchema::isTypeLengthSupported | ( |  | $pgType | ) |

Definition at line 312 of file ezpgsqlschema.php.

Referenced by generateFieldDef().

## ◆ parseDefault()

eZPgsqlSchema::parseDefault | ( |  | $default,
|  | & | $autoinc
| ) |  |

Definition at line 413 of file ezpgsqlschema.php.

Referenced by fetchTableFields().

## ◆ parseType()

eZPgsqlSchema::parseType | ( |  | $type_info,
|  | & | $length_info
| ) |  |

Definition at line 299 of file ezpgsqlschema.php.

References convertToStandardType().

Referenced by fetchTableFields().

## ◆ primaryKeyIndexName()

eZPgsqlSchema::primaryKeyIndexName | ( |  | $tableName,
|  |  | $indexName,
|  |  | $fields
| ) |  |
| private

The name will consist of the table name and _pkey, since it is only allowed to have one primary key pre table that shouldn't be a problem.

Returns
  A string representing the name of the primary key index.

Definition at line 373 of file ezpgsqlschema.php.

Referenced by fetchTableIndexes(), generateAddIndexSql(), and generateDropIndexSql().

## ◆ reservedKeywordList()

eZPgsqlSchema::reservedKeywordList | ( |  | ) |

Returns
  An array with keywords that are reserved by PostgreSQL.

Definition at line 912 of file ezpgsqlschema.php.

Referenced by generateAddIndexSql(), generateDropFieldSql(), and generateFieldDef().

## ◆ schema()

eZPgsqlSchema::schema | ( |  | $params = `array()` | ) |
| 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

Implements eZDBSchemaInterface.

Definition at line 71 of file ezpgsqlschema.php.

References eZDBSchemaInterface\$Schema, fetchTableFields(), fetchTableIndexes(), SHOW_TABLES_QUERY, and eZDBSchemaInterface\transformSchema().

## ◆ schemaName()

eZPgsqlSchema::schemaName | ( |  | ) |
| virtual

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

See also
  schemaType()

Implements eZDBSchemaInterface.

Definition at line 904 of file ezpgsqlschema.php.

## ◆ schemaType()

eZPgsqlSchema::schemaType | ( |  | ) |
| virtual

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

See also
  schemaName()

Implements eZDBSchemaInterface.

Definition at line 899 of file ezpgsqlschema.php.

## Member Data Documentation

## ◆ FETCH_INDEX_COL_NAMES_QUERY

const eZPgsqlSchema::FETCH_INDEX_COL_NAMES_QUERY

Initial value:
= '
SELECT a.attnum, a.attname
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = \'<<indexrelid>>\' AND a.attnum IN (<<attids>>) AND NOT a.attisdropped
ORDER BY a.attnum'

Definition at line 65 of file ezpgsqlschema.php.

Referenced by fetchTableIndexes().

## ◆ FETCH_INDEX_DEF_QUERY

const eZPgsqlSchema::FETCH_INDEX_DEF_QUERY

Initial value:
= '
SELECT c.relname, i.*
FROM pg_catalog.pg_index i, pg_catalog.pg_class c
WHERE indrelid = \'<<oid>>\'
AND i.indexrelid = c.oid'

Definition at line 59 of file ezpgsqlschema.php.

Referenced by fetchTableIndexes().

## ◆ FETCH_TABLE_DEF_QUERY

const eZPgsqlSchema::FETCH_TABLE_DEF_QUERY

Initial value:
= '
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(pg_get_expr(d.adbin, d.adrelid) for 128) FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef) as default,
a.attnotnull, a.attnum
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = \'<<oid>>\' AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum'

Definition at line 49 of file ezpgsqlschema.php.

Referenced by fetchTableFields().

## ◆ FETCH_TABLE_OID_QUERY

const eZPgsqlSchema::FETCH_TABLE_OID_QUERY

Initial value:
= '
SELECT c.oid,
n.nspname,
c.relname
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE pg_catalog.pg_table_is_visible(c.oid)
AND c.relname ~ \'^<<tablename>>$\'
ORDER BY 2, 3'

Definition at line 39 of file ezpgsqlschema.php.

Referenced by fetchTableFields(), and fetchTableIndexes().

## ◆ SHOW_TABLES_QUERY

const eZPgsqlSchema::SHOW_TABLES_QUERY

Initial value:
= '
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind
WHEN \'r\' THEN \'table\'
WHEN \'v\' THEN \'view\'
WHEN \'i\' THEN \'index\'
WHEN \'S\' THEN \'sequence\'
WHEN \'s\' THEN \'special\'
END as "Type",
u.usename as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN (\'r\',\'\')
AND n.nspname NOT IN (\'pg_catalog\', \'pg_toast\')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1, 2'

Definition at line 20 of file ezpgsqlschema.php.

Referenced by schema().

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

- ezpgsqlschema.php

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