0 follower

CMysqlCommandBuilder

Package system.db.schema.mysql
Inheritance class CMysqlCommandBuilder » CDbCommandBuilder » CComponent
Since 1.1.13
Source Code framework/db/schema/mysql/CMysqlCommandBuilder.php
CMysqlCommandBuilder provides basic methods to create query commands for tables.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
dbConnection CDbConnection database connection. CDbCommandBuilder
schema CDbSchema the schema for this command builder. CDbCommandBuilder

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
integerPrimaryKeyDefaultValue string Returns default value of the integer/serial primary key. Default value means that the next CDbCommandBuilder

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__construct() CDbCommandBuilder
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
applyCondition() Alters the SQL to apply WHERE clause. CDbCommandBuilder
applyGroup() Alters the SQL to apply GROUP BY. CDbCommandBuilder
applyHaving() Alters the SQL to apply HAVING. CDbCommandBuilder
applyJoin() Alters the SQL to apply JOIN clause. CMysqlCommandBuilder
applyLimit() Alters the SQL to apply LIMIT and OFFSET. CMysqlCommandBuilder
applyOrder() Alters the SQL to apply ORDER BY. CDbCommandBuilder
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
bindValues() Binds parameter values for an SQL command. CDbCommandBuilder
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
createColumnCriteria() Creates a query criteria with the specified column values. CDbCommandBuilder
createCountCommand() Creates a COUNT(*) command for a single table. CDbCommandBuilder
createCriteria() Creates a query criteria. CDbCommandBuilder
createDeleteCommand() Creates a DELETE command. CDbCommandBuilder
createFindCommand() Creates a SELECT command for a single table. CDbCommandBuilder
createInCondition() Generates the expression for selecting rows of specified primary key values. CDbCommandBuilder
createInsertCommand() Creates an INSERT command. CDbCommandBuilder
createMultipleInsertCommand() Creates a multiple INSERT command. CDbCommandBuilder
createPkCondition() Generates the expression for selecting rows of specified primary key values. CDbCommandBuilder
createPkCriteria() Creates a query criteria with the specified primary key. CDbCommandBuilder
createSearchCondition() Generates the expression for searching the specified keywords within a list of columns. CDbCommandBuilder
createSqlCommand() Creates a command based on a given SQL statement. CDbCommandBuilder
createUpdateCommand() Creates an UPDATE command. CDbCommandBuilder
createUpdateCounterCommand() Creates an UPDATE command that increments/decrements certain columns. CDbCommandBuilder
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getDbConnection() Returns database connection. CDbCommandBuilder
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getLastInsertID() Returns the last insertion ID for the specified table. CDbCommandBuilder
getSchema() Returns the schema for this command builder. CDbCommandBuilder
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
composeMultipleInsertCommand() Creates a multiple INSERT command. CDbCommandBuilder
createCompositeInCondition() Generates the expression for selecting rows with specified composite key values. CDbCommandBuilder
ensureTable() Checks if the parameter is a valid table schema. CDbCommandBuilder
getIntegerPrimaryKeyDefaultValue() Returns default value of the integer/serial primary key. Default value means that the next CDbCommandBuilder

Method Details

applyJoin() method
public string applyJoin(string $sql, string $join)
$sql string the SQL statement to be altered
$join string the JOIN clause (starting with join type, such as INNER JOIN)
{return} string the altered SQL statement
Source Code: framework/db/schema/mysql/CMysqlCommandBuilder.php#28 (show)
public function applyJoin($sql,$join)
{
    if(
$join=='')
        return 
$sql;

    if(
strpos($sql,'UPDATE')===&& ($pos=strpos($sql,'SET'))!==false)
        return 
substr($sql,0,$pos).$join.' '.substr($sql,$pos);
    elseif(
strpos($sql,'DELETE FROM ')===0)
    {
        
$tableName=substr($sql,12);
        return 
"DELETE {$tableName} FROM {$tableName} ".$join;
    }
    else
        return 
$sql.' '.$join;
}

Alters the SQL to apply JOIN clause. This method handles the mysql specific syntax where JOIN has to come before SET in UPDATE statement and for DELETE where JOIN has to be after FROM part.

applyLimit() method
public string applyLimit(string $sql, integer $limit, integer $offset)
$sql string SQL query string without LIMIT and OFFSET.
$limit integer maximum number of rows, -1 to ignore limit.
$offset integer row offset, -1 to ignore offset.
{return} string SQL with LIMIT and OFFSET
Source Code: framework/db/schema/mysql/CMysqlCommandBuilder.php#51 (show)
public function applyLimit($sql,$limit,$offset)
{
    
// Ugly, but this is how MySQL recommends doing it: https://dev.mysql.com/doc/refman/5.0/en/select.html
    
if($limit<=&& $offset>0)
        
$limit=PHP_INT_MAX;
    return 
parent::applyLimit($sql,$limit,$offset);
}

Alters the SQL to apply LIMIT and OFFSET.