Skip to content

Commit

Permalink
fix: modify replaceBindings logic to fit current laravel implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-lee-lb committed Jul 1, 2023
1 parent b7792f6 commit b51bc46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Objects/Concerns/ReplacesBindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function replaceBindings($sql, array $bindings)
$generalRegex = $this->getRegex();

foreach ($this->formatBindings($bindings) as $key => $binding) {
$regex = is_numeric($key) ? $generalRegex : $this->getNamedParameterRegex($key);
$regex = is_int($key) ? $generalRegex : $this->getNamedParameterRegex($key);
$sql = preg_replace($regex, $this->value($binding), $sql, 1);
}

Expand All @@ -43,7 +43,7 @@ protected function value($value)
return (int) $value;
}

return is_numeric($value) ? $value : "'" . $value . "'";
return is_int($value) ? $value : "'" . $value . "'";
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Objects/SqlQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function it_returns_valid_query_with_replaced_bindings()

$expectedSql = <<<EOF
SELECT * FROM tests WHERE a = '\'test' AND CONCAT('{$bindings[1]->toDateTimeString()}', '%'
, '{$bindings[2]->format('Y-m-d H:i:s')}') = 453 AND column = 67.23
, '{$bindings[2]->format('Y-m-d H:i:s')}') = 453 AND column = '67.23'
EOF;

$this->assertSame($expectedSql, $query->get());
Expand All @@ -72,7 +72,7 @@ public function it_returns_valid_query_with_replaced_bindings_for_immutable_date

$expectedSql = <<<EOF
SELECT * FROM tests WHERE a = '\'test' AND CONCAT('{$bindings[1]->toDateTimeString()}', '%'
, '{$bindings[2]->format('Y-m-d H:i:s')}') = 453 AND column = 67.23
, '{$bindings[2]->format('Y-m-d H:i:s')}') = 453 AND column = '67.23'
EOF;

$this->assertSame($expectedSql, $query->get());
Expand Down

0 comments on commit b51bc46

Please sign in to comment.