PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TDbCommandBuilder

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

TComponent
Extended by TDbCommandBuilder

Direct known subclasses

TMssqlCommandBuilder, TMysqlCommandBuilder, TOracleCommandBuilder, TPgsqlCommandBuilder, TSqliteCommandBuilder
Package: System\Data\Common
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Wei Zhuo <weizho[at]gmail[dot]com>
Since: 3.1
Located at Data/Common/TDbCommandBuilder.php
Methods summary
public
# __construct( TDbConnection $connection = null, TDbTableInfo $tableInfo = null )

Parameters

$connection
TDbConnection
database connection.
$tableInfo
TDbTableInfo
table information.

Overrides

TComponent::__construct()
public TDbConnection
# getDbConnection( )

Returns

TDbConnection
database connection.
public
# setDbConnection( TDbConnection $value )

Parameters

$value
TDbConnection
database connection.
public
# setTableInfo( TDbTableInfo $value )

Parameters

$value
TDbTableInfo
table information.
public
# getTableInfo( )
public mixed
# getLastInsertID( )

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

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

Returns

mixed
last insert id, null if none is found.
public string
# applyLimitOffset( string $sql, integer $limit = -1, integer $offset = -1 )

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

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

Parameters

$sql
string
SQL query string.
$limit
integer
maximum number of rows, -1 to ignore limit.
$offset
integer
row offset, -1 to ignore offset.

Returns

string
SQL with limit and offset.
public string
# applyOrdering( string $sql, array $ordering )

Parameters

$sql
string
SQL string without existing ordering.
$ordering
array
pairs of column names as key and direction as value.

Returns

string
modified SQL applied with ORDER BY.
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).

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).

Parameters

$fields
array
list of column id for potential search condition.
$keywords
string
string of keywords

Returns

string
SQL search condition matching on a set of columns.
protected string
# getSearchCondition( string $column, array $words )

Parameters

$column
string
column name.
$words
array
keywords

Returns

string
search condition for all words in one column.
public array
# getSelectFieldList( mixed $data = '*' )

Different behavior depends on type of passed data string usage without modification

null will be expanded to full list of quoted table column names (quoting depends on database)

array

  • Column names will be quoted if used as key or value of array
    array('col1', 'col2', 'col2')
    // SELECT `col1`, `col2`, `col3` FROM...
    
  • Column aliasing
array('mycol1' => 'col1', 'mycol2' => 'COUNT(*)')
// SELECT `col1` AS mycol1, COUNT(*) AS mycol2 FROM...
  • NULL and scalar values (strings will be quoted depending on database)
array('col1' => 'my custom string', 'col2' => 1.0, 'col3' => 'NULL')
// SELECT "my custom string" AS `col1`, 1.0 AS `col2`, NULL AS `col3` FROM...
  • If the *-wildcard char is used as key or value, add the full list of quoted table column names
array('col1' => 'NULL', '*')
// SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM...

Parameters

$data
mixed
$value

Returns

array
of generated fields - use implode(', ', $selectfieldlist) to collapse field list for usage

Since

3.1.7

Todo

add support for table aliasing
add support for quoting of column aliasing
public TDbCommand
# createFindCommand( string $where = '1=1', array $parameters = array(), mixed $ordering = array(), mixed $limit = -1, mixed $offset = -1, mixed $select = '*' )

Appends the $where condition to the string "SELECT * FROM tableName WHERE ". The tableName is obtained from the setTableInfo TableInfo property.

Appends the $where condition to the string "SELECT * FROM tableName WHERE ". The tableName is obtained from the setTableInfo TableInfo property.

Parameters

$where
string
query condition
$parameters
array
condition parameters.
$ordering
$limit
$offset
$select

Returns

TDbCommand
query command.
public
# applyCriterias( mixed $sql, mixed $parameters = array(), mixed $ordering = array(), mixed $limit = -1, mixed $offset = -1 )
public TDbCommand
# createCountCommand( string $where = '1=1', array $parameters = array(), mixed $ordering = array(), mixed $limit = -1, mixed $offset = -1 )

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

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

Parameters

$where
string
count condition.
$parameters
array
binding parameters.
$ordering
$limit
$offset

Returns

TDbCommand
count command.
public TDbCommand
# createDeleteCommand( string $where, array $parameters = array() )

Creates a delete command for the table described in setTableInfo TableInfo. The conditions for delete is given by the $where argument and the parameters for the condition is given by $parameters.

Creates a delete command for the table described in setTableInfo TableInfo. The conditions for delete is given by the $where argument and the parameters for the condition is given by $parameters.

Parameters

$where
string
delete condition.
$parameters
array
delete parameters.

Returns

TDbCommand
delete command.
public TDbCommand
# createInsertCommand( array $data )

Creates an insert command for the table described in setTableInfo TableInfo 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.

Creates an insert command for the table described in setTableInfo TableInfo 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.

Parameters

$data
array
name-value pairs of new data to be inserted.

Returns

TDbCommand
insert command
public TDbCommand
# createUpdateCommand( array $data, string $where, array $parameters = array() )

Creates an update command for the table described in setTableInfo TableInfo 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.

Creates an update command for the table described in setTableInfo TableInfo 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.

Parameters

$data
array
name-value pairs of data to be updated.
$where
string
update condition.
$parameters
array
update parameters.

Returns

TDbCommand
update command.
protected array
# getInsertFieldBindings( object $values )

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

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

Parameters

$values
object
array or object to be inserted.

Returns

array
tuple ($fields, $bindings)
protected string
# getColumnBindings( array $values, boolean $position = false )

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

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

Parameters

$values
array
data for binding.
$position
boolean
true to bind as position values.

Returns

string
update column names with corresponding binding substrings.
public TDbCommand
# createCommand( string $sql )

Parameters

$sql
string
SQL query string.

Returns

TDbCommand
corresponding database command.
public
# bindColumnValues( TDbCommand $command, array $values )

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

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

Parameters

$command
TDbCommand
database command.
$values
array
name-value pairs.
public
# bindArrayValues( TDbCommand $command, array $values )

Parameters

$command
TDbCommand
database command
$values
array
values for binding.
public static integer
# getPdoType( mixed $value )

Parameters

$value
mixed
PHP value

Returns

integer
PDO parameter types.
protected boolean
# hasIntegerKey( array $array )

Parameters

$array
array

Returns

boolean
true if any array key is an integer.
Methods inherited from TComponent
__call(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO