PHP Class Horde_Db_Adapter_Base_Schema, horde

Author: Mike Naberezny ([email protected])
Author: Derek DeVries ([email protected])
Author: Chuck Hagenbuch ([email protected])
Author: Jan Schneider ([email protected])
Afficher le fichier Open project: horde/horde Class Usage Examples

Protected Properties

Свойство Type Description
$_adapter Horde_Db_Adapter_Base A Horde_Db_Adapter instance.
$_adapterMethods array Method names are in the keys.

Méthodes publiques

Méthode Description
__call ( string $method, array $args ) : mixed Delegates calls to the adapter object.
__construct ( Horde_Db_Adapter $adapter ) Constructor.
__get ( string $key ) : object Delegates access to $_cache and $_logger to the adapter object.
addColumn ( string $tableName, string $columnName, string $type, array $options = [] ) Adds a new column to a table.
addColumnOptions ( string $sql, array $options ) : string Adds default/null options to column SQL definitions.
addIndex ( string $tableName, string | array $columnName, array $options = [] ) : string Adds a new index to a table.
addOrderByForAssocLimiting ( string $sql, array $options ) : string Adds an ORDER BY clause to an existing query.
addPrimaryKey ( string $tableName, $columns ) Adds a primary key to a table.
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.
column ( string $tableName, string $columnName ) : Horde_Db_Adapter_Base_Column Returns a table column.
columns ( string $tableName, string $name = null ) : array Returns a list of table columns.
createDatabase ( string $name, array $options = [] ) Creates a database.
createTable ( string $name, array $options = [] ) : Horde_Db_Adapter_Base_TableDefinition Creates a new table.
currentDatabase ( ) : string Returns the name of the currently selected database.
distinct ( string $columns, string $orderBy = null ) : string Generates a DISTINCT clause for SELECT queries.
dropDatabase ( string $name ) Drops a database.
dropTable ( string $name ) Drops a table from the database.
endTable ( string | Horde_Db_Adapter_Base_TableDefinition $name, array $options = [] ) Finishes and executes table creation.
indexName ( string $tableName, string | array $options = [] ) Builds the name for an index.
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_Base_Column Factory for Column objects.
makeColumnDefinition ( $base, $name, $type, $limit = null, $precision = null, $scale = null, $unsigned = null, $default = null, $null = null, $autoincrement = null ) : Horde_Db_Adapter_Base_ColumnDefinition Factory for ColumnDefinition objects.
makeIndex ( string $table, string $name, boolean $primary, boolean $unique, array $columns ) : Horde_Db_Adapter_Base_Index Factory for Index objects.
makeTable ( $name, $primaryKey, $columns, $indexes ) : Horde_Db_Adapter_Base_Table Factory for Table objects.
makeTableDefinition ( $name, $base, $options = [] ) : Horde_Db_Adapter_Base_TableDefinition Factory for TableDefinition 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.
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.
quoteColumnName ( string $name ) : string Returns a quoted form of the column name.
quoteDate ( $value ) : string Returns a quoted date value.
quoteFalse ( ) : string Returns a quoted boolean false.
quoteString ( string $string ) : string Quotes a string, escaping any ' (single quote) and \ (backslash) characters.
quoteTableName ( string $name ) : string Returns a quoted form of the table name.
quoteTrue ( ) : string Returns a quoted boolean true.
recreateDatabase ( string $name ) Recreates, i.e. drops then creates a database.
removeColumn ( string $tableName, string $columnName ) Removes a column from a table.
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.
setAdapter ( Horde_Db_Adapter $adapter ) Setter for a Horde_Db_Adapter instance.
table ( string $tableName, string $name = null ) : Horde_Db_Adapter_Base_Table Returns a Horde_Db_Adapter_Base_Table object for a table.
tableAliasFor ( string $tableName ) : string Converts a table name into a suitable table alias.
tableAliasLength ( ) : integer Returns the maximum length a table alias can have.
tables ( ) : array Returns a list of all tables of the current database.
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
_clearTableCache ( string $tableName ) Clears the cache for tables when altering them.
_escapePrepare ( string $query ) : string Escapes all characters in a string that are placeholders for prepare/execute methods.

Method Details

__call() public méthode

Delegates calls to the adapter object.
public __call ( string $method, array $args ) : mixed
$method string A method name.
$args array Method parameters.
Résultat mixed The method call result.

__construct() public méthode

Constructor.
public __construct ( Horde_Db_Adapter $adapter )
$adapter Horde_Db_Adapter A Horde_Db_Adapter instance.

__get() public méthode

Delegates access to $_cache and $_logger to the adapter object.
public __get ( string $key ) : object
$key string Property name. Only '_cache' and '_logger' are supported.
Résultat object The request property object.

_clearTableCache() protected méthode

Clears the cache for tables when altering them.
protected _clearTableCache ( string $tableName )
$tableName string A table name.

