Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml


Classes:
Keyword

Class TDbCommandBuilder

TComponent
   |
   --TDbCommandBuilder

TDbCommandBuilder provides basic methods to create query commands for tables giving by setTableInfo the property.

Since: 3.1
Author: Wei Zhuo <weizho[at]gmail[dot]com>

Constructor Summary
public
__construct Array

Method Summary
void
applyCriterias ( mixed $sql, mixed $parameters, mixed $ordering, mixed $limit, mixed $offset)
string
applyLimitOffset ( string $sql, integer $limit, integer $offset)
Alters the sql to apply $limit and $offset. Default implementation is applicable for PostgreSQL, MySQL and SQLite.
string
applyOrdering ( string $sql, array $ordering)
void
bindArrayValues ( TDbCommand $command, array $values)
void
bindColumnValues ( TDbCommand $command, array $values)
Bind the name-value pairs of $values where the array keys correspond to column names.
TDbCommand
createCommand ( string $sql)
TDbCommand
createCountCommand ( string $where, array $parameters, mixed $ordering, mixed $limit, mixed $offset)
Creates a count(*) command for the table described in setTableInfo.
TDbCommand
createDeleteCommand ( string $where, array $parameters)
Creates a delete command for the table described in setTableInfo.
TDbCommand
createFindCommand ( string $where, array $parameters, mixed $ordering, mixed $limit, mixed $offset)
Appends the $where condition to the string "SELECT * FROM tableName WHERE ".
TDbCommand
createInsertCommand ( array $data)
Creates an insert command for the table described in setTableInfo for the given data.
TDbCommand
createUpdateCommand ( array $data, string $where, array $parameters)
Creates an update command for the table described in setTableInfo for the given data.
protected  string
getColumnBindings ( array $values, boolean $position)
Create a name-value or position-value if $position=true binding strings.
TDbConnection
protected  array
getInsertFieldBindings ( object array $values)
Returns a list of insert field name and a list of binding names.
mixed
Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
integer
getPdoType ( mixed $value)
protected  string
getSearchCondition ( string $column, array $words)
string
getSearchExpression ( array $fields, string $keywords)
Computes the SQL condition for search a set of column using regular expression (or LIKE, depending on database implementation) to match a string of keywords (default matches all keywords).
void
protected  boolean
hasIntegerKey ( array $array)
void
void
Methods Inherited From TComponent
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()

Constructor Details

__construct

public __construct Array


Method Details

applyCriterias

public void applyCriterias (mixed $sql , mixed $parameters , mixed $ordering , mixed $limit , mixed $offset )

Input
mixed$sql
mixed$parameters
mixed$ordering
mixed$limit
mixed$offset
Output
Exception

applyLimitOffset

public string applyLimitOffset (string $sql , integer $limit , integer $offset )

Alters the sql to apply $limit and $offset. Default implementation is applicable for PostgreSQL, MySQL and SQLite.

Input
string$sqlSQL query string.
integer$limitmaximum number of rows, -1 to ignore limit.
integer$offsetrow offset, -1 to ignore offset.
Output
string SQL with limit and offset.
Exception

applyOrdering

public string applyOrdering (string $sql , array $ordering )

Input
string$sqlSQL string without existing ordering.
array$orderingpairs of column names as key and direction as value.
Output
string modified SQL applied with ORDER BY.
Exception

bindArrayValues

public void bindArrayValues (TDbCommand $command , array $values )

Input
TDbCommand$commanddatabase command
array$valuesvalues for binding.
Output
Exception

bindColumnValues

public void bindColumnValues (TDbCommand $command , array $values )

Bind the name-value pairs of $values where the array keys correspond to column names.

Input
TDbCommand$commanddatabase command.
array$valuesname-value pairs.
Output
Exception

createCommand

public TDbCommand createCommand (string $sql )

Input
string$sqlSQL query string.
Output
TDbCommand corresponding database command.
Exception

createCountCommand

public TDbCommand createCountCommand (string $where , array $parameters , mixed $ordering , mixed $limit , mixed $offset )

Creates a count(*) command for the table described in setTableInfo.

Input
string$wherecount condition.
array$parametersbinding parameters.
mixed$ordering
mixed$limit
mixed$offset
Output
TDbCommand count command.
Exception

createDeleteCommand

public TDbCommand createDeleteCommand (string $where , array $parameters )

Creates a delete command for the table described in setTableInfo.

The conditions for delete is given by the $where argument and the parameters for the condition is given by $parameters.

Input
string$wheredelete condition.
array$parametersdelete parameters.
Output
TDbCommand delete command.
Exception

createFindCommand

public TDbCommand createFindCommand (string $where , array $parameters , mixed $ordering , mixed $limit , mixed $offset )

Appends the $where condition to the string "SELECT * FROM tableName WHERE ".

The tableName is obtained from the TableInfo property.

Input
string$wherequery condition
array$parameterscondition parameters.
mixed$ordering
mixed$limit
mixed$offset
Output
TDbCommand query command.
Exception

createInsertCommand

public TDbCommand createInsertCommand (array $data )

Creates an insert command for the table described in setTableInfo for the given data.

Each array key in the $data array must correspond to the column name of the table (if a column allows to be null, it may be omitted) to be inserted with the corresponding array value.

Input
array$dataname-value pairs of new data to be inserted.
Output
TDbCommand insert command
Exception

createUpdateCommand

public TDbCommand createUpdateCommand (array $data , string $where , array $parameters )

Creates an update command for the table described in setTableInfo for the given data.

Each array key in the $data array must correspond to the column name to be updated with the corresponding array value.

Input
array$dataname-value pairs of data to be updated.
string$whereupdate condition.
array$parametersupdate parameters.
Output
TDbCommand update command.
Exception

getColumnBindings

protected string getColumnBindings (array $values , boolean $position )

Create a name-value or position-value if $position=true binding strings.

Input
array$valuesdata for binding.
boolean$positiontrue to bind as position values.
Output
string update column names with corresponding binding substrings.
Exception

getDbConnection

public TDbConnection getDbConnection ()

Output
TDbConnection database connection.
Exception

getInsertFieldBindings

protected array getInsertFieldBindings (object array $values )

Returns a list of insert field name and a list of binding names.

Input
object array$valuesor object to be inserted.
Output
array tuple ($fields, $bindings)
Exception

getLastInsertID

public mixed getLastInsertID ()

Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.

Output
mixed last insert id, null if none is found.
Exception

getPdoType

public integer getPdoType (mixed $value )

Input
mixed$valuePHP value
Output
integer PDO parameter types.
Exception

getSearchCondition

protected string getSearchCondition (string $column , array $words )

Input
string$columncolumn name.
array$wordskeywords
Output
string search condition for all words in one column.
Exception

getSearchExpression

public string getSearchExpression (array $fields , string $keywords )

Computes the SQL condition for search a set of column using regular expression (or LIKE, depending on database implementation) to match a string of keywords (default matches all keywords).

Input
array$fieldslist of column id for potential search condition.
string$keywordsstring of keywords
Output
string SQL search condition matching on a set of columns.
Exception

getTableInfo

public void getTableInfo (TDbTableInfo 0 )

Input
TDbTableInfo0table information.
Output
Exception

hasIntegerKey

protected boolean hasIntegerKey (array $array )

Input
array$array
Output
boolean true if any array key is an integer.
Exception

setDbConnection

public void setDbConnection (TDbConnection $value )

Input
TDbConnection$valuedatabase connection.
Output
Exception

setTableInfo

public void setTableInfo (TDbTableInfo $value )

Input
TDbTableInfo$valuetable information.
Output
Exception