PHP 클래스 Horde_Db_Adapter_Base_Schema, horde

저자: Mike Naberezny ([email protected])
저자: Derek DeVries ([email protected])
저자: Chuck Hagenbuch ([email protected])
저자: Jan Schneider ([email protected])
파일 보기 프로젝트 열기: horde/horde 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_adapter Horde_Db_Adapter_Base A Horde_Db_Adapter instance.
$_adapterMethods array Method names are in the keys.

공개 메소드들

메소드 설명
__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.

보호된 메소드들

메소드 설명
_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.

메소드 상세

__call() 공개 메소드

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

__construct() 공개 메소드

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

__get() 공개 메소드

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.
리턴 object The request property object.

_clearTableCache() 보호된 메소드

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

_escapePrepare() 보호된 메소드

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

addColumn() 공개 메소드

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() 공개 메소드

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.
리턴 string The manipulated SQL definition.

addIndex() 공개 메소드

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?
리턴 string The index name. @since Horde_Db 2.1.0

addOrderByForAssocLimiting() 공개 메소드

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.
리턴 string The manipulated SQL query.

addPrimaryKey() 공개 메소드

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

buildClause() 공개 메소드

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

changeColumn() 추상적인 공개 메소드

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() 추상적인 공개 메소드

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() 공개 메소드

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.
리턴 Horde_Db_Adapter_Base_Column A column object.

columns() 추상적인 공개 메소드

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?)
리턴 array A list of Horde_Db_Adapter_Base_Column objects.

createDatabase() 추상적인 공개 메소드

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

createTable() 공개 메소드

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.
리턴 Horde_Db_Adapter_Base_TableDefinition The definition of the created table.

currentDatabase() 추상적인 공개 메소드

Returns the name of the currently selected database.
abstract public currentDatabase ( ) : string
리턴 string The database name.

distinct() 공개 메소드

$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.
리턴 string The generated DISTINCT clause.

dropDatabase() 추상적인 공개 메소드

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

dropTable() 공개 메소드

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

endTable() 공개 메소드

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() 공개 메소드

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() 추상적인 공개 메소드

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?)
리턴 array A list of Horde_Db_Adapter_Base_Index objects.

interval() 공개 메소드

Generates an INTERVAL clause for SELECT queries.
사용 중단: 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.
리턴 string The generated INTERVAL clause.

makeColumn() 공개 메소드

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.
리턴 Horde_Db_Adapter_Base_Column A column object.

makeColumnDefinition() 공개 메소드

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
리턴 Horde_Db_Adapter_Base_ColumnDefinition A column definition object.

makeIndex() 공개 메소드

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.
리턴 Horde_Db_Adapter_Base_Index An index object.

makeTable() 공개 메소드

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

makeTableDefinition() 공개 메소드

Factory for TableDefinition objects.
public makeTableDefinition ( $name, $base, $options = [] ) : Horde_Db_Adapter_Base_TableDefinition
리턴 Horde_Db_Adapter_Base_TableDefinition A table definition object.

modifyDate() 공개 메소드

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).
리턴 string The generated INTERVAL clause.

nativeDatabaseTypes() 추상적인 공개 메소드

See TableDefinition::column() for details on the recognized abstract data types.
또한 보기: TableDefinition::column()
abstract public nativeDatabaseTypes ( ) : array
리턴 array A database type map.

primaryKey() 추상적인 공개 메소드

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?)
리턴 Horde_Db_Adapter_Base_Index The primary key index object.

quote() 공개 메소드

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().
리턴 string The correctly quoted value.

quoteBinary() 공개 메소드

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

quoteColumnName() 공개 메소드

Returns a quoted form of the column name.
public quoteColumnName ( string $name ) : string
$name string A column name.
리턴 string The quoted column name.

quoteDate() 공개 메소드

Returns a quoted date value.
public quoteDate ( $value ) : string
리턴 string The quoted date value.

quoteFalse() 공개 메소드

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

quoteString() 공개 메소드

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

quoteTableName() 공개 메소드

Defaults to column name quoting.
public quoteTableName ( string $name ) : string
$name string A table name.
리턴 string The quoted table name.

quoteTrue() 공개 메소드

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

recreateDatabase() 공개 메소드

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

removeColumn() 공개 메소드

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

removeIndex() 공개 메소드

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() 추상적인 공개 메소드

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

renameColumn() 추상적인 공개 메소드

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() 추상적인 공개 메소드

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

setAdapter() 공개 메소드

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

table() 공개 메소드

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?)
리턴 Horde_Db_Adapter_Base_Table A table object.

tableAliasFor() 공개 메소드

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

tableAliasLength() 공개 메소드

Returns the maximum length a table alias can have.
public tableAliasLength ( ) : integer
리턴 integer The maximum table alias length.

tables() 추상적인 공개 메소드

Returns a list of all tables of the current database.
abstract public tables ( ) : array
리턴 array A table list.

typeToSql() 공개 메소드

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).
리턴 string The SQL definition. If $type is not one of the internally supported types, $type is returned unchanged.

프로퍼티 상세

$_adapter 보호되어 있는 프로퍼티

A Horde_Db_Adapter instance.
protected Horde_Db_Adapter_Base $_adapter
리턴 Horde_Db_Adapter_Base

$_adapterMethods 보호되어 있는 프로퍼티

Method names are in the keys.
protected array $_adapterMethods
리턴 array