PHP Class Horde_Db_Adapter_Postgresql_Schema, horde

Author: Mike Naberezny ([email protected])
Author: Derek DeVries ([email protected])
Author: Chuck Hagenbuch ([email protected])
Author: Jan Schneider ([email protected])
Inheritance: extends Horde_Db_Adapter_Base_Schema
ファイルを表示 Open project: horde/horde

Protected Properties

Property Type Description
$_schemaSearchPath string The active schema search path.
$_version integer Cached version.

Public Methods

Method Description
addColumn ( string $tableName, string $columnName, string $type, array $options = [] ) Adds a new column to a table.
addOrderByForAssociationLimiting ( string $sql, array $options ) : string Adds an ORDER BY clause to an existing query.
buildClause ( string $lhs, string $op, string $rhs, boolean $bind = false, array $params = [] ) : string | array Returns an expression using the specified operator.
changeColumn ( string $tableName, string $columnName, string $type, array $options = [] ) Changes an existing column's definition.
changeColumnDefault ( string $tableName, string $columnName, mixed $default ) Sets a new default value for a column.
changeColumnNull ( string $tableName, string $columnName, boolean $null, mixed $default = null ) Sets whether a column allows NULL values.
columns ( string $tableName, string $name = null ) : array Returns a list of table columns.
createDatabase ( string $name, array $options = [] ) Creates a database.
currentDatabase ( ) : string Returns the name of the currently selected database.
defaultSequenceName ( string $tableName, string $pk = null ) : string Returns the sequence name for a table's primary key or some other specified key.
distinct ( string $columns, string $orderBy = null ) : string Generates a DISTINCT clause for SELECT queries.
dropDatabase ( string $name ) Drops a database.
encoding ( ) : string Returns the current database's encoding format.
getClientMinMessages ( ) : string Returns the current client log message level.
indexes ( string $tableName, string $name = null ) : array Returns a list of tables indexes.
interval ( string $interval, string $precision ) : string Generates an INTERVAL clause for SELECT queries.
makeColumn ( string $name, string $default, string $sqlType = null, boolean $null = true ) : Horde_Db_Adapter_Postgresql_Column Factory for Column objects.
modifyDate ( string $reference, string $operator, integer $amount, string $interval ) : string Generates a modified date for SELECT queries.
nativeDatabaseTypes ( ) : array Returns a hash of mappings from the abstract data types to the native database types.
pkAndSequenceFor ( $table ) : array Returns a table's primary key and the key's sequence.
postgresqlVersion ( ) : integer Returns the version of the connected PostgreSQL server.
primaryKey ( string $tableName, string $name = null ) : Horde_Db_Adapter_Base_Index Returns a table's primary key.
quote ( mixed $value, object $column = null ) : string Quotes the column value to help prevent SQL injection attacks.
quoteBinary ( $value ) : string Returns a quoted binary value.
quoteFalse ( ) : string Returns a quoted boolean false.
quoteSequenceName ( string $name ) : string Returns a quoted sequence name.
quoteTrue ( ) : string Returns a quoted boolean true.
removeIndex ( string $tableName, string | array $options = [] ) Removes an index from a table.
removePrimaryKey ( string $tableName ) Removes a primary key from a table.
renameColumn ( string $tableName, string $columnName, string $newColumnName ) Renames a column.
renameTable ( string $name, string $newName ) Renames a table.
resetPkSequence ( $table, string $pk = null, string $sequence = null ) : integer Resets the sequence of a table's primary key to the maximum value.
setClientMinMessages ( string $level ) Sets the client log message level.
setSchemaSearchPath ( string $schemaCsv ) Sets the schema search path to a string of comma-separated schema names.
tableAliasLength ( ) : integer Returns the maximum length a table alias can have.
tables ( ) : array Returns a list of all tables in the schema search path.
typeToSql ( string $type, integer $limit = null, integer $precision = null, integer $scale = null, boolean $unsigned = null ) : string Generates the SQL definition for a column type.

Protected Methods

Method Description
_columnDefinitions ( $tableName, $name = null ) Returns the list of a table's column names, data types, and default values.
_quoteBinaryCallback ( array $matches ) : string Callback function for quoteBinary().

Method Details

_columnDefinitions() protected method

The underlying query is roughly: SELECT column.name, column.type, default.value FROM column LEFT JOIN default ON column.table_id = default.table_id AND column.num = default.column_num WHERE column.table_id = get_table_id('table_name') AND column.num > 0 AND NOT column.is_dropped ORDER BY column.num If the table name is not prefixed with a schema, the database will take the first match from the schema search path. Query implementation notes: - format_type includes the column size constraint, e.g. varchar(50) - ::regclass is a function that gives the id for a table name
protected _columnDefinitions ( $tableName, $name = null )

