mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 21:28:02 +02:00
added test, whitespace
This commit is contained in:
@@ -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
|
||||
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user