1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-04 13:17:58 +02:00

added test, whitespace

This commit is contained in:
David Grudl
2015-11-02 15:10:13 +01:00
parent f2a400084f
commit 654e345921
2 changed files with 34 additions and 19 deletions

View File

@@ -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

View File

@@ -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(