Commit 0839ceb5 by Klimov Paul

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

parent 36da1617
......@@ -453,11 +453,12 @@ class Command extends Component
* @param string|array $condition the condition that will be put in the WHERE part. Please
* refer to [[Query::where()]] on how to specify condition.
* @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
*/
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);
}
......
......@@ -14,7 +14,7 @@ namespace yii\sphinx;
* @property QueryBuilder $queryBuilder The query builder for this Sphinx connection. This property is
* read-only.
* @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>
* @since 2.0
......
......@@ -204,9 +204,10 @@ class QueryBuilder extends Object
* refer to [[Query::where()]] on how to specify condition.
* @param array $params the binding parameters that will be modified by this method
* 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
*/
public function update($index, $columns, $condition, &$params)
public function update($index, $columns, $condition, &$params, $options)
{
if (($indexSchema = $this->db->getIndexSchema($index)) !== null) {
$columnSchemas = $indexSchema->columns;
......@@ -241,7 +242,14 @@ class QueryBuilder extends Object
$sql = 'UPDATE ' . $this->db->quoteIndexName($index) . ' SET ' . implode(', ', $lines);
$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
}
/**
* @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
*/
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