_quoteBinaryCallback() protected method

Callback function for quoteBinary().
protected _quoteBinaryCallback ( array $matches ) : string
$matches array Matches from preg_replace().
return string Escaped/encoded binary value.

addColumn() public method

Adds a new column to a table.
public addColumn ( string $tableName, string $columnName, string $type, array $options = [] )
$tableName string A table name.
$columnName string A column name.
$type string A data type.
$options array Column options. See Horde_Db_Adapter_Base_TableDefinition#column() for details.

addOrderByForAssociationLimiting() public method

PostgreSQL does not allow arbitrary ordering when using DISTINCT ON, so we work around this by wrapping the $sql string as a sub-select and ordering in that query.
public addOrderByForAssociationLimiting ( string $sql, array $options ) : string
$sql string An SQL query to manipulate.
$options array Options: - order: Order column an direction.
return string The manipulated SQL query.

buildClause() public method

Returns an expression using the specified operator.
public buildClause ( string $lhs, string $op, string $rhs, boolean $bind = false, array $params = [] ) : string | array
$lhs string The column or expression to test.
$op string The operator.
$rhs string The comparison value.
$bind boolean If true, the method returns the query and a list of values suitable for binding as an array.
$params array Any additional parameters for the operator.
return string | array The SQL test fragment, or an array containing the query and a list of values if $bind is true.

changeColumn() public method

Changes an existing column's definition.
public changeColumn ( string $tableName, string $columnName, string $type, array $options = [] )
$tableName string A table name.
$columnName string A column name.
$type string A data type.
$options array Column options. See Horde_Db_Adapter_Base_TableDefinition#column() for details.

changeColumnDefault() public method

If you want to set the default value to NULL, you are out of luck. You need to execute the apppropriate SQL statement yourself.
public changeColumnDefault ( string $tableName, string $columnName, mixed $default )
$tableName string A table name.
$columnName string A column name.
$default mixed The new default value.

changeColumnNull() public method

Sets whether a column allows NULL values.
public changeColumnNull ( string $tableName, string $columnName, boolean $null, mixed $default = null )
$tableName string A table name.
$columnName string A column name.
$null boolean Whether NULL values are allowed.
$default mixed The new default value.

columns() public method

Returns a list of table columns.
public columns ( string $tableName, string $name = null ) : array
$tableName string A table name.
$name string (can be removed?)
return array A list of Horde_Db_Adapter_Base_Column objects.

createDatabase() public method

Creates a database.
public createDatabase ( string $name, array $options = [] )
$name string A database name.
$options array Database options: owner, template, charset, tablespace, and connection_limit.

currentDatabase() public method

Returns the name of the currently selected database.
public currentDatabase ( ) : string
return string The database name.

defaultSequenceName() public method

If a sequence name doesn't exist, it is built from the table and primary key name.
public defaultSequenceName ( string $tableName, string $pk = null ) : string
$tableName string A table name.
$pk string A primary key name. Overrides the existing key name when building a new sequence name.
return string The key's sequence name.

distinct() public method

PostgreSQL requires the ORDER BY columns in the SELECT list for distinct queries, and requires that the ORDER BY include the DISTINCT column. $connection->distinct('posts.id', 'posts.created_at DESC')
public distinct ( string $columns, string $orderBy = null ) : string
$columns string A column list.
$orderBy string An ORDER clause.
return string The generated DISTINCT clause.

dropDatabase() public method

Drops a database.
public dropDatabase ( string $name )
$name string A database name.

encoding() public method

Returns the current database's encoding format.
public encoding ( ) : string
return string The current database's encoding format.

getClientMinMessages() public method

Returns the current client log message level.
public getClientMinMessages ( ) : string
return string The current client log message level.

indexes() public method

Returns a list of tables indexes.
public indexes ( string $tableName, string $name = null ) : array
$tableName string A table name.
$name string (can be removed?)
return array A list of Horde_Db_Adapter_Base_Index objects.

interval() public method

Generates an INTERVAL clause for SELECT queries.
public interval ( string $interval, string $precision ) : string
$interval string The interval.
$precision string The precision.
return string The generated INTERVAL clause.

makeColumn() public method

Factory for Column objects.
public makeColumn ( string $name, string $default, string $sqlType = null, boolean $null = true ) : Horde_Db_Adapter_Postgresql_Column
$name string The column's name, such as "supplier_id" in "supplier_id int(11)".
$default string The type-casted default value, such as "new" in "sales_stage varchar(20) default 'new'".
$sqlType string Used to extract the column's type, length and signed status, if necessary. For example "varchar" and "60" in "company_name varchar(60)" or "unsigned => true" in "int(10) UNSIGNED".
$null boolean Whether this column allows NULL values.
return Horde_Db_Adapter_Postgresql_Column A column object.

