Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
0839ceb5
Commit
0839ceb5
authored
Nov 13, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parameter "options" added to "yii\sphinx\Command::update()"
parent
36da1617
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
5 deletions
+44
-5
Command.php
extensions/sphinx/Command.php
+3
-2
Connection.php
extensions/sphinx/Connection.php
+1
-1
QueryBuilder.php
extensions/sphinx/QueryBuilder.php
+10
-2
CommandTest.php
tests/unit/extensions/sphinx/CommandTest.php
+30
-0
No files found.
extensions/sphinx/Command.php
View file @
0839ceb5
...
...
@@ -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
);
}
...
...
extensions/sphinx/Connection.php
View file @
0839ceb5
...
...
@@ -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()
t
he query builder for this Sphinx connection
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
...
...
extensions/sphinx/QueryBuilder.php
View file @
0839ceb5
...
...
@@ -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
;
}
/**
...
...
tests/unit/extensions/sphinx/CommandTest.php
View file @
0839ceb5
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment