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
124a73a5
Commit
124a73a5
authored
Dec 17, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make Query reuseable
fixes #1545
parent
b59b77cd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
ActiveQuery.php
framework/yii/db/ActiveQuery.php
+11
-2
Query.php
framework/yii/db/Query.php
+24
-6
No files found.
framework/yii/db/ActiveQuery.php
View file @
124a73a5
...
@@ -123,6 +123,9 @@ class ActiveQuery extends Query implements ActiveQueryInterface
...
@@ -123,6 +123,9 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
}
if
(
$this
->
sql
===
null
)
{
if
(
$this
->
sql
===
null
)
{
$select
=
$this
->
select
;
$from
=
$this
->
from
;
if
(
$this
->
from
===
null
)
{
if
(
$this
->
from
===
null
)
{
$tableName
=
$modelClass
::
tableName
();
$tableName
=
$modelClass
::
tableName
();
if
(
$this
->
select
===
null
&&
!
empty
(
$this
->
join
))
{
if
(
$this
->
select
===
null
&&
!
empty
(
$this
->
join
))
{
...
@@ -130,8 +133,14 @@ class ActiveQuery extends Query implements ActiveQueryInterface
...
@@ -130,8 +133,14 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
}
$this
->
from
=
[
$tableName
];
$this
->
from
=
[
$tableName
];
}
}
list
(
$this
->
sql
,
$this
->
params
)
=
$db
->
getQueryBuilder
()
->
build
(
$this
);
list
(
$sql
,
$params
)
=
$db
->
getQueryBuilder
()
->
build
(
$this
);
$this
->
select
=
$select
;
$this
->
from
=
$from
;
}
else
{
$sql
=
$this
->
sql
;
$params
=
$this
->
params
;
}
}
return
$db
->
createCommand
(
$
this
->
sql
,
$this
->
params
);
return
$db
->
createCommand
(
$
sql
,
$
params
);
}
}
}
}
framework/yii/db/Query.php
View file @
124a73a5
...
@@ -190,8 +190,11 @@ class Query extends Component implements QueryInterface
...
@@ -190,8 +190,11 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
count
(
$q
=
'*'
,
$db
=
null
)
public
function
count
(
$q
=
'*'
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
$this
->
select
=
[
"COUNT(
$q
)"
];
$this
->
select
=
[
"COUNT(
$q
)"
];
return
$this
->
createCommand
(
$db
)
->
queryScalar
();
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -204,8 +207,11 @@ class Query extends Component implements QueryInterface
...
@@ -204,8 +207,11 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
sum
(
$q
,
$db
=
null
)
public
function
sum
(
$q
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
$this
->
select
=
[
"SUM(
$q
)"
];
$this
->
select
=
[
"SUM(
$q
)"
];
return
$this
->
createCommand
(
$db
)
->
queryScalar
();
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -218,8 +224,11 @@ class Query extends Component implements QueryInterface
...
@@ -218,8 +224,11 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
average
(
$q
,
$db
=
null
)
public
function
average
(
$q
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
$this
->
select
=
[
"AVG(
$q
)"
];
$this
->
select
=
[
"AVG(
$q
)"
];
return
$this
->
createCommand
(
$db
)
->
queryScalar
();
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -232,8 +241,11 @@ class Query extends Component implements QueryInterface
...
@@ -232,8 +241,11 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
min
(
$q
,
$db
=
null
)
public
function
min
(
$q
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
$this
->
select
=
[
"MIN(
$q
)"
];
$this
->
select
=
[
"MIN(
$q
)"
];
return
$this
->
createCommand
(
$db
)
->
queryScalar
();
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -246,8 +258,11 @@ class Query extends Component implements QueryInterface
...
@@ -246,8 +258,11 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
max
(
$q
,
$db
=
null
)
public
function
max
(
$q
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
$this
->
select
=
[
"MAX(
$q
)"
];
$this
->
select
=
[
"MAX(
$q
)"
];
return
$this
->
createCommand
(
$db
)
->
queryScalar
();
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -258,8 +273,11 @@ class Query extends Component implements QueryInterface
...
@@ -258,8 +273,11 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
exists
(
$db
=
null
)
public
function
exists
(
$db
=
null
)
{
{
$select
=
$this
->
select
;
$this
->
select
=
[
new
Expression
(
'1'
)];
$this
->
select
=
[
new
Expression
(
'1'
)];
return
$this
->
scalar
(
$db
)
!==
false
;
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
()
!==
false
;
}
}
/**
/**
...
...
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