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
1f42b72b
Commit
1f42b72b
authored
Feb 06, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #2346: ActiveQuery used in building sub-query should not need to set FROM clause explicitly.
parent
fa353294
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
Query.php
framework/db/Query.php
+4
-1
QueryBuilder.php
framework/db/QueryBuilder.php
+13
-3
No files found.
framework/db/Query.php
View file @
1f42b72b
...
...
@@ -95,7 +95,10 @@ class Query extends Component implements QueryInterface
public
$having
;
/**
* @var array this is used to construct the UNION clause(s) in a SQL statement.
* Each array element can be either a string or a [[Query]] object representing a sub-query.
* Each array element is an array of the following structure:
*
* - `query`: either a string or a [[Query]] object representing a query
* - `all`: boolean, whether it should be `UNION ALL` or `UNION`
*/
public
$union
;
/**
...
...
framework/db/QueryBuilder.php
View file @
1f42b72b
...
...
@@ -767,8 +767,11 @@ class QueryBuilder extends \yii\base\Object
if
(
$query
instanceof
Query
)
{
// save the original parameters so that we can restore them later to prevent from modifying the query object
$originalParams
=
$query
->
params
;
$query
->
addParams
(
$params
);
list
(
$unions
[
$i
][
'query'
],
$params
)
=
$this
->
build
(
$query
);
$command
=
$query
->
createCommand
(
$this
->
db
);
$unions
[
$i
][
'query'
]
=
$command
->
sql
;
foreach
(
$command
->
params
as
$name
=>
$value
)
{
$params
[
$name
]
=
$value
;
}
$query
->
params
=
$originalParams
;
}
...
...
@@ -1107,11 +1110,18 @@ class QueryBuilder extends \yii\base\Object
* @param array $operands contains only one element which is a [[Query]] object representing the sub-query.
* @param array $params the binding parameters to be populated
* @return string the generated SQL expression
* @throws InvalidParamException if the operand is not a [[Query]] object.
*/
public
function
buildExistsCondition
(
$operator
,
$operands
,
&
$params
)
{
$subQuery
=
$operands
[
0
];
list
(
$subQuerySql
,
$subQueryParams
)
=
$this
->
build
(
$subQuery
);
if
(
!
$subQuery
instanceof
Query
)
{
throw
new
InvalidParamException
(
'Subquery for EXISTS operator must be a Query object.'
);
}
$command
=
$subQuery
->
createCommand
(
$this
->
db
);
$subQuerySql
=
$command
->
sql
;
$subQueryParams
=
$command
->
params
;
if
(
!
empty
(
$subQueryParams
))
{
foreach
(
$subQueryParams
as
$name
=>
$value
)
{
$params
[
$name
]
=
$value
;
...
...
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