eZPublishCommunityProject(LegacyStack)  2013.9
eZPgsqlSchema Class Reference

Handles schemas for PostgreSQL. More...

+ Inheritance diagram for eZPgsqlSchema:
+ Collaboration diagram for eZPgsqlSchema:

Public Member Functions

 convertFromStandardType ($type, &$length)
 
 convertToStandardType ($type, &$length)
 
 escapeSQLString ($value)
 
 eZPgsqlSchema ($db)
 
 generateSchemaFile ($schema, $params=array())
 
 generateTableInsertSQLList ($tableName, $tableDef, $dataEntries, $params, $withClosure=true)
 
 generateTableSchema ($table, $table_def, $params)
 
 generateTableSQLList ($table, $table_def, $params, $separateTypes)
 
 isTypeLengthSupported ($pgType)
 
 parseDefault ($default, &$autoinc)
 
 parseType ($type_info, &$length_info)
 
 reservedKeywordList ()
 
 schema ($params=array())
 
 schemaName ()
 
 schemaType ()
 
- Public Member Functions inherited from eZDBSchemaInterface
 appendSQLComments ($def, &$sql)
 
 data ($schema=false, $tableNameList=false, $params=array())
 
 eZDBSchemaInterface ($params)
 
 insertSchema ($params=array())
 
 validate ()
 
 writeArraySchemaFile ($filename, $params=array())
 
 writeSerializedSchemaFile ($filename, $params=array())
 
 writeSQLSchemaFile ($filename, $params=array())
 
 writeUpgradeFile ($differences, $filename, $params=array())
 

Public Attributes

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

Private Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from eZDBSchemaInterface
 fetchTableData ($tableInfo, $offset=false, $limit=false)
 
 generateDataValueTextSQL ($fieldDef, $value)
 
 generateTableInsert ($tableName, $tableDef, $dataEntries, $params)
 
 generateTableInsertSQLList ($tableName, $tableDef, $dataEntries, $params, $withClosure=true)
 
 isMultiInsertSupported ()
 
 transformData (&$data, $toLocal)
 
 transformSchema (&$schema, $toLocal)
 

Detailed Description

Handles schemas for PostgreSQL.

Member Function Documentation

eZPgsqlSchema::convertFromStandardType (   $type,
$length 
)

Referenced by generateFieldDef().

eZPgsqlSchema::convertToStandardType (   $type,
$length 
)

Referenced by parseType().

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.

eZPgsqlSchema::eZPgsqlSchema (   $db)

Constructor

Parameters
dbinstance
eZPgsqlSchema::fetchTableFields (   $table,
  $params 
)
private

Referenced by schema().

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

Referenced by schema().

eZPgsqlSchema::generateAddFieldSql (   $table_name,
  $field_name,
  $def,
  $params 
)
privatevirtual

Implements eZDBSchemaInterface.

eZPgsqlSchema::generateAddIndexSql (   $table_name,
  $index_name,
  $def,
  $params,
  $withClosure = true 
)
private
Parameters
$table_nameThe table name
$index_nameThe index name
$defThe index structure, see eZDBSchemaInterface for more details
$paramsAn associative array with optional parameters which controls the output of SQLs
$withClosureIf true then the SQLs will contain semi-colons to close them.

Referenced by generateTableArrays().

eZPgsqlSchema::generateAlterFieldSql (   $table_name,
  $field_name,
  $def,
  $params 
)
privatevirtual

Implements eZDBSchemaInterface.

eZPgsqlSchema::generateDefaultDef (   $table_name,
  $field_name,
  $def,
  $params 
)
private
eZPgsqlSchema::generateDropFieldSql (   $table_name,
  $field_name,
  $params 
)
private
eZPgsqlSchema::generateDropIndexSql (   $table_name,
  $index_name,
  $def,
  $withClosure = true 
)
private
eZPgsqlSchema::generateDropTable (   $table)
private
eZPgsqlSchema::generateFieldDef (   $table_name,
  $field_name,
  $def,
  $add_default_not_null = true,
  $params 
)
private
eZPgsqlSchema::generateNullDef (   $table_name,
  $field_name,
  $def,
  $params 
)
private
eZPgsqlSchema::generateSchemaFile (   $schema,
  $params = array() 
)
eZPgsqlSchema::generateTableArrays (   $table,
  $table_def,
  $params,
  $withClosure = true 
)
private
Parameters
$tableThe table name
$table_defThe table structure, see eZDBSchemaInterface for more details
$paramsAn associative array with optional parameters which controls the output of SQLs
$withClosureIf true then the SQLs will contain semi-colons to close them.

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

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

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

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

Implements eZDBSchemaInterface.

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

Implements eZDBSchemaInterface.

eZPgsqlSchema::isTypeLengthSupported (   $pgType)

Referenced by generateFieldDef().

eZPgsqlSchema::parseDefault (   $default,
$autoinc 
)

Referenced by fetchTableFields().

eZPgsqlSchema::parseType (   $type_info,
$length_info 
)

Referenced by fetchTableFields().

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.

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

eZPgsqlSchema::reservedKeywordList ( )
Returns
An array with keywords that are reserved by PostgreSQL.

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

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
$paramssupported options are 'meta_data' and 'format'
Returns
DB schema array

Implements eZDBSchemaInterface.

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

Implements eZDBSchemaInterface.

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

Implements eZDBSchemaInterface.

Member Data Documentation

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'

Referenced by fetchTableIndexes().

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'

Referenced by fetchTableIndexes().

const eZPgsqlSchema::FETCH_TABLE_DEF_QUERY
Initial value:
= '
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(d.adsrc 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'

Referenced by fetchTableFields().

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'

Referenced by fetchTableFields(), and fetchTableIndexes().

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'

Referenced by schema().


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