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
0f8f3f34
Commit
0f8f3f34
authored
Jun 17, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Query\Compiler.
parent
00fcaf2b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
38 deletions
+8
-38
compiler.php
system/db/query/compiler.php
+8
-38
No files found.
system/db/query/compiler.php
View file @
0f8f3f34
...
...
@@ -10,30 +10,18 @@ class Compiler {
*/
public
static
function
select
(
$query
)
{
// ----------------------------------------------------
// Add the SELECT, FROM, and WHERE clause to the query.
// ----------------------------------------------------
$sql
=
$query
->
select
.
' '
.
$query
->
from
.
' '
.
$query
->
where
;
// ----------------------------------------------------
// Add the ORDER BY clause to the query.
// ----------------------------------------------------
if
(
count
(
$query
->
orderings
)
>
0
)
{
$sql
.=
' ORDER BY '
.
implode
(
', '
,
$query
->
orderings
);
}
// ----------------------------------------------------
// Add the LIMIT clause to the query.
// ----------------------------------------------------
if
(
!
is_null
(
$query
->
limit
))
{
$sql
.=
' LIMIT '
.
$query
->
limit
;
}
// ----------------------------------------------------
// Add the OFFSET clause to the query.
// ----------------------------------------------------
if
(
!
is_null
(
$query
->
offset
))
{
$sql
.=
' OFFSET '
.
$query
->
offset
;
...
...
@@ -51,14 +39,8 @@ class Compiler {
*/
public
static
function
insert
(
$query
,
$values
)
{
// -----------------------------------------------------
// Begin the INSERT statement.
// -----------------------------------------------------
$sql
=
'INSERT INTO '
.
$query
->
table
.
' ('
;
// ----------------------------------------------------
// Wrap each column name in keyword identifiers.
// ----------------------------------------------------
$sql
=
'INSERT INTO '
.
$query
->
wrap
(
$query
->
table
);
$columns
=
array
();
foreach
(
array_keys
(
$values
)
as
$column
)
...
...
@@ -66,10 +48,7 @@ class Compiler {
$columns
[]
=
$query
->
wrap
(
$column
);
}
// -----------------------------------------------------
// Concatenante the columns and values to the statement.
// -----------------------------------------------------
return
$sql
.=
implode
(
', '
,
$columns
)
.
') VALUES ('
.
$query
->
parameterize
(
$values
)
.
')'
;
return
$sql
.=
' ('
.
implode
(
', '
,
$columns
)
.
') VALUES ('
.
$query
->
parameterize
(
$values
)
.
')'
;
}
/**
...
...
@@ -81,25 +60,16 @@ class Compiler {
*/
public
static
function
update
(
$query
,
$values
)
{
// ----------------------------------------------------
// Initialize the UPDATE statement.
// ----------------------------------------------------
$sql
=
'UPDATE '
.
$query
->
table
.
' SET '
;
// ---------------------------------------------------
// Add each column set the statement.
// ---------------------------------------------------
$columns
=
array
();
$sql
=
'UPDATE '
.
$query
->
wrap
(
$query
->
table
)
.
' SET '
;
$sets
=
array
();
foreach
(
array_keys
(
$values
)
as
$column
)
{
$
column
s
[]
=
$query
->
wrap
(
$column
)
.
' = ?'
;
$
set
s
[]
=
$query
->
wrap
(
$column
)
.
' = ?'
;
}
// ---------------------------------------------------
// Concatenate the SETs to the statement.
// ---------------------------------------------------
return
$sql
.=
implode
(
', '
,
$columns
)
.
' '
.
$query
->
where
;
return
$sql
.=
implode
(
', '
,
$sets
)
.
' '
.
$query
->
where
;
}
/**
...
...
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