_escapePrepare() protected méthode

Escapes all characters in a string that are placeholders for prepare/execute methods.
protected _escapePrepare ( string $query ) : string
$query string A string to escape.
Résultat string The correctly escaped string.

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.

addColumnOptions() public méthode

Adds default/null options to column SQL definitions.
public addColumnOptions ( string $sql, array $options ) : string
$sql string Existing SQL definition for a column.
$options array Column options: - column: (Horde_Db_Adapter_Base_ColumnDefinition The column definition class. - null: (boolean) Whether to allow NULL values. - default: (mixed) Default column value. - autoincrement: (boolean) Whether the column is an autoincrement column. Driver depedendent.
Résultat string The manipulated SQL definition.

addIndex() public méthode

The index will be named after the table and the first column names, unless you pass 'name' as an option. When creating an index on multiple columns, the first column is used as a name for the index. For example, when you specify an index on two columns 'first' and 'last', the DBMS creates an index for both columns as well as an index for the first colum 'first'. Using just the first name for this index makes sense, because you will never have to create a singular index with this name. Examples: Creating a simple index $schema->addIndex('suppliers', 'name'); generates CREATE INDEX suppliers_name_index ON suppliers(name) Creating a unique index $schema->addIndex('accounts', array('branch_id', 'party_id'), array('unique' => true)); generates CREATE UNIQUE INDEX accounts_branch_id_index ON accounts(branch_id, party_id) Creating a named index $schema->addIndex('accounts', array('branch_id', 'party_id'), array('unique' => true, 'name' => 'by_branch_party')); generates CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id)
public addIndex ( string $tableName, string | array $columnName, array $options = [] ) : string
$tableName string A table name.
$columnName string | array One or more column names.
$options array Index options: - name: (string) the index name. - unique: (boolean) create a unique index?
Résultat string The index name. @since Horde_Db 2.1.0

addOrderByForAssocLimiting() public méthode

