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
6dba4da3
Commit
6dba4da3
authored
Aug 29, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #828: refactored QueryBuilder::build()
parent
147558ea
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
17 deletions
+21
-17
ActiveQuery.php
framework/yii/db/ActiveQuery.php
+4
-4
ActiveRelation.php
framework/yii/db/ActiveRelation.php
+2
-2
Query.php
framework/yii/db/Query.php
+2
-2
QueryBuilder.php
framework/yii/db/QueryBuilder.php
+12
-8
QueryBuilderTest.php
tests/unit/framework/db/QueryBuilderTest.php
+1
-1
No files found.
framework/yii/db/ActiveQuery.php
View file @
6dba4da3
...
...
@@ -156,6 +156,8 @@ class ActiveQuery extends Query
if
(
$db
===
null
)
{
$db
=
$modelClass
::
getDb
();
}
$params
=
$this
->
params
;
if
(
$this
->
sql
===
null
)
{
if
(
$this
->
from
===
null
)
{
$tableName
=
$modelClass
::
tableName
();
...
...
@@ -164,11 +166,9 @@ class ActiveQuery extends Query
}
$this
->
from
=
array
(
$tableName
);
}
/** @var $qb QueryBuilder */
$qb
=
$db
->
getQueryBuilder
();
$this
->
sql
=
$qb
->
build
(
$this
);
list
(
$this
->
sql
,
$params
)
=
$db
->
getQueryBuilder
()
->
build
(
$this
);
}
return
$db
->
createCommand
(
$this
->
sql
,
$
this
->
params
);
return
$db
->
createCommand
(
$this
->
sql
,
$params
);
}
/**
...
...
framework/yii/db/ActiveRelation.php
View file @
6dba4da3
...
...
@@ -297,7 +297,7 @@ class ActiveRelation extends ActiveQuery
/** @var $primaryModel ActiveRecord */
$primaryModel
=
reset
(
$primaryModels
);
$db
=
$primaryModel
->
getDb
();
$sql
=
$db
->
getQueryBuilder
()
->
build
(
$this
);
return
$db
->
createCommand
(
$sql
,
$
this
->
params
)
->
queryAll
();
list
(
$sql
,
$params
)
=
$db
->
getQueryBuilder
()
->
build
(
$this
);
return
$db
->
createCommand
(
$sql
,
$params
)
->
queryAll
();
}
}
framework/yii/db/Query.php
View file @
6dba4da3
...
...
@@ -149,8 +149,8 @@ class Query extends Component
if
(
$db
===
null
)
{
$db
=
Yii
::
$app
->
getDb
();
}
$sql
=
$db
->
getQueryBuilder
()
->
build
(
$this
);
return
$db
->
createCommand
(
$sql
,
$
this
->
params
);
list
(
$sql
,
$params
)
=
$db
->
getQueryBuilder
()
->
build
(
$this
);
return
$db
->
createCommand
(
$sql
,
$params
);
}
/**
...
...
framework/yii/db/QueryBuilder.php
View file @
6dba4da3
...
...
@@ -55,22 +55,24 @@ class QueryBuilder extends \yii\base\Object
/**
* Generates a SELECT SQL statement from a [[Query]] object.
* @param Query $query the [[Query]] object from which the SQL statement will be generated
* @return string the generated SQL statement
* @return array the generated SQL statement (the first array element) and the corresponding
* parameters to be bound to the SQL statement (the second array element).
*/
public
function
build
(
$query
)
{
$params
=
$query
->
params
;
$clauses
=
array
(
$this
->
buildSelect
(
$query
->
select
,
$query
->
distinct
,
$query
->
selectOption
),
$this
->
buildFrom
(
$query
->
from
),
$this
->
buildJoin
(
$query
->
join
,
$
query
->
params
),
$this
->
buildWhere
(
$query
->
where
,
$
query
->
params
),
$this
->
buildJoin
(
$query
->
join
,
$params
),
$this
->
buildWhere
(
$query
->
where
,
$params
),
$this
->
buildGroupBy
(
$query
->
groupBy
),
$this
->
buildHaving
(
$query
->
having
,
$
query
->
params
),
$this
->
buildUnion
(
$query
->
union
,
$
query
->
params
),
$this
->
buildHaving
(
$query
->
having
,
$params
),
$this
->
buildUnion
(
$query
->
union
,
$params
),
$this
->
buildOrderBy
(
$query
->
orderBy
),
$this
->
buildLimit
(
$query
->
limit
,
$query
->
offset
),
);
return
implode
(
$this
->
separator
,
array_filter
(
$clauses
)
);
return
array
(
implode
(
$this
->
separator
,
array_filter
(
$clauses
)),
$params
);
}
/**
...
...
@@ -718,9 +720,11 @@ class QueryBuilder extends \yii\base\Object
}
foreach
(
$unions
as
$i
=>
$union
)
{
if
(
$union
instanceof
Query
)
{
// save the original parameters so that we can restore them later to prevent from modifying the query object
$originalParams
=
$union
->
params
;
$union
->
addParams
(
$params
);
$unions
[
$i
]
=
$this
->
build
(
$union
);
$
params
=
$union
->
p
arams
;
list
(
$unions
[
$i
],
$params
)
=
$this
->
build
(
$union
);
$
union
->
params
=
$originalP
arams
;
}
}
return
"UNION (
\n
"
.
implode
(
"
\n
) UNION (
\n
"
,
$unions
)
.
"
\n
)"
;
...
...
tests/unit/framework/db/QueryBuilderTest.php
View file @
6dba4da3
...
...
@@ -112,7 +112,7 @@ class QueryBuilderTest extends DatabaseTestCase
}
}
public
function
testAddDropPrimayKey
()
public
function
testAddDropPrima
r
yKey
()
{
$tableName
=
'tbl_constraints'
;
$pkeyName
=
$tableName
.
"_pkey"
;
...
...
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