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 TMappedStatement

TComponent
   |
   --TMappedStatement

TMappedStatement class executes SQL mapped statements. Mapped Statements can hold any SQL statement and use Parameter Maps and Result Maps for input and output.

This class is usualy instantiated during SQLMap configuration by TSqlDomBuilder.

Since: 3.0
Author: Wei Zhuo <weizhuo[at]gmail[dot]com>

Constructor Summary
public
__construct Array
Creates a new mapped statement.

Method Summary
protected  object result
addResultMapGroupBy ( TResultMap $resultMap, array $row, object the $parent, mixed &$resultObject)
ResultMap with GroupBy property. Save object collection graph in a tree and collect the result later.
protected  object the
applyResultMap ( array $row, object the &$resultObject)
Apply result mapping.
protected  void
enquequePostSelect ( string $select, TResultMap $resultMap, TResultProperty $property, array $row, object the $resultObject)
Add nested result property to post select queue.
string
executeInsert ( IDbConnection $connection, mixed $parameter)
Execute an insert statement. Fill the parameter object with the ouput parameters if any, also could return the insert generated key.
protected  void
executePostSelect ( IDbConnection $connection)
Process 'select' result properties
array
executeQueryForList ( IDbConnection $connection, mixed $parameter, object result $result, integer $skip, integer $max, callback $delegate)
Executes the SQL and retuns a List of result objects.
array
executeQueryForMap ( IDbConnection $connection, mixed $parameter, string $keyProperty, string $valueProperty, callback $skip, mixed $max, mixed $delegate)
Executes the SQL and retuns all rows selected in a map that is keyed on the property named in the keyProperty parameter. The value at each key will be the value of the property specified in the valueProperty parameter.
${return}
executeQueryForObject ( IDbConnection $connection, mixed $parameter, mixed $result)
Executes an SQL statement that returns a single row as an object of the type of the <tt>$result</tt> passed in as a parameter.
protected  string
executeSelectKey ( IDbConnection $connection, mixed $parameter, TSqlMapSelectKey $selectKey)
Execute the select key statement, used to obtain last insert ID.
protected  mixed
executeSQLQueryLimit ( IDbConnection $connection, array $command, mixed $max, mixed $skip)
Execute SQL Query with limits.
integer
executeUpdate ( IDbConnection $connection, mixed $parameter)
Execute an update statement. Also used for delete statement.
protected  array
fillArrayResultMap ( TResultMap $resultMap, array $row, object the $resultObject)
Retrieve the result map as an array.
protected  mixed
fillDefaultResultMap ( TResultMap $resultMap, array $row, object the $resultObject)
Fill the result map using default settings. If <tt>$resultMap</tt> is null the result object returned will be guessed from <tt>$resultObject</tt>.
protected  boolean
fillPropertyWithResultMap ( TResultMap $resultMap, array $row, object the &$resultObject)
Fills the property with result mapping results.
protected  object result
fillResultArrayList ( array $row, object result $resultObject)
Apply the result to a TList or an array.
protected  object result
fillResultClass ( string $resultClass, array $row, object the $resultObject)
Fill the result using ResultClass, will creates new result object if required.
protected  object result
fillResultMap ( string $resultMapName, array $row, object result $parentGroup, mixed &$resultObject)
Fills the result object according to result mappings.
protected  object result
fillResultObjectProperty ( array $row, object result $resultObject)
Apply the result to an object.
TPreparedCommand
string
getID ()
TSqlMapper
protected  string
getPostGeneratedSelectKey ( IDbConnection $connection, mixed $parameter)
Gets the inserted row ID after executing an insert statement.
protected  array
getPostSelectKeys ( TResultMap $resultMap, TResultProperty $property, array $row)
Finds in the post select property the SQL statement primary selection keys.
protected  string
getPreGeneratedSelectKey ( IDbConnection $connection, mixed $parameter)
Gets the insert generated ID before executing an insert statement.
protected  string
getResultMapGroupKey ( TResultMap $resultMap, array $row)
Gets the result 'group by' groupping key for each row.
protected  mixed
getScalarResult ( array $result, string $type)
Converts the first array value to scalar value of given type.
void
TSqlMapStatement
protected  void
Empty the group by results cache.
void
onExecuteQuery ( array $sql)
Raise the execute query event.
protected  void
raiseRowDelegate ( object event $handler, mixed $param)
Raises delegate handler.
array
runQueryForList ( IDbConnection $connection, mixed $parameter, array $sql, object result $result, integer $delegate, integer 5, callback 6)
Executes the SQL and retuns a List of result objects.
array
runQueryForMap ( IDbConnection $connection, mixed $parameter, array $command, string $keyProperty, string $valueProperty, callback $delegate)
Executes the SQL and retuns all rows selected in a map that is keyed on the property named in the keyProperty parameter. The value at each key will be the value of the property specified in the valueProperty parameter.
object the
runQueryForObject ( IDbConnection $connection, array $command, object The &$result)
Executes an SQL statement that returns a single row as an object of the type of the <tt>$result</tt> passed in as a parameter.
protected  void
setObjectProperty ( TResultMap $resultMap, TResultProperty $property, array $row, object the &$resultObject)
Set a property of the result object with appropriate 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()

Constant Summary
int QUERY_FOR_ARRAY
int QUERY_FOR_LIST
int QUERY_FOR_OBJECT

Constructor Details

__construct

public __construct Array

Creates a new mapped statement.


Method Details

addResultMapGroupBy

protected object result addResultMapGroupBy (TResultMap $resultMap , array $row , object the $parent , mixed &$resultObject )

ResultMap with GroupBy property. Save object collection graph in a tree and collect the result later.

Input
TResultMap$resultMapresult mapping details.
array$rowa result set row retrieved from the database
object the$parentresult object
mixed&$resultObject
Output
object result object.
Exception

applyResultMap

protected object the applyResultMap (array $row , object the &$resultObject )

Apply result mapping.

Input
array$rowa result set row retrieved from the database
object the&$resultObjectresult object, will create if necessary.
Output
object the result filled with data, null if not filled.
Exception

enquequePostSelect

protected void enquequePostSelect (string $select , TResultMap $resultMap , TResultProperty $property , array $row , object the $resultObject )

Add nested result property to post select queue.

Input
string$selectpost select statement ID
TResultMap$resultMapcurrent result mapping details.
TResultProperty$propertycurrent result property.
array$rowa result set row retrieved from the database
object the$resultObjectresult object
Output
Exception

executeInsert

public string executeInsert (IDbConnection $connection , mixed $parameter )

Execute an insert statement. Fill the parameter object with the ouput parameters if any, also could return the insert generated key.

Input
IDbConnection$connectiondatabase connection
mixed$parameterThe parameter object used to fill the statement.
Output
string the insert generated key.
Exception

executePostSelect

protected void executePostSelect (IDbConnection $connection )

Process 'select' result properties

Input
IDbConnection$connectiondatabase connection
Output
Exception

executeQueryForList

public array executeQueryForList (IDbConnection $connection , mixed $parameter , object result $result , integer $skip , integer $max , callback $delegate )

Executes the SQL and retuns a List of result objects.

Input
IDbConnection$connectiondatabase connection
mixed$parameterThe object used to set the parameters in the SQL.
object result$resultcollection object.
integer$skipThe number of rows to skip over.
integer$maxThe maximum number of rows to return.
callback$delegaterow delegate handler
Output
array a list of result objects
Exception

executeQueryForMap

public array executeQueryForMap (IDbConnection $connection , mixed $parameter , string $keyProperty , string $valueProperty , callback $skip , mixed $max , mixed $delegate )

Executes the SQL and retuns all rows selected in a map that is keyed on the property named in the keyProperty parameter. The value at each key will be the value of the property specified in the valueProperty parameter.

If valueProperty is null, the entire result object will be entered.

Input
IDbConnection$connectiondatabase connection
mixed$parameterThe object used to set the parameters in the SQL.
string$keyPropertyThe property of the result object to be used as the key.
string$valuePropertyThe property of the result object to be used as the value (or null).
callback$skiprow delegate handler
mixed$max
mixed$delegate
Output
array An array of object containing the rows keyed by keyProperty.
Exception

executeQueryForObject

public ${return} executeQueryForObject (IDbConnection $connection , mixed $parameter , mixed $result )

Executes an SQL statement that returns a single row as an object of the type of the <tt>$result</tt> passed in as a parameter.

Input
IDbConnection$connectiondatabase connection
mixed$parameterThe parameter data (object, arrary, primitive) used to set the parameters in the SQL
mixed$resultThe result object.
Output
Exception

executeSelectKey

protected string executeSelectKey (IDbConnection $connection , mixed $parameter , TSqlMapSelectKey $selectKey )

Execute the select key statement, used to obtain last insert ID.

Input
IDbConnection$connectiondatabase connection
mixed$parameterinsert statement parameter
TSqlMapSelectKey$selectKeyselect key statement
Output
string last insert ID.
Exception

executeSQLQueryLimit

protected mixed executeSQLQueryLimit (IDbConnection $connection , array $command , mixed $max , mixed $skip )

Execute SQL Query with limits.

Input
IDbConnection$connectiondatabase connection
array$commandSQL statement and parameters.
mixed$max
mixed$skip
Output
mixed record set if applicable.
Exception
throwsTSqlMapExecutionException if execution error or false record set.
throwsTSqlMapQueryExecutionException if any execution error

executeUpdate

public integer executeUpdate (IDbConnection $connection , mixed $parameter )

Execute an update statement. Also used for delete statement.

Return the number of rows effected.

Input
IDbConnection$connectiondatabase connection
mixed$parameterThe object used to set the parameters in the SQL.
Output
integer The number of rows effected.
Exception

fillArrayResultMap

protected array fillArrayResultMap (TResultMap $resultMap , array $row , object the $resultObject )

Retrieve the result map as an array.

Input
TResultMap$resultMapresult mapping details.
array$rowa result set row retrieved from the database
object the$resultObjectresult object
Output
array array list of result objects.
Exception

fillDefaultResultMap

protected mixed fillDefaultResultMap (TResultMap $resultMap , array $row , object the $resultObject )

Fill the result map using default settings. If <tt>$resultMap</tt> is null the result object returned will be guessed from <tt>$resultObject</tt>.

Input
TResultMap$resultMapresult mapping details.
array$rowa result set row retrieved from the database
object the$resultObjectresult object
Output
mixed the result object filled with data.
Exception

fillPropertyWithResultMap

protected boolean fillPropertyWithResultMap (TResultMap $resultMap , array $row , object the &$resultObject )

Fills the property with result mapping results.

Input
TResultMap$resultMapnested result mapping details.
array$rowa result set row retrieved from the database
object the&$resultObjectresult object
Output
boolean true if the data was found, false otherwise.
Exception

fillResultArrayList

protected object result fillResultArrayList (array $row , object result $resultObject )

Apply the result to a TList or an array.

Input
array$rowa result set row retrieved from the database
object result$resultObjectobject, array or list
Output
object result filled with data.
Exception

fillResultClass

protected object result fillResultClass (string $resultClass , array $row , object the $resultObject )

Fill the result using ResultClass, will creates new result object if required.

Input
string$resultClassresult object class name
array$rowa result set row retrieved from the database
object the$resultObjectresult object, will create if necessary.
Output
object result object filled with data
Exception

fillResultMap

protected object result fillResultMap (string $resultMapName , array $row , object result $parentGroup , mixed &$resultObject )

Fills the result object according to result mappings.

Input
string$resultMapNameresult map name.
array$rowa result set row retrieved from the database
object result$parentGroupobject to fill, will create new instances if required.
mixed&$resultObject
Output
object result object filled with data.
Exception

fillResultObjectProperty

protected object result fillResultObjectProperty (array $row , object result $resultObject )

Apply the result to an object.

Input
array$rowa result set row retrieved from the database
object result$resultObjectobject, array or list
Output
object result filled with data.
Exception

getCommand

public TPreparedCommand getCommand ()

Output
TPreparedCommand command to prepare SQL statements.
Exception

getID

public string getID ()

Output
string Name used to identify the TMappedStatement amongst the others. This the name of the SQL statement by default.
Exception

getManager

public TSqlMapper getManager ()

Output
TSqlMapper The SqlMap used by this MappedStatement
Exception

getPostGeneratedSelectKey

protected string getPostGeneratedSelectKey (IDbConnection $connection , mixed $parameter )

Gets the inserted row ID after executing an insert statement.

Input
IDbConnection$connectiondatabase connection
mixed$parameterinsert statement parameter.
Output
string last insert ID, null otherwise.
Exception

getPostSelectKeys

protected array getPostSelectKeys (TResultMap $resultMap , TResultProperty $property , array $row )

Finds in the post select property the SQL statement primary selection keys.

