|
|
|
@ -34,6 +34,8 @@ namespace yii\db\dao;
|
|
|
|
|
* And by calling [[createCommand()]], we can get a [[Command]] instance which can be further |
|
|
|
|
* used to perform/execute the DB query against a database. |
|
|
|
|
* |
|
|
|
|
* @property string $sql the SQL statement represented by this query object. |
|
|
|
|
* |
|
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
|
* @since 2.0 |
|
|
|
|
*/ |
|
|
|
@ -512,6 +514,38 @@ class Query extends \yii\base\Object
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets the parameters to be bound to the query. |
|
|
|
|
* @param array list of query parameter values indexed by parameter placeholders. |
|
|
|
|
* For example, `array(':name'=>'Dan', ':age'=>31)`. |
|
|
|
|
* @return Query the query object itself |
|
|
|
|
* @see addParams() |
|
|
|
|
*/ |
|
|
|
|
public function params($params) |
|
|
|
|
{ |
|
|
|
|
$this->params = $params; |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Adds additional parameters to be bound to the query. |
|
|
|
|
* @param array list of query parameter values indexed by parameter placeholders. |
|
|
|
|
* For example, `array(':name'=>'Dan', ':age'=>31)`. |
|
|
|
|
* @return Query the query object itself |
|
|
|
|
* @see params() |
|
|
|
|
*/ |
|
|
|
|
public function addParams($params) |
|
|
|
|
{ |
|
|
|
|
foreach ($params as $name => $value) { |
|
|
|
|
if (is_integer($name)) { |
|
|
|
|
$this->params[] = $value; |
|
|
|
|
} else { |
|
|
|
|
$this->params[$name] = $value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates and executes an INSERT SQL statement. |
|
|
|
|
* The method will properly escape the column names, and bind the values to be inserted. |
|
|
|
|
* @param string $table the table that new rows will be inserted into. |
|
|
|
@ -520,7 +554,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function insert($table, $columns) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('insert', $table, $columns, array()); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $columns, array()); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -537,7 +571,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
public function update($table, $columns, $condition = '', $params = array()) |
|
|
|
|
{ |
|
|
|
|
$this->addParams($params); |
|
|
|
|
$this->operation = array('update', $table, $columns, $condition, array()); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $columns, $condition, array()); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -551,7 +585,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function delete($table, $condition = '', $params = array()) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('delete', $table, $condition); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $condition); |
|
|
|
|
return $this->addParams($params); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -575,7 +609,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function createTable($table, $columns, $options = null) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('createTable', $table, $columns, $options); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $columns, $options); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -587,7 +621,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function renameTable($table, $newName) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('renameTable', $table, $newName); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $newName); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -598,7 +632,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function dropTable($table) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('dropTable', $table); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -609,7 +643,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function truncateTable($table) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('truncateTable', $table); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -624,7 +658,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function addColumn($table, $column, $type) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('addColumn', $table, $column, $type); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $column, $type); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -636,7 +670,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function dropColumn($table, $column) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('dropColumn', $table, $column); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $column); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -649,7 +683,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function renameColumn($table, $name, $newName) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('renameColumn', $table, $name, $newName); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $name, $newName); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -664,7 +698,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function alterColumn($table, $column, $type) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('alterColumn', $table, $column, $type); |
|
|
|
|
$this->operation = array(__FUNCTION__, $table, $column, $type); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -682,7 +716,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('addForeignKey', $name, $table, $columns, $refTable, $refColumns, $delete, $update); |
|
|
|
|
$this->operation = array(__FUNCTION__, $name, $table, $columns, $refTable, $refColumns, $delete, $update); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -694,7 +728,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function dropForeignKey($name, $table) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('dropForeignKey', $name, $table); |
|
|
|
|
$this->operation = array(__FUNCTION__, $name, $table); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -709,7 +743,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function createIndex($name, $table, $columns, $unique = false) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('createIndex', $name, $table, $columns, $unique); |
|
|
|
|
$this->operation = array(__FUNCTION__, $name, $table, $columns, $unique); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -721,39 +755,7 @@ class Query extends \yii\base\Object
|
|
|
|
|
*/ |
|
|
|
|
public function dropIndex($name, $table) |
|
|
|
|
{ |
|
|
|
|
$this->operation = array('dropIndex', $name, $table); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets the parameters to be bound to the query. |
|
|
|
|
* @param array list of query parameter values indexed by parameter placeholders. |
|
|
|
|
* For example, `array(':name'=>'Dan', ':age'=>31)`. |
|
|
|
|
* @return Query the query object itself |
|
|
|
|
* @see addParams() |
|
|
|
|
*/ |
|
|
|
|
public function params($params) |
|
|
|
|
{ |
|
|
|
|
$this->params = $params; |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Adds additional parameters to be bound to the query. |
|
|
|
|
* @param array list of query parameter values indexed by parameter placeholders. |
|
|
|
|
* For example, `array(':name'=>'Dan', ':age'=>31)`. |
|
|
|
|
* @return Query the query object itself |
|
|
|
|
* @see params() |
|
|
|
|
*/ |
|
|
|
|
public function addParams($params) |
|
|
|
|
{ |
|
|
|
|
foreach ($params as $name => $value) { |
|
|
|
|
if (is_integer($name)) { |
|
|
|
|
$this->params[] = $value; |
|
|
|
|
} else { |
|
|
|
|
$this->params[$name] = $value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$this->operation = array(__FUNCTION__, $name, $table); |
|
|
|
|
return $this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|