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
Afficher le fichier Open project: horde/horde

Protected Properties

Свойство Type Description
$_schemaSearchPath string The active schema search path.
$_version integer Cached version.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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 méthode

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

addColumn() public méthode

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 méthode

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.
Résultat string The manipulated SQL query.

buildClause() public méthode

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.
Résultat string | array The SQL test fragment, or an array containing the query and a list of values if $bind is true.

changeColumn() public méthode

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 méthode

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 méthode

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 méthode

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

createDatabase() public méthode

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 méthode

Returns the name of the currently selected database.
public currentDatabase ( ) : string
Résultat string The database name.

defaultSequenceName() public méthode

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.
Résultat string The key's sequence name.

distinct() public méthode

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.
Résultat string The generated DISTINCT clause.

dropDatabase() public méthode

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

encoding() public méthode

Returns the current database's encoding format.
public encoding ( ) : string
Résultat string The current database's encoding format.

getClientMinMessages() public méthode

Returns the current client log message level.
public getClientMinMessages ( ) : string
Résultat string The current client log message level.

indexes() public méthode

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

interval() public méthode

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

makeColumn() public méthode

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.
Résultat Horde_Db_Adapter_Postgresql_Column A column object.

modifyDate() public méthode

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).
Résultat string The generated INTERVAL clause.

nativeDatabaseTypes() public méthode

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

pkAndSequenceFor() public méthode

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

postgresqlVersion() public méthode

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

primaryKey() public méthode

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?)
Résultat Horde_Db_Adapter_Base_Index The primary key index object.

quote() public méthode

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().
Résultat string The correctly quoted value.

quoteBinary() public méthode

Returns a quoted binary value.
public quoteBinary ( $value ) : string
Résultat string The quoted binary value.

quoteFalse() public méthode

Returns a quoted boolean false.
public quoteFalse ( ) : string
Résultat string The quoted boolean false.

quoteSequenceName() public méthode

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

quoteTrue() public méthode

Returns a quoted boolean true.
public quoteTrue ( ) : string
Résultat string The quoted boolean true.

removeIndex() public méthode

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 méthode

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

renameColumn() public méthode

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 méthode

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

resetPkSequence() public méthode

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.
Résultat integer The (next) sequence value if a primary key and a sequence exist.

setClientMinMessages() public méthode

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 méthode

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 méthode

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

tables() public méthode

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

typeToSql() public méthode

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).
Résultat 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
Résultat string

$_version protected_oe property

Cached version.
protected int $_version
Résultat integer