1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 05:37:39 +02:00

Translator: Literal can be used with %sql or %SQL modifiers

This commit is contained in:
David Grudl
2015-11-02 16:55:14 +01:00
parent a9a45f0c4c
commit b7d922d992
2 changed files with 13 additions and 3 deletions

View File

@@ -330,10 +330,16 @@ final class Translator
// with modifier procession
if ($modifier) {
if ($value !== NULL && !is_scalar($value) && !$value instanceof \DateTime && !$value instanceof \DateTimeInterface) { // array is already processed
if ($value !== NULL && !is_scalar($value)) { // array is already processed
if ($value instanceof Literal && ($modifier === 'sql' || $modifier === 'SQL')) {
$modifier = 'SQL';
} elseif ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
// continue
} else {
$type = is_object($value) ? get_class($value) : gettype($value);
return $this->errors[] = "**Invalid combination of type $type and modifier %$modifier**";
}
}
switch ($modifier) {
case 's': // string

View File

@@ -519,6 +519,10 @@ Assert::same(
$conn->translate('SELECT', new Dibi\Literal('* FROM table'))
);
Assert::same(
reformat('SELECT * FROM table'),
$conn->translate('SELECT %SQL', new Dibi\Literal('* FROM table'))
);
Assert::same(
reformat('SELECT * FROM table'),