Skip to content

Commit

Permalink
Translator: improved Expression usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 6, 2018
1 parent 20fdf45 commit d37eee2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Dibi/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ public function formatValue($value, $modifier)
if ($modifier) {
if ($value !== null && !is_scalar($value)) { // array is already processed
if ($value instanceof Literal && ($modifier === 'sql' || $modifier === 'SQL')) {
$modifier = 'SQL';
return (string) $value;

} elseif ($value instanceof Expression && $modifier === 'ex') {
return call_user_func_array([$this->connection, 'translate'], $value->getValues());

} elseif (($value instanceof \DateTime || $value instanceof \DateTimeInterface) && ($modifier === 'd' || $modifier === 't' || $modifier === 'dt')) {
// continue
} else {
Expand Down
12 changes: 12 additions & 0 deletions tests/dibi/Translator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,18 @@ Assert::same(
);


Assert::same(
reformat('SELECT * FROM [table] WHERE (([left] = 1) OR ([top] = 2)) AND (number < 100)'),
$conn->translate('SELECT * FROM `table` WHERE %and', [
new Dibi\Expression('%or', [
'left' => 1,
'top' => 2,
]),
new Dibi\Expression('number < %i', 100),
])
);


$e = Assert::exception(function () use ($conn) {
$array6 = [
'id' => [1, 2, 3, 4],
Expand Down

0 comments on commit d37eee2

Please sign in to comment.