Methods summary
public
|
|
public
|
#
setAdapter( Horde_Db_Adapter $adapter )
Setter for a Horde_Db_Adapter instance.
Setter for a Horde_Db_Adapter instance.
Parameters
- $adapter
- A Horde_Db_Adapter instance.
|
public
Horde_Db_Adapter_Base_Column
|
#
makeColumn( string $name, string $default, string $sqlType = null, boolean $null = true )
Factory for Column objects.
Factory for Column objects.
Parameters
- $name
- <p>The column's name, such as "supplier_id" in
"supplier_id int(11)".</p>
- $default
- <p>The type-casted default value, such as "new" in
"sales_stage varchar(20) default 'new'".</p>
- $sqlType
- <p>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".</p>
- $null
- Whether this column allows NULL values.
Returns
|
public
Horde_Db_Adapter_Base_ColumnDefinition
|
#
makeColumnDefinition( mixed $base, mixed $name, mixed $type, mixed $limit = null, mixed $precision = null, mixed $scale = null, mixed $unsigned = null, mixed $default = null, mixed $null = null, mixed $autoincrement = null )
Factory for ColumnDefinition objects.
Factory for ColumnDefinition objects.
Returns
|
public
Horde_Db_Adapter_Base_Index
|
#
makeIndex( string $table, string $name, boolean $primary, boolean $unique, array $columns )
Factory for Index objects.
Factory for Index objects.
Parameters
- $table
- The table the index is on.
- $name
- The index's name.
- $primary
- Is this a primary key?
- $unique
- Is this a unique index?
- $columns
- The columns this index covers.
Returns
|
public
Horde_Db_Adapter_Base_Table
|
#
makeTable( mixed $name, mixed $primaryKey, mixed $columns, mixed $indexes )
Factory for Table objects.
Factory for Table objects.
Returns
|
public
Horde_Db_Adapter_Base_TableDefinition
|
#
makeTableDefinition( mixed $name, mixed $base, mixed $options = array() )
Factory for TableDefinition objects.
Factory for TableDefinition objects.
Returns
|
public
mixed
|
#
__call( string $method, array $args )
Delegates calls to the adapter object.
Delegates calls to the adapter object.
Parameters
- $method
- A method name.
- $args
- Method parameters.
Returns
mixed The method call result.
Throws
BadMethodCallException if method doesn't exist in the adapter.
|
public
object
|
#
__get( string $key )
Delegates access to $_cache and $_logger to the adapter object.
Delegates access to $_cache and $_logger to the adapter object.
Parameters
- $key
- <p>Property name. Only '_cache' and '_logger' are
supported.</p>
Returns
object The request property object.
|
public
string
|
#
quote( mixed $value, object $column = null )
Quotes the column value to help prevent SQL injection attacks.
Quotes the column value to help prevent SQL injection attacks.
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.
Parameters
- $value
- <p>The scalar value to quote, a Horde_Db_Value,
Horde_Date, or DateTime instance, or an object
implementing quotedId().</p>
- $column
- An object implementing getType().
Returns
string The correctly quoted value.
|
public
string
|
#
quoteString( string $string )
Quotes a string, escaping any ' (single quote) and \ (backslash)
characters.
Quotes a string, escaping any ' (single quote) and \ (backslash)
characters.
Parameters
- $string
- A string to escape.
Returns
string The escaped and quoted string.
|
abstract public
string
|
#
quoteColumnName( string $name )
Returns a quoted form of the column name.
Returns a quoted form of the column name.
Parameters
Returns
string The quoted column name.
|
public
string
|
#
quoteTableName( string $name )
Returns a quoted form of the table name.
Returns a quoted form of the table name.
Defaults to column name quoting.
Parameters
Returns
string The quoted table name.
|
public
string
|
#
quoteTrue( )
Returns a quoted boolean true.
Returns a quoted boolean true.
Returns
string The quoted boolean true.
|
public
string
|
#
quoteFalse( )
Returns a quoted boolean false.
Returns a quoted boolean false.
Returns
string The quoted boolean false.
|
public
string
|
#
quoteDate( mixed $value )
Returns a quoted date value.
Returns a quoted date value.
Parameters
- $value
- date value that can be casted to string.
Returns
string The quoted date value.
|
public
string
|
#
quoteBinary( mixed $value )
Returns a quoted binary value.
Returns a quoted binary value.
Parameters
Returns
string The quoted binary value.
|
public
array
|
#
nativeDatabaseTypes( )
Returns a hash of mappings from the abstract data types to the native
database types.
Returns a hash of mappings from the abstract data types to the native
database types.
See TableDefinition::column() for details on the recognized abstract
data types.
Returns
array A database type map.
See
TableDefinition::column()
|
public
integer
|
#
tableAliasLength( )
Returns the maximum length a table alias can have.
Returns the maximum length a table alias can have.
Returns
integer The maximum table alias length.
|
public
string
|
#
tableAliasFor( string $tableName )
Converts a table name into a suitable table alias.
Converts a table name into a suitable table alias.
Parameters
Returns
string A possible alias name for the table.
|
abstract public
array
|
#
tables( )
Returns a list of all tables of the current database.
Returns a list of all tables of the current database.
Returns
array A table list.
|
public
Horde_Db_Adapter_Base_Table
|
#
table( string $tableName, string $name = null )
Returns a Horde_Db_Adapter_Base_Table object for a table.
Returns a Horde_Db_Adapter_Base_Table object for a table.
Parameters
- $tableName
- A table name.
- $name
- (can be removed?)
Returns
|
abstract public
Horde_Db_Adapter_Base_Index
|
#
primaryKey( string $tableName, string $name = null )
Returns a table's primary key.
Returns a table's primary key.
Parameters
- $tableName
- A table name.
- $name
- (can be removed?)
Returns
|
abstract public
array
|
#
indexes( string $tableName, string $name = null )
Returns a list of tables indexes.
Returns a list of tables indexes.
Parameters
- $tableName
- A table name.
- $name
- (can be removed?)
Returns
array A list of Horde_Db_Adapter_Base_Index objects.
|
abstract public
array
|
#
columns( string $tableName, string $name = null )
Returns a list of table columns.
Returns a list of table columns.
Parameters
- $tableName
- A table name.
- $name
- (can be removed?)
Returns
array A list of Horde_Db_Adapter_Base_Column objects.
|
public
Horde_Db_Adapter_Base_TableDefinition
|
#
createTable( string $name, array $options = array() )
Creates a new table.
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:
$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
$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)
)
$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.
Parameters
- $name
- A table name.
- $options
- <p>A list of table options, see the method
description.</p>
Returns
|
public
|
#
endTable( string|Horde_Db_Adapter_Base_TableDefinition $name, array $options = array() )
Finishes and executes table creation.
Finishes and executes table creation.
Parameters
- $name
- A table name or object.
- $options
- A list of options. See createTable().
|
abstract public
|
#
renameTable( string $name, string $newName )
Renames a table.
Parameters
- $name
- A table name.
- $newName
- The new table name.
|
public
|
#
dropTable( string $name )
Drops a table from the database.
Drops a table from the database.
Parameters
|
public
|
#
addColumn( string $tableName, string $columnName, string $type, array $options = array() )
Adds a new column to a table.
Adds a new column to a table.
Parameters
- $tableName
- A table name.
- $columnName
- A column name.
- $type
- A data type.
- $options
- <p>Column options. See
Horde_Db_Adapter_Base_TableDefinition#column()
for details.</p>
|
public
|
#
removeColumn( string $tableName, string $columnName )
Removes a column from a table.
Removes a column from a table.
Parameters
- $tableName
- A table name.
- $columnName
- A column name.
|
abstract public
|
#
changeColumn( string $tableName, string $columnName, string $type, array $options = array() )
Changes an existing column's definition.
Changes an existing column's definition.
Parameters
- $tableName
- A table name.
- $columnName
- A column name.
- $type
- A data type.
- $options
- <p>Column options. See
Horde_Db_Adapter_Base_TableDefinition#column()
for details.</p>
|
abstract public
|
#
changeColumnDefault( string $tableName, string $columnName, mixed $default )
Sets a new default value for a column.
Sets a new default value for a column.
If you want to set the default value to NULL, you are out of luck. You
need to execute the apppropriate SQL statement yourself.
Parameters
- $tableName
- A table name.
- $columnName
- A column name.
- $default
- The new default value.
|
abstract public
|
#
renameColumn( string $tableName, string $columnName, string $newColumnName )
Renames a column.
Parameters
- $tableName
- A table name.
- $columnName
- A column name.
- $newColumnName
- The new column name.
|
public
|
#
addPrimaryKey( string $tableName, string|array $columns )
Adds a primary key to a table.
Adds a primary key to a table.
Parameters
- $tableName
- A table name.
- $columns
- $columnName One or more column names.
Throws
Since
Horde_Db 1.1.0
|
abstract public
|
#
removePrimaryKey( string $tableName )
Removes a primary key from a table.
Removes a primary key from a table.
Parameters
Throws
Since
Horde_Db 1.1.0
|
public
|
#
addIndex( string $tableName, string|array $columnName, array $options = array() )
Adds a new index to a table.
Adds a new index to a table.
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)
Parameters
- $tableName
- A table name.
- $columnName
- One or more column names.
- $options
- <p>Index options:
- name: (string) the index name.
- unique: (boolean) create a unique
index?</p>
|
public
|
#
removeIndex( string $tableName, string|array $options = array() )
Removes an index from a table.
Removes an index from a table.
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');
Parameters
- $tableName
- A table name.
- $options
- <p>Either a column name or index options:
- name: (string) the index name.
- column: (string|array) column name(s).</p>
|
public
|
#
indexName( string $tableName, string|array $options = array() )
Builds the name for an index.
Builds the name for an index.
Parameters
- $tableName
- A table name.
- $options
- <p>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.</p>
|
public
|
#
recreateDatabase( string $name )
Recreates, i.e. drops then creates a database.
Recreates, i.e. drops then creates a database.
Parameters
|
abstract public
|
#
createDatabase( string $name, array $options = array() )
Creates a database.
Parameters
- $name
- A database name.
- $options
- Database options.
|
abstract public
|
|
abstract public
string
|
#
currentDatabase( )
Returns the name of the currently selected database.
Returns the name of the currently selected database.
Returns
string The database name.
|
public
string
|
#
typeToSql( string $type, integer $limit = null, integer $precision = null, integer $scale = null, boolean $unsigned = null )
Generates the SQL definition for a column type.
Generates the SQL definition for a column type.
Parameters
- $type
- A column type.
- $limit
- Maximum column length (non decimal type only)
- $precision
- The number precision (decimal type only).
- $scale
- The number scaling (decimal columns only).
- $unsigned
- <p>Whether the column is an unsigned number
(non decimal columns only).</p>
Returns
string The SQL definition. If $type is not one of the
internally supported types, $type is returned unchanged.
|
public
string
|
#
addColumnOptions( string $sql, array $options )
Adds default/null options to column SQL definitions.
Adds default/null options to column SQL definitions.
Parameters
- $sql
- Existing SQL definition for a column.
- $options
- <p>Column options:
- null: (boolean) Whether to allow NULL values.
- default: (mixed) Default column value.
- autoincrement: (boolean) Whether the column is
an autoincrement column. Driver depedendent.</p>
Returns
string The manipulated SQL definition.
|
public
string
|
#
distinct( string $columns, string $orderBy = null )
Generates a DISTINCT clause for SELECT queries.
Generates a DISTINCT clause for SELECT queries.
$connection->distinct('posts.id', 'posts.created_at DESC')
Parameters
- $columns
- A column list.
- $orderBy
- An ORDER clause.
Returns
string The generated DISTINCT clause.
|
public
string
|
#
addOrderByForAssocLimiting( string $sql, array $options )
Adds an ORDER BY clause to an existing query.
Adds an ORDER BY clause to an existing query.
Parameters
- $sql
- An SQL query to manipulate.
- $options
- <p>Options:
- order: Order column an direction.</p>
Returns
string The manipulated SQL query.
|
public
string
|
#
modifyDate( string $reference, string $operator, integer $amount, string $interval )
Generates a modified date for SELECT queries.
Generates a modified date for SELECT queries.
Parameters
- $reference
- <p>The reference date - this is a column
referenced in the SELECT.</p>
- $operator
- Add or subtract time? (+/-)
- $amount
- <p>The shift amount (number of days if $interval
is DAY, etc).</p>
- $interval
- <p>The interval (SECOND, MINUTE, HOUR, DAY,
MONTH, YEAR).</p>
Returns
string The generated INTERVAL clause.
Since
Horde_Db 1.2.0
|
public
string|array
|
#
buildClause( string $lhs, string $op, string $rhs, boolean $bind = false, array $params = array() )
Returns an expression using the specified operator.
Returns an expression using the specified operator.
Parameters
- $lhs
- The column or expression to test.
- $op
- The operator.
- $rhs
- The comparison value.
- $bind
- <p>If true, the method returns the query and a list
of values suitable for binding as an array.</p>
- $params
- Any additional parameters for the operator.
Returns
string|array The SQL test fragment, or an array containing the
query and a list of values if $bind is true.
|