1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-01 11:50:15 +02:00

Translator: improved Expression usage

This commit is contained in:
David Grudl
2018-04-06 02:56:22 +02:00
parent ccc035c8fb
commit cf0129a194
2 changed files with 17 additions and 1 deletions

View File

@@ -316,7 +316,11 @@ final class Translator
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 $this->connection->translate(...$value->getValues());
} elseif ($value instanceof \DateTimeInterface && ($modifier === 'd' || $modifier === 't' || $modifier === 'dt')) {
// continue
} else {

View File

@@ -507,6 +507,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],