Commit 0839ceb5 by Klimov Paul

Parameter "options" added to "yii\sphinx\Command::update()"

parent 36da1617
...@@ -453,11 +453,12 @@ class Command extends Component ...@@ -453,11 +453,12 @@ class Command extends Component
* @param string|array $condition the condition that will be put in the WHERE part. Please * @param string|array $condition the condition that will be put in the WHERE part. Please
* refer to [[Query::where()]] on how to specify condition. * refer to [[Query::where()]] on how to specify condition.
* @param array $params the parameters to be bound to the command * @param array $params the parameters to be bound to the command
* @param array $options list of options in format: optionName => optionValue
* @return static the command object itself * @return static the command object itself
*/ */
public function update($index, $columns, $condition = '', $params = []) public function update($index, $columns, $condition = '', $params = [], $options = [])
{ {
$sql = $this->db->getQueryBuilder()->update($index, $columns, $condition, $params); $sql = $this->db->getQueryBuilder()->update($index, $columns, $condition, $params, $options);
return $this->setSql($sql)->bindValues($params); return $this->setSql($sql)->bindValues($params);
} }
......
...@@ -14,7 +14,7 @@ namespace yii\sphinx; ...@@ -14,7 +14,7 @@ namespace yii\sphinx;
* @property QueryBuilder $queryBuilder The query builder for this Sphinx connection. This property is * @property QueryBuilder $queryBuilder The query builder for this Sphinx connection. This property is
* read-only. * read-only.
* @method Schema getSchema() The schema information for this Sphinx connection * @method Schema getSchema() The schema information for this Sphinx connection
* @method QueryBuilder getQueryBuilder() he query builder for this Sphinx connection * @method QueryBuilder getQueryBuilder() the query builder for this Sphinx connection
* *
* @author Paul Klimov <klimov.paul@gmail.com> * @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0 * @since 2.0
......
...@@ -204,9 +204,10 @@ class QueryBuilder extends Object ...@@ -204,9 +204,10 @@ class QueryBuilder extends Object
* refer to [[Query::where()]] on how to specify condition. * refer to [[Query::where()]] on how to specify condition.
* @param array $params the binding parameters that will be modified by this method * @param array $params the binding parameters that will be modified by this method
* so that they can be bound to the DB command later. * so that they can be bound to the DB command later.
* @param array $options list of options in format: optionName => optionValue
* @return string the UPDATE SQL * @return string the UPDATE SQL
*/ */
public function update($index, $columns, $condition, &$params) public function update($index, $columns, $condition, &$params, $options)
{ {
if (($indexSchema = $this->db->getIndexSchema($index)) !== null) { if (($indexSchema = $this->db->getIndexSchema($index)) !== null) {
$columnSchemas = $indexSchema->columns; $columnSchemas = $indexSchema->columns;
...@@ -241,7 +242,14 @@ class QueryBuilder extends Object ...@@ -241,7 +242,14 @@ class QueryBuilder extends Object
$sql = 'UPDATE ' . $this->db->quoteIndexName($index) . ' SET ' . implode(', ', $lines); $sql = 'UPDATE ' . $this->db->quoteIndexName($index) . ' SET ' . implode(', ', $lines);
$where = $this->buildWhere($condition, $params); $where = $this->buildWhere($condition, $params);
return $where === '' ? $sql : $sql . ' ' . $where; if ($where !== '') {
$sql = $sql . ' ' . $where;
}
$option = $this->buildOption($options, $params);
if ($option !== '') {
$sql = $sql . ' ' . $option;
}
return $sql;
} }
/** /**
......
...@@ -233,6 +233,36 @@ class CommandTest extends SphinxTestCase ...@@ -233,6 +233,36 @@ class CommandTest extends SphinxTestCase
} }
/** /**
* @depends testUpdate
*/
public function testUpdateWithOptions()
{
$db = $this->getConnection();
$db->createCommand()->insert('yii2_test_rt_index', [
'title' => 'Test title',
'content' => 'Test content',
'type_id' => 2,
'id' => 1,
])->execute();
$newTypeId = 5;
$command = $db->createCommand()->update(
'yii2_test_rt_index',
[
'type_id' => $newTypeId,
'non_existing_attribute' => 10,
],
'id = 1',
[],
[
'ignore_nonexistent_columns' => 1
]
);
$this->assertEquals(1, $command->execute(), 'Unable to execute update!');
}
/**
* @depends testInsert * @depends testInsert
*/ */
public function testDelete() public function testDelete()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment