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
320c72ed
Commit
320c72ed
authored
Aug 02, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring query class.
parent
e678b77b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
22 deletions
+9
-22
query.php
system/db/query.php
+9
-22
No files found.
system/db/query.php
View file @
320c72ed
...
...
@@ -170,7 +170,7 @@ class Query {
}
/**
* Reset the where clause to its initial state.
* Reset the where clause to its initial state.
All bindings will be cleared.
*
* @return void
*/
...
...
@@ -345,6 +345,9 @@ class Query {
/**
* Add dynamic where conditions to the query.
*
* Dynamic queries are caught by the __call magic method and are parsed here.
* They provide a convenient, expressive API for building simple conditions.
*
* @param string $method
* @param array $parameters
* @return Query
...
...
@@ -466,24 +469,11 @@ class Query {
*/
public
function
paginate
(
$per_page
,
$columns
=
array
(
'*'
))
{
$select
=
$this
->
select
;
$total
=
$this
->
count
();
// Every query clears the SELECT clause, so we store the contents of the clause
// before executing the count query and then put the contents back in afterwards.
if
(
!
is_null
(
$select
))
{
$this
->
select
=
$select
;
}
else
{
$this
->
select
(
$columns
);
}
$current_page
=
\System\Paginator
::
page
(
$total
,
$per_page
);
$this
->
select
(
$columns
);
return
\System\Paginator
::
make
(
$this
->
for_page
(
$current_page
,
$per_page
)
->
get
(),
$total
,
$per_page
);
return
\System\Paginator
::
make
(
$this
->
for_page
(
\System\Paginator
::
page
(
$total
,
$per_page
)
,
$per_page
)
->
get
(),
$total
,
$per_page
);
}
/**
...
...
@@ -557,8 +547,8 @@ class Query {
{
$sql
=
$this
->
compile_insert
(
$values
);
// Use the RETURNING clause on Postgre
s instead of the PDO lastInsertID method
.
//
The PDO method is a little cumbersome using Postgres
.
// Use the RETURNING clause on Postgre
SQL so don't have to worry about sequence columns
.
//
MySQL and SQLite can use the PDO's lastInsertID() method
.
if
(
$this
->
connection
->
driver
()
==
'pgsql'
)
{
$query
=
$this
->
connection
->
pdo
->
prepare
(
$sql
.
' RETURNING '
.
$this
->
wrap
(
'id'
));
...
...
@@ -583,10 +573,7 @@ class Query {
{
$sql
=
'INSERT INTO '
.
$this
->
wrap
(
$this
->
table
);
foreach
(
array_keys
(
$values
)
as
$column
)
{
$columns
[]
=
$this
->
wrap
(
$column
);
}
$columns
=
array_map
(
array
(
$this
,
'wrap'
),
array_keys
(
$values
));
return
$sql
.=
' ('
.
implode
(
', '
,
$columns
)
.
') VALUES ('
.
$this
->
parameterize
(
$values
)
.
')'
;
}
...
...
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