eZ Publish  [4.2]
eZPgsqlSchema Class Reference

Handles schemas for PostgreSQL. More...

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

List of all members.

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

Private Member Functions

 fetchTableFields ($table, $params)
 fetchTableIndexes ($table, $params)
 generateAddFieldSql ($table_name, $field_name, $def, $params)
 generateAddIndexSql ($table_name, $index_name, $def, $params, $withClosure)
 generateAlterFieldSql ($table_name, $field_name, $def, $params)
 generateDefaultDef ($table_name, $field_name, $def, $params)
 generateDropIndexSql ($table_name, $index_name, $def, $withClosure)
 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)
 primaryKeyIndexName ($tableName, $indexName, $fields)

Detailed Description

Handles schemas for PostgreSQL.

Definition at line 36 of file ezpgsqlschema.php.


Member Function Documentation

eZPgsqlSchema::convertFromStandardType ( type,
&$  length 
)

Definition at line 354 of file ezpgsqlschema.php.

Referenced by generateFieldDef().

eZPgsqlSchema::convertToStandardType ( type,
&$  length 
)

Definition at line 416 of file ezpgsqlschema.php.

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.

Definition at line 917 of file ezpgsqlschema.php.

eZPgsqlSchema::eZPgsqlSchema ( db)

Constructor

Parameters:
dbinstance

Definition at line 94 of file ezpgsqlschema.php.

eZPgsqlSchema::fetchTableFields ( table,
params 
) [private]

Definition at line 141 of file ezpgsqlschema.php.

Referenced by schema().

eZPgsqlSchema::fetchTableIndexes ( table,
params 
) [private]

Definition at line 252 of file ezpgsqlschema.php.

Referenced by schema().

eZPgsqlSchema::generateAddFieldSql ( table_name,
field_name,
def,
params 
) [private, virtual]

Implements eZDBSchemaInterface.

Definition at line 713 of file ezpgsqlschema.php.

eZPgsqlSchema::generateAddIndexSql ( table_name,
index_name,
def,
params,
withClosure 
) [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.

Definition at line 507 of file ezpgsqlschema.php.

Referenced by generateTableArrays().

eZPgsqlSchema::generateAlterFieldSql ( table_name,
field_name,
def,
params 
) [private, virtual]

Implements eZDBSchemaInterface.

Definition at line 730 of file ezpgsqlschema.php.

eZPgsqlSchema::generateDefaultDef ( table_name,
field_name,
def,
params 
) [private]

Definition at line 642 of file ezpgsqlschema.php.

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

eZPgsqlSchema::generateDropIndexSql ( table_name,
index_name,
def,
withClosure 
) [private]

Definition at line 571 of file ezpgsqlschema.php.

eZPgsqlSchema::generateDropTable ( table) [private]

Definition at line 912 of file ezpgsqlschema.php.

eZPgsqlSchema::generateFieldDef ( table_name,
field_name,
def,
add_default_not_null = true,
params 
) [private]
eZPgsqlSchema::generateNullDef ( table_name,
field_name,
def,
params 
) [private]

Definition at line 692 of file ezpgsqlschema.php.

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

eZPgsqlSchema::generateSchemaFile ( schema,
params = array() 
)
Parameters:
schemadatabase schema
Returns:
schema for file output

Reimplemented from eZDBSchemaInterface.

Definition at line 855 of file ezpgsqlschema.php.

eZPgsqlSchema::generateTableArrays ( table,
table_def,
params,
withClosure 
) [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.

Definition at line 775 of file ezpgsqlschema.php.

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.

Reimplemented from eZDBSchemaInterface.

Definition at line 838 of file ezpgsqlschema.php.

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.

Definition at line 746 of file ezpgsqlschema.php.

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.

Definition at line 755 of file ezpgsqlschema.php.

eZPgsqlSchema::isTypeLengthSupported ( pgType)

Definition at line 340 of file ezpgsqlschema.php.

Referenced by generateFieldDef().

eZPgsqlSchema::parseDefault ( default,
&$  autoinc 
)

Definition at line 456 of file ezpgsqlschema.php.

Referenced by fetchTableFields().

eZPgsqlSchema::parseType ( type_info,
&$  length_info 
)

Definition at line 327 of file ezpgsqlschema.php.

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.

Definition at line 411 of file ezpgsqlschema.php.

Referenced by fetchTableIndexes(), and generateAddIndexSql().

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

Definition at line 937 of file ezpgsqlschema.php.

Referenced by generateAddIndexSql(), and generateFieldDef().

eZPgsqlSchema::schema ( params = array()) [virtual]

Get SQL db schema

Returns:
DB schema array

Implements eZDBSchemaInterface.

Definition at line 99 of file ezpgsqlschema.php.

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

Implements eZDBSchemaInterface.

Definition at line 929 of file ezpgsqlschema.php.

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

Implements eZDBSchemaInterface.

Definition at line 924 of file ezpgsqlschema.php.


Member Data Documentation

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 83 of file ezpgsqlschema.php.

Referenced by fetchTableIndexes().

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 77 of file ezpgsqlschema.php.

Referenced by fetchTableIndexes().

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'

Definition at line 67 of file ezpgsqlschema.php.

Referenced by fetchTableFields().

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 57 of file ezpgsqlschema.php.

Referenced by fetchTableFields(), and fetchTableIndexes().

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 38 of file ezpgsqlschema.php.

Referenced by schema().


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