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
b2d91669
Commit
b2d91669
authored
Dec 17, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored scalar query functions to share common code
parent
124a73a5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
27 deletions
+19
-27
Query.php
framework/yii/db/Query.php
+19
-27
No files found.
framework/yii/db/Query.php
View file @
b2d91669
...
@@ -190,11 +190,7 @@ class Query extends Component implements QueryInterface
...
@@ -190,11 +190,7 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
count
(
$q
=
'*'
,
$db
=
null
)
public
function
count
(
$q
=
'*'
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
return
$this
->
queryScalar
(
"COUNT(
$q
)"
,
$db
);
$this
->
select
=
[
"COUNT(
$q
)"
];
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -207,11 +203,7 @@ class Query extends Component implements QueryInterface
...
@@ -207,11 +203,7 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
sum
(
$q
,
$db
=
null
)
public
function
sum
(
$q
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
return
$this
->
queryScalar
(
"SUM(
$q
)"
,
$db
);
$this
->
select
=
[
"SUM(
$q
)"
];
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -224,11 +216,7 @@ class Query extends Component implements QueryInterface
...
@@ -224,11 +216,7 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
average
(
$q
,
$db
=
null
)
public
function
average
(
$q
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
return
$this
->
queryScalar
(
"AVG(
$q
)"
,
$db
);
$this
->
select
=
[
"AVG(
$q
)"
];
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -241,11 +229,7 @@ class Query extends Component implements QueryInterface
...
@@ -241,11 +229,7 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
min
(
$q
,
$db
=
null
)
public
function
min
(
$q
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
return
$this
->
queryScalar
(
"MIN(
$q
)"
,
$db
);
$this
->
select
=
[
"MIN(
$q
)"
];
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -258,11 +242,7 @@ class Query extends Component implements QueryInterface
...
@@ -258,11 +242,7 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
max
(
$q
,
$db
=
null
)
public
function
max
(
$q
,
$db
=
null
)
{
{
$select
=
$this
->
select
;
return
$this
->
queryScalar
(
"MAX(
$q
)"
,
$db
);
$this
->
select
=
[
"MAX(
$q
)"
];
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
@@ -273,11 +253,23 @@ class Query extends Component implements QueryInterface
...
@@ -273,11 +253,23 @@ class Query extends Component implements QueryInterface
*/
*/
public
function
exists
(
$db
=
null
)
public
function
exists
(
$db
=
null
)
{
{
return
$this
->
queryScalar
(
new
Expression
(
'1'
),
$db
)
!==
false
;
}
/**
* Queries a scalar value by setting [[select]] first.
* Restores the value of select to make this query reusable.
* @param string|Expression $selectExpression
* @param Connection $db
* @return bool|string
*/
private
function
queryScalar
(
$selectExpression
,
$db
)
{
$select
=
$this
->
select
;
$select
=
$this
->
select
;
$this
->
select
=
[
new
Expression
(
'1'
)
];
$this
->
select
=
[
$selectExpression
];
$command
=
$this
->
createCommand
(
$db
);
$command
=
$this
->
createCommand
(
$db
);
$this
->
select
=
$select
;
$this
->
select
=
$select
;
return
$command
->
queryScalar
()
!==
false
;
return
$command
->
queryScalar
();
}
}
/**
/**
...
...
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