Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions RDbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,30 @@ public function insertIgnore($table, $columns)
* 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.
* @param array $columns the column data (name=>value) to be inserted into the table
* or array(array(name=>value),array(name=>value)).
* or array(array(name=>value),array(name=>value)).
* @param array $update the column data (name=>value) to be update
* @param string $ignore '' or 'IGNORE'
* @return integer number of rows affected by the execution.
* @return int number of rows affected by the execution.
* @throws CDbException
*/
public function insertUpdate($table, $columns, $update=array(), $ignore='')
{
if(!$table || !is_string($table))
{
throw new CDbException(Yii::t('ext.RDbCommand', 'Table name should be a valid string.'));
}

if(!$columns || !is_array($columns))
{
throw new CDbException(Yii::t('ext.RDbCommand', 'Columns should be a valid one demention array.'));
}

list($names, $placeholders, $params) = $this->_insert($columns);

$sql="INSERT {$ignore} INTO " . $this->getConnection()->quoteTableName($table)
. ' (' . implode(', ',$names) . ') VALUES '
. implode(', ', $placeholders);

list($lines, $params) = $this->_updatePrepare($update, $params);
if($lines)
{
Expand Down Expand Up @@ -92,6 +93,8 @@ protected function _insert($columns)
/**
* Prepare $names, $placeholders, $params
* @param array $columns
* @param string $iterat
* @param array $params
* @return array array($names, $placeholders, $params)
*/
protected function _insertPrepare($columns, $iterat='', $params=array())
Expand Down Expand Up @@ -121,6 +124,7 @@ protected function _insertPrepare($columns, $iterat='', $params=array())
/**
* Prepare $lines, $params
* @param array $columns
* @param array $params
* @return array array($lines, $params)
*/
protected function _updatePrepare($columns, $params=array())
Expand All @@ -130,13 +134,13 @@ protected function _updatePrepare($columns, $params=array())
{
if($value instanceof CDbExpression)
{
$lines[]=$this->_connection->quoteColumnName($name) . '=' . $value->expression;
$lines[]=$this->getConnection()->quoteColumnName($name) . '=' . $value->expression;
foreach($value->params as $n => $v)
$params[$n] = $v;
}
else
{
$lines[]=$this->_connection->quoteColumnName($name) . '=:' . $name;
$lines[]=$this->getConnection()->quoteColumnName($name) . '=:' . $name;
$params[$this->_paramName(':' . $name, $params)]=$value;
}
}
Expand Down
12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "RSol/RDB",
"description": "Yii extention for MySQL database",
"version": "0.1.1",
"type": "library",
"require": {
"yiisoft/yii": ">=1.1.1, <2"
},
"autoload": {
"classmap" : ["RDbCommand.php", "RDbConnection.php"]
}
}