- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

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:
TDbCommandBuilder
TDbMetaData
TDbTableColumn
TDbTableInfo
TMssqlCommandBuilder
TMysqlCommandBuilder
TOracleCommandBuilder
TOracleTableInfo
TPgsqlCommandBuilder
TSqliteCommandBuilder

Keyword

# Class TDbCommandBuilder

    TComponent
       |
       --TDbCommandBuilder

#### Direct Known Sub-classes:

TMssqlCommandBuilder , TMysqlCommandBuilder , TPgsqlCommandBuilder , TOracleCommandBuilder , TSqliteCommandBuilder

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 | getDbConnection ()
protected array | getInsertFieldBindings ( object array $values) Returns a list of insert field name and a list of binding names.
mixed | getLastInsertID () 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 | getTableInfo ( TDbTableInfo 0)
protected boolean | hasIntegerKey ( array $array)
void | setDbConnection ( TDbConnection $value)
void | setTableInfo ( TDbTableInfo $value)

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 | $sql | SQL query string.
integer | $limit | maximum number of rows, -1 to ignore limit.
integer | $offset | row offset, -1 to ignore offset.
Output
string | SQL with limit and offset.
Exception

## applyOrdering

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

Input
string | $sql | SQL string without existing ordering.
array | $ordering | pairs 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 | $command | database command
array | $values | values 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 | $command | database command.
array | $values | name-value pairs.
Output
Exception

## createCommand

public TDbCommand createCommand | (string $sql )

Input
string | $sql | SQL 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 | $where | count condition.
array | $parameters | binding 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 | $where | delete condition.
array | $parameters | delete 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 | $where | query condition
array | $parameters | condition 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 | $data | name-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 | $data | name-value pairs of data to be updated.
string | $where | update condition.
array | $parameters | update 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 | $values | data for binding.
boolean | $position | true 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 | $values | or 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 | $value | PHP value
Output
integer | PDO parameter types.
Exception

## getSearchCondition

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

Input
string | $column | column name.
array | $words | keywords
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 | $fields | list of column id for potential search condition.
string | $keywords | string of keywords
Output
string | SQL search condition matching on a set of columns.
Exception

## getTableInfo

public void getTableInfo | (TDbTableInfo 0 )

Input
TDbTableInfo | 0 | table 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 | $value | database connection.
Output
Exception

## setTableInfo

public void setTableInfo | (TDbTableInfo $value )

Input
TDbTableInfo | $value | table information.
Output
Exception