modifyDate() public method

Generates a modified date for SELECT queries.
public modifyDate ( string $reference, string $operator, integer $amount, string $interval ) : string
$reference string The reference date - this is a column referenced in the SELECT.
$operator string Add or subtract time? (+/-)
$amount integer The shift amount (number of days if $interval is DAY, etc).
$interval string The interval (SECOND, MINUTE, HOUR, DAY, MONTH, YEAR).
return string The generated INTERVAL clause.

nativeDatabaseTypes() public method

See TableDefinition::column() for details on the recognized abstract data types.
See also: TableDefinition::column()
public nativeDatabaseTypes ( ) : array
return array A database type map.

pkAndSequenceFor() public method

Returns a table's primary key and the key's sequence.
public pkAndSequenceFor ( $table ) : array
return array Array with two values: the primary key name and the key's sequence name.

postgresqlVersion() public method

Returns the version of the connected PostgreSQL server.
public postgresqlVersion ( ) : integer
return integer Zero padded PostgreSQL version, e.g. 80108 for 8.1.8.

primaryKey() public method

Returns a table's primary key.
public primaryKey ( string $tableName, string $name = null ) : Horde_Db_Adapter_Base_Index
$tableName string A table name.
$name string (can be removed?)
return Horde_Db_Adapter_Base_Index The primary key index object.

quote() public method

This method makes educated guesses on the scalar type based on the passed value. Make sure to correctly cast the value and/or pass the $column parameter to get the best results.
public quote ( mixed $value, object $column = null ) : string
$value mixed The scalar value to quote, a Horde_Db_Value, Horde_Date, or DateTime instance, or an object implementing quotedId().
$column object An object implementing getType().
return string The correctly quoted value.

quoteBinary() public method

Returns a quoted binary value.
public quoteBinary ( $value ) : string
return string The quoted binary value.

quoteFalse() public method

Returns a quoted boolean false.
public quoteFalse ( ) : string
return string The quoted boolean false.

quoteSequenceName() public method

PostgreSQL specific method.
public quoteSequenceName ( string $name ) : string
$name string A sequence name.
return string The quoted sequence name.

quoteTrue() public method

Returns a quoted boolean true.
public quoteTrue ( ) : string
return string The quoted boolean true.

removeIndex() public method

See parent class for examples.
public removeIndex ( string $tableName, string | array $options = [] )
$tableName string A table name.
$options string | array Either a column name or index options: - name: (string) the index name. - column: (string|array) column name(s).

removePrimaryKey() public method

Removes a primary key from a table.
public removePrimaryKey ( string $tableName )
$tableName string A table name.

renameColumn() public method

Renames a column.
public renameColumn ( string $tableName, string $columnName, string $newColumnName )
$tableName string A table name.
$columnName string A column name.
$newColumnName string The new column name.

renameTable() public method

Renames a table.
public renameTable ( string $name, string $newName )
$name string A table name.
$newName string The new table name.

resetPkSequence() public method

Resets the sequence of a table's primary key to the maximum value.
public resetPkSequence ( $table, string $pk = null, string $sequence = null ) : integer
$pk string A primary key name. Defaults to the existing primary key.
$sequence string A sequence name. Defaults to the sequence name of the existing primary key.
return integer The (next) sequence value if a primary key and a sequence exist.

setClientMinMessages() public method

Sets the client log message level.
public setClientMinMessages ( string $level )
$level string The client log message level. One of DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, LOG, NOTICE, WARNING, ERROR, FATAL, or PANIC.

setSchemaSearchPath() public method

Names beginning with $ have to be quoted (e.g. $user => '$user'). See: http://www.postgresql.org/docs/current/static/ddl-schemas.html
public setSchemaSearchPath ( string $schemaCsv )
$schemaCsv string A comma-separated schema name list.

tableAliasLength() public method

Returns the configured supported identifier length supported by PostgreSQL.
public tableAliasLength ( ) : integer
return integer The maximum table alias length.

tables() public method

Returns a list of all tables in the schema search path.
public tables ( ) : array
return array A table list.

typeToSql() public method

Generates the SQL definition for a column type.
public typeToSql ( string $type, integer $limit = null, integer $precision = null, integer $scale = null, boolean $unsigned = null ) : string
$type string A column type.
$limit integer Maximum column length (non decimal type only)
$precision integer The number precision (decimal type only).
$scale integer The number scaling (decimal columns only).
$unsigned boolean Whether the column is an unsigned number (non decimal columns only).
return string The SQL definition. If $type is not one of the internally supported types, $type is returned unchanged.

Property Details

$_schemaSearchPath protected_oe property

The active schema search path.
protected string $_schemaSearchPath
return string

$_version protected_oe property

Cached version.
protected int $_version
return integer