system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

COciCommandBuilder

system.db.schema.oci
继承 class COciCommandBuilder » CDbCommandBuilder » CComponent
源码 framework/db/schema/oci/COciCommandBuilder.php
COciCommandBuilder provides basic methods to create query commands for tables.

公共属性

隐藏继承的属性

属性类型描述被定义在
dbConnection CDbConnection database connection. CDbCommandBuilder
returnID integer the last insertion ID COciCommandBuilder
schema CDbSchema the schema for this command builder. CDbCommandBuilder

受保护的属性

隐藏继承的属性

属性类型描述被定义在
integerPrimaryKeyDefaultValue string Returns default value of the integer/serial primary key. Default value means that the next CDbCommandBuilder

公共方法

隐藏继承的方法

方法描述被定义在
__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. CDbCommandBuilder
applyLimit() Alters the SQL to apply LIMIT and OFFSET. COciCommandBuilder
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. COciCommandBuilder
createMultipleInsertCommand() Creates a multiple INSERT command. COciCommandBuilder
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. COciCommandBuilder
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

受保护的方法

隐藏继承的方法

方法描述被定义在
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

属性详情

returnID 属性
public integer $returnID;

the last insertion ID

方法详情

applyLimit() 方法
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
源码: framework/db/schema/oci/COciCommandBuilder.php#41 (显示)
public function applyLimit($sql,$limit,$offset)
{
    if ((
$limit 0) and ($offset 0)) return $sql;

    
$filters = array();
    if(
$offset>0){
        
$filters[] = 'rowNumId > '.(int)$offset;
    }

    if(
$limit>=0){
        
$filters[]= 'rownum <= '.(int)$limit;
    }

    if (
count($filters) > 0){
        
$filter implode(' and '$filters);
        
$filter" WHERE ".$filter;
    }else{
        
$filter '';
    }


    
$sql = <<<EOD
WITH USER_SQL AS ({$sql}),
PAGINATION AS (SELECT USER_SQL.*, rownum as rowNumId FROM USER_SQL)
SELECT *
FROM PAGINATION
{$filter}
EOD;

    return 
$sql;
}

Alters the SQL to apply LIMIT and OFFSET.

createInsertCommand() 方法
public CDbCommand createInsertCommand(mixed $table, array $data)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$data array data to be inserted (column name=>column value). If a key is not a valid column name, the corresponding value will be ignored.
{return} CDbCommand insert command
源码: framework/db/schema/oci/COciCommandBuilder.php#79 (显示)
public function createInsertCommand($table,$data)
{
    
$this->ensureTable($table);
    
$fields=array();
    
$values=array();
    
$placeholders=array();
    
$i=0;
    foreach(
$data as $name=>$value)
    {
        if((
$column=$table->getColumn($name))!==null && ($value!==null || $column->allowNull))
        {
            
$fields[]=$column->rawName;
            if(
$value instanceof CDbExpression)
            {
                
$placeholders[]=$value->expression;
                foreach(
$value->params as $n=>$v)
                    
$values[$n]=$v;
            }
            else
            {
                
$placeholders[]=self::PARAM_PREFIX.$i;
                
$values[self::PARAM_PREFIX.$i]=$column->typecast($value);
                
$i++;
            }
        }
    }

    
$sql="INSERT INTO {$table->rawName} (".implode(', ',$fields).') VALUES ('.implode(', ',$placeholders).')';

    if(
is_string($table->primaryKey) && ($column=$table->getColumn($table->primaryKey))!==null && $column->type!=='string')
    {
        
$sql.=' RETURNING '.$column->rawName.' INTO :RETURN_ID';
        
$command=$this->getDbConnection()->createCommand($sql);
        
$command->bindParam(':RETURN_ID'$this->returnIDPDO::PARAM_INT12);
        
$table->sequenceName='RETURN_ID';
    }
    else
        
$command=$this->getDbConnection()->createCommand($sql);

    foreach(
$values as $name=>$value)
        
$command->bindValue($name,$value);

    return 
$command;
}

Creates an INSERT command.

createMultipleInsertCommand() 方法 (自版本 v1.1.14 可用)
public CDbCommand createMultipleInsertCommand(mixed $table, array $data)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$data array list data to be inserted, each value should be an array in format (column name=>column value). If a key is not a valid column name, the corresponding value will be ignored.
{return} CDbCommand multiple insert command
源码: framework/db/schema/oci/COciCommandBuilder.php#134 (显示)
public function createMultipleInsertCommand($table,array $data)
{
    
$templates=array(
        
'main'=>'INSERT ALL {{rowInsertValues}} SELECT * FROM dual',
        
'columnInsertValue'=>'{{value}}',
        
'columnInsertValueGlue'=>', ',
        
'rowInsertValue'=>'INTO {{tableName}} ({{columnInsertNames}}) VALUES ({{columnInsertValues}})',
        
'rowInsertValueGlue'=>' ',
        
'columnInsertNameGlue'=>', ',
    );
    return 
$this->composeMultipleInsertCommand($table,$data,$templates);
}

Creates a multiple INSERT command. This method could be used to achieve better performance during insertion of the large amount of data into the database tables.

getLastInsertID() 方法
public mixed getLastInsertID(mixed $table)
$table mixed the table schema (CDbTableSchema) or the table name (string).
{return} mixed last insertion id. Null is returned if no sequence name.
源码: framework/db/schema/oci/COciCommandBuilder.php#29 (显示)
public function getLastInsertID($table)
{
    return 
$this->returnID;
}

Returns the last insertion ID for the specified table.