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:
@@ -330,9 +330,15 @@ final class Translator
|
||||
|
||||
// with modifier procession
|
||||
if ($modifier) {
|
||||
if ($value !== NULL && !is_scalar($value) && !$value instanceof \DateTime && !$value instanceof \DateTimeInterface) { // array is already processed
|
||||
$type = is_object($value) ? get_class($value) : gettype($value);
|
||||
return $this->errors[] = "**Invalid combination of type $type and modifier %$modifier**";
|
||||
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) {
|
||||
|
@@ -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'),
|
||||
|
Reference in New Issue
Block a user