move shortcut method into grammar.
This commit is contained in:
parent
087f50a52c
commit
8240b2ffd1
|
@ -206,7 +206,7 @@ protected function execute($sql, $bindings = array())
|
||||||
return ! $binding instanceof Expression;
|
return ! $binding instanceof Expression;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
$sql = $this->transform($sql, $bindings);
|
$sql = $this->grammar()->shortcut($sql, $bindings);
|
||||||
|
|
||||||
$statement = $this->pdo->prepare($sql);
|
$statement = $this->pdo->prepare($sql);
|
||||||
|
|
||||||
|
@ -229,39 +229,6 @@ protected function execute($sql, $bindings = array())
|
||||||
return array($statement, $result);
|
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.
|
* Log the query and fire the core query event.
|
||||||
*
|
*
|
||||||
|
|
|
@ -75,9 +75,10 @@ final protected function concatenate($components)
|
||||||
*/
|
*/
|
||||||
protected function selects(Query $query)
|
protected function selects(Query $query)
|
||||||
{
|
{
|
||||||
// Sometimes developers may set a "select" clause on the same query that
|
// Sometimes developers may set a "select" clause on the same query
|
||||||
// is performing in aggregate look-up, such as during pagination. So we
|
// that is performing in aggregate look-up, like during pagination.
|
||||||
// will not generate the select clause if an aggregate is present.
|
// So we will not generate the select clause if an aggregate is
|
||||||
|
// present so the aggregates work.
|
||||||
if ( ! is_null($query->aggregate)) return;
|
if ( ! is_null($query->aggregate)) return;
|
||||||
|
|
||||||
$select = ($query->distinct) ? 'SELECT DISTINCT ' : 'SELECT ';
|
$select = ($query->distinct) ? 'SELECT DISTINCT ' : 'SELECT ';
|
||||||
|
@ -388,4 +389,36 @@ public function delete(Query $query)
|
||||||
return trim("DELETE FROM {$table} ".$this->wheres($query));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue