Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
bc8c0f2c
Commit
bc8c0f2c
authored
Jul 07, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Query class. Remove comment bloat.
parent
98a691fa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
20 deletions
+6
-20
query.php
system/db/query.php
+6
-20
No files found.
system/db/query.php
View file @
bc8c0f2c
...
@@ -125,10 +125,8 @@ class Query {
...
@@ -125,10 +125,8 @@ class Query {
foreach
(
func_get_args
()
as
$column
)
foreach
(
func_get_args
()
as
$column
)
{
{
// ---------------------------------------------------------
// If the column name is being aliased, we will need to wrap the column
// If the column name is being aliased, we will need to
// name and its alias in keyword identifiers.
// wrap the column name and its alias.
// ---------------------------------------------------------
if
(
strpos
(
strtolower
(
$column
),
' as '
)
!==
false
)
if
(
strpos
(
strtolower
(
$column
),
' as '
)
!==
false
)
{
{
$segments
=
explode
(
' '
,
$column
);
$segments
=
explode
(
' '
,
$column
);
...
@@ -433,6 +431,7 @@ class Query {
...
@@ -433,6 +431,7 @@ class Query {
private
function
aggregate
(
$aggregator
,
$column
)
private
function
aggregate
(
$aggregator
,
$column
)
{
{
$this
->
select
=
'SELECT '
.
$aggregator
.
'('
.
$this
->
wrap
(
$column
)
.
') AS '
.
$this
->
wrap
(
'aggregate'
);
$this
->
select
=
'SELECT '
.
$aggregator
.
'('
.
$this
->
wrap
(
$column
)
.
') AS '
.
$this
->
wrap
(
'aggregate'
);
return
$this
->
first
()
->
aggregate
;
return
$this
->
first
()
->
aggregate
;
}
}
...
@@ -457,10 +456,8 @@ class Query {
...
@@ -457,10 +456,8 @@ class Query {
{
{
$sql
=
Query\Compiler
::
insert
(
$this
,
$values
);
$sql
=
Query\Compiler
::
insert
(
$this
,
$values
);
// ---------------------------------------------------------
// Use the RETURNING clause on Postgres instead of the PDO lastInsertID method.
// Use the RETURNING clause on Postgres instead of PDO.
// The PDO method is a little cumbersome using Postgres.
// The Postgres PDO ID method is slightly cumbersome.
// ---------------------------------------------------------
if
(
DB
::
driver
(
$this
->
connection
)
==
'pgsql'
)
if
(
DB
::
driver
(
$this
->
connection
)
==
'pgsql'
)
{
{
$query
=
DB
::
connection
(
$this
->
connection
)
->
prepare
(
$sql
.
' RETURNING '
.
$this
->
wrap
(
'id'
));
$query
=
DB
::
connection
(
$this
->
connection
)
->
prepare
(
$sql
.
' RETURNING '
.
$this
->
wrap
(
'id'
));
...
@@ -470,9 +467,6 @@ class Query {
...
@@ -470,9 +467,6 @@ class Query {
return
$query
->
fetch
(
\PDO
::
FETCH_CLASS
,
'stdClass'
)
->
id
;
return
$query
->
fetch
(
\PDO
::
FETCH_CLASS
,
'stdClass'
)
->
id
;
}
}
// ---------------------------------------------------------
// Use the PDO ID method for MySQL and SQLite.
// ---------------------------------------------------------
DB
::
query
(
$sql
,
array_values
(
$values
),
$this
->
connection
);
DB
::
query
(
$sql
,
array_values
(
$values
),
$this
->
connection
);
return
DB
::
connection
(
$this
->
connection
)
->
lastInsertId
();
return
DB
::
connection
(
$this
->
connection
)
->
lastInsertId
();
...
@@ -514,6 +508,7 @@ class Query {
...
@@ -514,6 +508,7 @@ class Query {
public
function
wrap
(
$value
)
public
function
wrap
(
$value
)
{
{
$wrap
=
(
DB
::
driver
(
$this
->
connection
)
==
'mysql'
)
?
'`'
:
'"'
;
$wrap
=
(
DB
::
driver
(
$this
->
connection
)
==
'mysql'
)
?
'`'
:
'"'
;
return
implode
(
'.'
,
array_map
(
function
(
$segment
)
use
(
$wrap
)
{
return
(
$segment
!=
'*'
)
?
$wrap
.
$segment
.
$wrap
:
$segment
;},
explode
(
'.'
,
$value
)));
return
implode
(
'.'
,
array_map
(
function
(
$segment
)
use
(
$wrap
)
{
return
(
$segment
!=
'*'
)
?
$wrap
.
$segment
.
$wrap
:
$segment
;},
explode
(
'.'
,
$value
)));
}
}
...
@@ -533,20 +528,11 @@ class Query {
...
@@ -533,20 +528,11 @@ class Query {
*/
*/
public
function
__call
(
$method
,
$parameters
)
public
function
__call
(
$method
,
$parameters
)
{
{
// ---------------------------------------------------------
// Dynamic methods allows the building of very expressive
// queries. All dynamic methods start with "where_".
//
// Ex: DB::table('users')->where_email($email)->first();
// ---------------------------------------------------------
if
(
strpos
(
$method
,
'where_'
)
===
0
)
if
(
strpos
(
$method
,
'where_'
)
===
0
)
{
{
return
Query\Dynamic
::
build
(
$method
,
$parameters
,
$this
);
return
Query\Dynamic
::
build
(
$method
,
$parameters
,
$this
);
}
}
// ---------------------------------------------------------
// Handle any of the aggregate functions.
// ---------------------------------------------------------
if
(
in_array
(
$method
,
array
(
'count'
,
'min'
,
'max'
,
'avg'
,
'sum'
)))
if
(
in_array
(
$method
,
array
(
'count'
,
'min'
,
'max'
,
'avg'
,
'sum'
)))
{
{
return
(
$method
==
'count'
)
?
$this
->
aggregate
(
strtoupper
(
$method
),
'*'
)
:
$this
->
aggregate
(
strtoupper
(
$method
),
$parameters
[
0
]);
return
(
$method
==
'count'
)
?
$this
->
aggregate
(
strtoupper
(
$method
),
'*'
)
:
$this
->
aggregate
(
strtoupper
(
$method
),
$parameters
[
0
]);
...
...
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