mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 06:07:39 +02:00
Translator: Literal can be used with %sql or %SQL modifiers
This commit is contained in:
@@ -330,10 +330,16 @@ final class Translator
|
|||||||
|
|
||||||
// with modifier procession
|
// with modifier procession
|
||||||
if ($modifier) {
|
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);
|
$type = is_object($value) ? get_class($value) : gettype($value);
|
||||||
return $this->errors[] = "**Invalid combination of type $type and modifier %$modifier**";
|
return $this->errors[] = "**Invalid combination of type $type and modifier %$modifier**";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch ($modifier) {
|
switch ($modifier) {
|
||||||
case 's': // string
|
case 's': // string
|
||||||
|
@@ -519,6 +519,10 @@ Assert::same(
|
|||||||
$conn->translate('SELECT', new Dibi\Literal('* FROM table'))
|
$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(
|
Assert::same(
|
||||||
reformat('SELECT * FROM table'),
|
reformat('SELECT * FROM table'),
|
||||||
|
Reference in New Issue
Block a user