Commit 8240b2ff authored by Taylor Otwell's avatar Taylor Otwell

move shortcut method into grammar.

parent 087f50a5
......@@ -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);
......@@ -229,39 +229,6 @@ class Connection {
return array($statement, $result);
}
/**
* 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.
*
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment