diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php index 8893fe26..c92f1ee3 100644 --- a/src/Dibi/Translator.php +++ b/src/Dibi/Translator.php @@ -137,22 +137,20 @@ final class Translator $arg = iterator_to_array($arg); } - if (is_array($arg)) { - if (is_string(key($arg))) { - // associative array -> autoselect between SET or VALUES & LIST - if ($commandIns === NULL) { - $commandIns = strtoupper(substr(ltrim($this->args[0]), 0, 6)); - $commandIns = $commandIns === 'INSERT' || $commandIns === 'REPLAC'; - $sql[] = $this->formatValue($arg, $commandIns ? 'v' : 'a'); - } else { - if ($lastArr === $cursor - 1) { - $sql[] = ','; - } - $sql[] = $this->formatValue($arg, $commandIns ? 'l' : 'a'); + if (is_array($arg) && is_string(key($arg))) { + // associative array -> autoselect between SET or VALUES & LIST + if ($commandIns === NULL) { + $commandIns = strtoupper(substr(ltrim($this->args[0]), 0, 6)); + $commandIns = $commandIns === 'INSERT' || $commandIns === 'REPLAC'; + $sql[] = $this->formatValue($arg, $commandIns ? 'v' : 'a'); + } else { + if ($lastArr === $cursor - 1) { + $sql[] = ','; } - $lastArr = $cursor; - continue; + $sql[] = $this->formatValue($arg, $commandIns ? 'l' : 'a'); } + $lastArr = $cursor; + continue; } // default processing diff --git a/tests/dibi/Translator.phpt b/tests/dibi/Translator.phpt index e6939da2..0c95d412 100644 --- a/tests/dibi/Translator.phpt +++ b/tests/dibi/Translator.phpt @@ -294,7 +294,8 @@ WHERE (`test`.`a` LIKE '1995-03-01' OR `b6` IN ('one', 'two', 'three') OR `b7` IN (NULL) OR `b8` IN (RAND() `col1` > `col2` ) - OR `b9` IN ( ) + OR `b9` IN (RAND(), [col1] > [col2] ) + OR `b10` IN ( ) AND `c` = 'embedded \' string' OR `d`=10 OR `e`=NULL @@ -314,7 +315,8 @@ WHERE ("test"."a" LIKE \'1995-03-01\' OR "b6" IN (\'one\', \'two\', \'three\') OR "b7" IN (NULL) OR "b8" IN (RAND() "col1" > "col2" ) - OR "b9" IN ( ) + OR "b9" IN (RAND(), [col1] > [col2] ) + OR "b10" IN ( ) AND "c" = \'embedded \'\' string\' OR "d"=10 OR "e"=NULL @@ -334,7 +336,8 @@ WHERE ([test].[a] LIKE #03/01/1995# OR [b6] IN ('one', 'two', 'three') OR [b7] IN (NULL) OR [b8] IN (RAND() [col1] > [col2] ) - OR [b9] IN ( ) + OR [b9] IN (RAND(), [col1] > [col2] ) + OR [b10] IN ( ) AND [c] = 'embedded '' string' OR [d]=10 OR [e]=NULL @@ -354,7 +357,8 @@ WHERE ([test].[a] LIKE '1995-03-01' OR [b6] IN ('one', 'two', 'three') OR [b7] IN (NULL) OR [b8] IN (RAND() [col1] > [col2] ) - OR [b9] IN ( ) + OR [b9] IN (RAND(), [col1] > [col2] ) + OR [b10] IN ( ) AND [c] = 'embedded '' string' OR [d]=10 OR [e]=NULL @@ -376,7 +380,8 @@ WHERE ([test.a] LIKE %d', '1995-03-01', ' OR [b6] IN %l', $array3, ' OR [b7] IN %in', [], ' OR [b8] IN (%sql', $array5, ') - OR [b9] IN (', [], ") + OR [b9] IN (%SQL', $array5, ') + OR [b10] IN (', [], ") AND [c] = 'embedded '' string' OR [d]=%i", 10.3, ' OR [e]=%i', NULL, ' @@ -509,6 +514,18 @@ Assert::same( ); +Assert::same( + reformat('SELECT * FROM table'), + $conn->translate('SELECT', new Dibi\Literal('* FROM table')) +); + + +Assert::same( + reformat('SELECT * FROM table'), + $conn->translate(new Dibi\Literal('SELECT * FROM table')) +); + + setLocale(LC_ALL, 'czech'); Assert::same(