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
001d5b16
Commit
001d5b16
authored
Nov 05, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed `yii\sphinx\QueryBuilder` does not support comparison operators (>,<,>=…
Fixed `yii\sphinx\QueryBuilder` does not support comparison operators (>,<,>= etc) in where specification
parent
ec48a61c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
34 deletions
+41
-34
CHANGELOG.md
extensions/sphinx/CHANGELOG.md
+1
-0
QueryBuilder.php
extensions/sphinx/QueryBuilder.php
+35
-34
ActiveRecordTest.php
tests/unit/extensions/sphinx/ActiveRecordTest.php
+5
-0
No files found.
extensions/sphinx/CHANGELOG.md
View file @
001d5b16
...
...
@@ -5,6 +5,7 @@ Yii Framework 2 sphinx extension Change Log
-----------------------
-
Bug #5601: Simple conditions in Query::where() and ActiveQuery::where() did not allow
`yii\db\Expression`
to be used as the value (cebe, stevekr)
-
Bug #5634: Fixed
`yii\sphinx\QueryBuilder`
does not support comparison operators (>,
<
,
>
= etc) in where specification (klimov-paul)
-
Enh #5223: Query builder now supports selecting sub-queries as columns (qiangxue)
...
...
extensions/sphinx/QueryBuilder.php
View file @
001d5b16
...
...
@@ -956,6 +956,41 @@ class QueryBuilder extends Object
}
/**
* Creates an SQL expressions like `"column" operator value`.
* @param IndexSchema[] $indexes list of indexes, which affected by query
* @param string $operator the operator to use. Anything could be used e.g. `>`, `<=`, etc.
* @param array $operands contains two column names.
* @param array $params the binding parameters to be populated
* @return string the generated SQL expression
* @throws InvalidParamException if count($operands) is not 2
*/
public
function
buildSimpleCondition
(
$indexes
,
$operator
,
$operands
,
&
$params
)
{
if
(
count
(
$operands
)
!==
2
)
{
throw
new
InvalidParamException
(
"Operator '
$operator
' requires two operands."
);
}
list
(
$column
,
$value
)
=
$operands
;
if
(
strpos
(
$column
,
'('
)
===
false
)
{
$column
=
$this
->
db
->
quoteColumnName
(
$column
);
}
if
(
$value
===
null
)
{
return
"
$column
$operator
NULL"
;
}
elseif
(
$value
instanceof
Expression
)
{
foreach
(
$value
->
params
as
$n
=>
$v
)
{
$params
[
$n
]
=
$v
;
}
return
"
$column
$operator
{
$value
->
expression
}
"
;
}
else
{
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$phName
]
=
$value
;
return
"
$column
$operator
$phName
"
;
}
}
/**
* @param array $columns
* @return string the ORDER BY clause built from [[query]].
*/
...
...
@@ -1067,40 +1102,6 @@ class QueryBuilder extends Object
}
/**
* Creates an SQL expressions like `"column" operator value`.
* @param string $operator the operator to use. Anything could be used e.g. `>`, `<=`, etc.
* @param array $operands contains two column names.
* @param array $params the binding parameters to be populated
* @return string the generated SQL expression
* @throws InvalidParamException if count($operands) is not 2
*/
public
function
buildSimpleCondition
(
$operator
,
$operands
,
&
$params
)
{
if
(
count
(
$operands
)
!==
2
)
{
throw
new
InvalidParamException
(
"Operator '
$operator
' requires two operands."
);
}
list
(
$column
,
$value
)
=
$operands
;
if
(
strpos
(
$column
,
'('
)
===
false
)
{
$column
=
$this
->
db
->
quoteColumnName
(
$column
);
}
if
(
$value
===
null
)
{
return
"
$column
$operator
NULL"
;
}
elseif
(
$value
instanceof
Expression
)
{
foreach
(
$value
->
params
as
$n
=>
$v
)
{
$params
[
$n
]
=
$v
;
}
return
"
$column
$operator
{
$value
->
expression
}
"
;
}
else
{
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$phName
]
=
$value
;
return
"
$column
$operator
$phName
"
;
}
}
/**
* @param array $indexes index names.
* @return IndexSchema[] index schemas.
*/
...
...
tests/unit/extensions/sphinx/ActiveRecordTest.php
View file @
001d5b16
...
...
@@ -58,6 +58,11 @@ class ActiveRecordTest extends SphinxTestCase
$this
->
assertTrue
(
$article
instanceof
ArticleIndex
);
$this
->
assertEquals
(
2
,
$article
->
id
);
// find by comparison
$article
=
ArticleIndex
::
find
()
->
where
([
'>'
,
'author_id'
,
1
])
->
one
();
$this
->
assertTrue
(
$article
instanceof
ArticleIndex
);
$this
->
assertEquals
(
2
,
$article
->
id
);
// find custom column
$article
=
ArticleIndex
::
find
()
->
select
([
'*'
,
'(5*2) AS custom_column'
])
->
where
([
'author_id'
=>
1
])
->
one
();
...
...
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