Adds an ORDER BY clause to an existing query.
public addOrderByForAssocLimiting ( 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.

addPrimaryKey() public méthode

Adds a primary key to a table.
public addPrimaryKey ( string $tableName, $columns )
$tableName string A table name.

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() abstract public méthode

Changes an existing column's definition.
abstract 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() abstract 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.
abstract public changeColumnDefault ( string $tableName, string $columnName, mixed $default )
$tableName string A table name.
$columnName string A column name.
$default mixed The new default value.

column() public méthode

Returns a table column.
public column ( string $tableName, string $columnName ) : Horde_Db_Adapter_Base_Column
$tableName string A table name.
$columnName string A column name.
Résultat Horde_Db_Adapter_Base_Column A column object.

columns() abstract public méthode

Returns a list of table columns.
abstract 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() abstract public méthode

Creates a database.
abstract public createDatabase ( string $name, array $options = [] )
$name string A database name.
$options array Database options.

createTable() public méthode

The $options hash can include the following keys: - autoincrementKey (string|array): The name of the autoincrementing primary key, if one is to be added automatically. Defaults to "id". - options (array): Any extra options you want appended to the table definition. - temporary (boolean): Make a temporary table. - force (boolean): Set to true or false to drop the table before creating it. Defaults to false. Examples: Add a backend specific option to the generated SQL (MySQL) $schema->createTable('suppliers', array('options' => 'ENGINE=InnoDB DEFAULT CHARSET=utf8'))); generates:
 CREATE TABLE suppliers (
   id int(10) UNSIGNED  NOT NULL AUTO_INCREMENT PRIMARY KEY
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
Rename the primary key column $table = $schema->createTable('objects', array('autoincrementKey' => 'guid')); $table->column('name', 'string', array('limit' => 80)); $table->end(); generates:
 CREATE TABLE objects (
   guid int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
   name varchar(80)
 )
Do not add a primary key column, use fluent interface, use type method. $schema->createTable('categories_suppliers', array('autoincrementKey' => false)) ->column('category_id', 'integer') ->integer('supplier_id') ->end(); generates:
 CREATE TABLE categories_suppliers (
   category_id int(11),
   supplier_id int(11)
 )
See also Horde_Db_Adapter_Base_TableDefinition::column() for details on how to create columns.
public createTable ( string $name, array $options = [] ) : Horde_Db_Adapter_Base_TableDefinition
$name string A table name.
$options array A list of table options, see the method description.
Résultat Horde_Db_Adapter_Base_TableDefinition The definition of the created table.

currentDatabase() abstract public méthode

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

distinct() public méthode

$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() abstract public méthode

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

dropTable() public méthode

Drops a table from the database.
public dropTable ( string $name )
$name string A table name.

endTable() public méthode

Finishes and executes table creation.
public endTable ( string | Horde_Db_Adapter_Base_TableDefinition $name, array $options = [] )
$name string | Horde_Db_Adapter_Base_TableDefinition A table name or object.
$options array A list of options. See createTable().

indexName() public méthode

Builds the name for an index.
public indexName ( string $tableName, string | array $options = [] )
$tableName string A table name.
$options string | array Either a column name or index options: - column: (string|array) column name(s). - name: (string) the index name to fall back to if no column names specified.

indexes() abstract public méthode

Returns a list of tables indexes.
abstract 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.
Deprecation: since version 1.2.0. This function does not work with SQLite as a backend so you should avoid using it. Use "modifyDate()" instead.
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_Base_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_Base_Column A column object.

makeColumnDefinition() public méthode

Factory for ColumnDefinition objects.
public makeColumnDefinition ( $base, $name, $type, $limit = null, $precision = null, $scale = null, $unsigned = null, $default = null, $null = null, $autoincrement = null ) : Horde_Db_Adapter_Base_ColumnDefinition
Résultat Horde_Db_Adapter_Base_ColumnDefinition A column definition object.

makeIndex() public méthode

Factory for Index objects.
public makeIndex ( string $table, string $name, boolean $primary, boolean $unique, array $columns ) : Horde_Db_Adapter_Base_Index
$table string The table the index is on.
$name string The index's name.
$primary boolean Is this a primary key?
$unique boolean Is this a unique index?
$columns array The columns this index covers.
Résultat Horde_Db_Adapter_Base_Index An index object.

makeTable() public méthode

Factory for Table objects.
public makeTable ( $name, $primaryKey, $columns, $indexes ) : Horde_Db_Adapter_Base_Table
Résultat Horde_Db_Adapter_Base_Table A table object.

makeTableDefinition() public méthode

Factory for TableDefinition objects.
public makeTableDefinition ( $name, $base, $options = [] ) : Horde_Db_Adapter_Base_TableDefinition
Résultat Horde_Db_Adapter_Base_TableDefinition A table definition 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() abstract public méthode

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

primaryKey() abstract public méthode

Returns a table's primary key.
abstract 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.

quoteColumnName() public méthode

Returns a quoted form of the column name.
public quoteColumnName ( string $name ) : string
$name string A column name.
Résultat string The quoted column name.

quoteDate() public méthode

Returns a quoted date value.
public quoteDate ( $value ) : string
Résultat string The quoted date value.

quoteFalse() public méthode

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

quoteString() public méthode

Quotes a string, escaping any ' (single quote) and \ (backslash) characters.
public quoteString ( string $string ) : string
$string string A string to escape.
Résultat string The escaped and quoted string.

quoteTableName() public méthode

Defaults to column name quoting.
public quoteTableName ( string $name ) : string
$name string A table name.
Résultat string The quoted table name.

quoteTrue() public méthode

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

recreateDatabase() public méthode

Recreates, i.e. drops then creates a database.
public recreateDatabase ( string $name )
$name string A database name.

removeColumn() public méthode

Removes a column from a table.
public removeColumn ( string $tableName, string $columnName )
$tableName string A table name.
$columnName string A column name.

removeIndex() public méthode

Examples: Remove the suppliers_name_index in the suppliers table: $schema->removeIndex('suppliers', 'name'); Remove the index named accounts_branch_id in the accounts table: $schema->removeIndex('accounts', array('column' => 'branch_id')); Remove the index named by_branch_party in the accounts table: $schema->removeIndex('accounts', array('name' => 'by_branch_party')); You can remove an index on multiple columns by specifying the first column: $schema->addIndex('accounts', array('username', 'password')) $schema->removeIndex('accounts', 'username');
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() abstract public méthode

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

renameColumn() abstract public méthode

Renames a column.
abstract 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() abstract public méthode

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

setAdapter() public méthode

Setter for a Horde_Db_Adapter instance.
public setAdapter ( Horde_Db_Adapter $adapter )
$adapter Horde_Db_Adapter A Horde_Db_Adapter instance.

table() public méthode

Returns a Horde_Db_Adapter_Base_Table object for a table.
public table ( string $tableName, string $name = null ) : Horde_Db_Adapter_Base_Table
$tableName string A table name.
$name string (can be removed?)
Résultat Horde_Db_Adapter_Base_Table A table object.

tableAliasFor() public méthode

Converts a table name into a suitable table alias.
public tableAliasFor ( string $tableName ) : string
$tableName string A table name.
Résultat string A possible alias name for the table.

tableAliasLength() public méthode

Returns the maximum length a table alias can have.
public tableAliasLength ( ) : integer
Résultat integer The maximum table alias length.

tables() abstract public méthode

Returns a list of all tables of the current database.
abstract 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

$_adapter protected_oe property

A Horde_Db_Adapter instance.
protected Horde_Db_Adapter_Base $_adapter
Résultat Horde_Db_Adapter_Base

$_adapterMethods protected_oe property

Method names are in the keys.
protected array $_adapterMethods
Résultat array