Fix parameter numbering with whereIn

This commit is contained in:
Denis Glushkov
2024-09-12 17:15:44 +05:00
parent 2009960f89
commit 2efca916ee
3 changed files with 4 additions and 25 deletions
+2
View File
@@ -77,6 +77,7 @@ class Connection extends BaseConnection
/** @inheritDoc */
public function statement($query, $bindings = []): bool
{
$query = QueryGrammar::prepareParameters($query);
return $this->run($query, $bindings, function ($query, $bindings) {
return !$this->cluster->getActiveNode()->write($query, $bindings)->isError();
});
@@ -85,6 +86,7 @@ class Connection extends BaseConnection
/** @inheritDoc */
public function affectingStatement($query, $bindings = []): int
{
$query = QueryGrammar::prepareParameters($query);
return (int)$this->statement($query, $bindings);
}
+1 -24
View File
@@ -9,30 +9,7 @@ use Illuminate\Database\Query\Grammars\Grammar;
class QueryGrammar extends Grammar
{
const PARAMETER_SIGN = '#@?';
/** @inheritDoc */
public function parameterize(array $values): string
{
$params = [];
for ($i = 0; $i < count($values); $i++) {
$params[] = ":$i";
}
return implode(', ', $params);
}
/** @inheritDoc */
public function parameter($value)
{
return $this->isExpression($value) ? $this->getValue($value) : self::PARAMETER_SIGN;
}
/** @inheritDoc */
public function compileWheres(Builder $query)
{
return static::prepareParameters(parent::compileWheres($query));
}
const PARAMETER_SIGN = '?';
/**
* Second part of trick to change signs "?" to ":0", ":1" and so on
+1 -1
View File
@@ -23,7 +23,7 @@ class BindingsTest extends TestCase
public function testBindingsByTableMethod()
{
$query = DB::table('examples')
->where(function (Builder $q) {
->where(function ($q) {
$q->where('f_int', 1)
->orWhere('f_int', 2)
->orWhere('f_int', 3);