Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
8240b2ff
Commit
8240b2ff
authored
Feb 06, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move shortcut method into grammar.
parent
087f50a5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
37 deletions
+38
-37
laravel/database/connection.php
+1
-34
laravel/database/query/grammars/grammar.php
+37
-3
No files found.
laravel/database/connection.php
View file @
8240b2ff
...
...
@@ -206,7 +206,7 @@ class Connection {
return
!
$binding
instanceof
Expression
;
}));
$sql
=
$this
->
transform
(
$sql
,
$bindings
);
$sql
=
$this
->
grammar
()
->
shortcut
(
$sql
,
$bindings
);
$statement
=
$this
->
pdo
->
prepare
(
$sql
);
...
...
@@ -230,39 +230,6 @@ class Connection {
}
/**
* Transform an SQL query into an executable query.
*
* @param string $sql
* @param array $bindings
* @return string
*/
protected
function
transform
(
$sql
,
$bindings
)
{
// Laravel provides an easy short-cut notation for writing raw
// WHERE IN statements. If (...) is in the query, it will be
// replaced with the correct number of parameters based on
// the bindings for the query.
if
(
strpos
(
$sql
,
'(...)'
)
!==
false
)
{
for
(
$i
=
0
;
$i
<
count
(
$bindings
);
$i
++
)
{
// If the binding is an array, we can assume it is being used
// to fill a "where in" condition, so we'll replace the next
// place-holder in the SQL query with the correct number of
// parameters based on the elements in the binding.
if
(
is_array
(
$bindings
[
$i
]))
{
$parameters
=
$this
->
grammar
()
->
parameterize
(
$bindings
[
$i
]);
$sql
=
preg_replace
(
'~\(\.\.\.\)~'
,
"(
{
$parameters
}
)"
,
$sql
,
1
);
}
}
}
return
trim
(
$sql
);
}
/**
* Log the query and fire the core query event.
*
* @param string $sql
...
...
laravel/database/query/grammars/grammar.php
View file @
8240b2ff
...
...
@@ -75,9 +75,10 @@ class Grammar extends \Laravel\Database\Grammar {
*/
protected
function
selects
(
Query
$query
)
{
// Sometimes developers may set a "select" clause on the same query that
// is performing in aggregate look-up, such as during pagination. So we
// will not generate the select clause if an aggregate is present.
// Sometimes developers may set a "select" clause on the same query
// that is performing in aggregate look-up, like during pagination.
// So we will not generate the select clause if an aggregate is
// present so the aggregates work.
if
(
!
is_null
(
$query
->
aggregate
))
return
;
$select
=
(
$query
->
distinct
)
?
'SELECT DISTINCT '
:
'SELECT '
;
...
...
@@ -388,4 +389,36 @@ class Grammar extends \Laravel\Database\Grammar {
return
trim
(
"DELETE FROM
{
$table
}
"
.
$this
->
wheres
(
$query
));
}
/**
* Transform an SQL short-cuts into real SQL for PDO.
*
* @param string $sql
* @param array $bindings
* @return string
*/
public
function
shortcut
(
$sql
,
$bindings
)
{
// Laravel provides an easy short-cut notation for writing raw
// WHERE IN statements. If (...) is in the query, it will be
// replaced with the correct number of parameters based on
// the bindings for the query.
if
(
strpos
(
$sql
,
'(...)'
)
!==
false
)
{
for
(
$i
=
0
;
$i
<
count
(
$bindings
);
$i
++
)
{
// If the binding is an array, we can just assume it's
// used to fill a "where in" condition, so we'll just
// replace the next place-holder in the query.
if
(
is_array
(
$bindings
[
$i
]))
{
$parameters
=
$this
->
parameterize
(
$bindings
[
$i
]);
$sql
=
preg_replace
(
'~\(\.\.\.\)~'
,
"(
{
$parameters
}
)"
,
$sql
,
1
);
}
}
}
return
trim
(
$sql
);
}
}
\ No newline at end of file
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