Input
TResultMap$resultMapresult mapping details
TResultProperty$propertyresult property
array$rowcurrent row data.
Output
array list of primary key values.
Exception

getPreGeneratedSelectKey

protected string getPreGeneratedSelectKey (IDbConnection $connection , mixed $parameter )

Gets the insert generated ID before executing an insert statement.

Input
IDbConnection$connectiondatabase connection
mixed$parameterinsert statement parameter.
Output
string new insert ID if pre-select key statement was executed, null otherwise.
Exception

getResultMapGroupKey

protected string getResultMapGroupKey (TResultMap $resultMap , array $row )

Gets the result 'group by' groupping key for each row.

Input
TResultMap$resultMapresult mapping details.
array$rowa result set row retrieved from the database
Output
string groupping key.
Exception

getScalarResult

protected mixed getScalarResult (array $result , string $type )

Converts the first array value to scalar value of given type.

Input
array$resultlist of results
string$typescalar type.
Output
mixed scalar value.
Exception

getSqlString

public void getSqlString ()

Output
Exception

getStatement

public TSqlMapStatement getStatement ()

Output
TSqlMapStatement The SQL statment used by this MappedStatement
Exception

initialGroupByResults

protected void initialGroupByResults ()

Empty the group by results cache.

Output
Exception

onExecuteQuery

public void onExecuteQuery (array $sql )

Raise the execute query event.

Input
array$sqlprepared SQL statement and subsititution parameters
Output
Exception

raiseRowDelegate

protected void raiseRowDelegate (object event $handler , mixed $param )

Raises delegate handler.

This method is invoked for each new list item. It is the responsibility of the handler to add the item to the list.

Input
object event$handlerparameter
mixed$param
Output
Exception

runQueryForList

public array runQueryForList (IDbConnection $connection , mixed $parameter , array $sql , object result $result , integer $delegate , integer 5 , callback 6 )

Executes the SQL and retuns a List of result objects.

This method should only be called by internal developers, consider using <tt>executeQueryForList()</tt> first.

Input
IDbConnection$connectiondatabase connection
mixed$parameterThe object used to set the parameters in the SQL.
array$sqlSQL string and subsititution parameters.
object result$resultcollection object.
integer$delegateThe number of rows to skip over.
integer5The maximum number of rows to return.
callback6row delegate handler
Output
array a list of result objects
Exception

runQueryForMap

public array runQueryForMap (IDbConnection $connection , mixed $parameter , array $command , string $keyProperty , string $valueProperty , callback $delegate )

Executes the SQL and retuns all rows selected in a map that is keyed on the property named in the keyProperty parameter. The value at each key will be the value of the property specified in the valueProperty parameter.

If valueProperty is null, the entire result object will be entered.

This method should only be called by internal developers, consider using <tt>executeQueryForMap()</tt> first.

Input
IDbConnection$connectiondatabase connection
mixed$parameterThe object used to set the parameters in the SQL.
array$commandSQL string and subsititution parameters.
string$keyPropertyThe property of the result object to be used as the key.
string$valuePropertyThe property of the result object to be used as the value (or null).
callback$delegaterow delegate, a callback function
Output
array An array of object containing the rows keyed by keyProperty.
Exception

runQueryForObject

public object the runQueryForObject (IDbConnection $connection , array $command , object The &$result )

Executes an SQL statement that returns a single row as an object of the type of the <tt>$result</tt> passed in as a parameter.

This method should only be called by internal developers, consider using <tt>executeQueryForObject()</tt> first.

Input
IDbConnection$connectiondatabase connection
array$commandSQL string and subsititution parameters.
object The&$resultresult object.
Output
object the object.
Exception

setObjectProperty

protected void setObjectProperty (TResultMap $resultMap , TResultProperty $property , array $row , object the &$resultObject )

Set a property of the result object with appropriate value.

Input
TResultMap$resultMapresult mapping details.
TResultProperty$propertythe result property to fill.
array$rowa result set row retrieved from the database
object the&$resultObjectresult object
Output
Exception


Constant Details

QUERY_FOR_ARRAY

Type:

int

Value:

1
Var: select is to query for list.

QUERY_FOR_LIST

Type:

int

Value:

0
Var: select is to query for list.

QUERY_FOR_OBJECT

Type:

int

Value:

2
Var: select is to query for object.