diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index a491d581..d6f48417 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -181,7 +181,7 @@ class Fluent implements IDataSource return $this; } elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier - $args = ['%n', $arg]; + $args = [$clause === 'AS' ? '%N' : '%n', $arg]; } elseif (is_array($arg) || ($arg instanceof \Traversable && !$arg instanceof self)) { // any array if (isset(self::$modifiers[$clause])) { diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php index 4986fe6c..3ea61163 100644 --- a/src/Dibi/Translator.php +++ b/src/Dibi/Translator.php @@ -225,7 +225,7 @@ final class Translator case 'n': // key, key, ... identifier names foreach ($value as $k => $v) { if (is_string($k)) { - $vx[] = $this->identifiers->$k . (empty($v) ? '' : ' AS ' . $this->identifiers->$v); + $vx[] = $this->identifiers->$k . (empty($v) ? '' : ' AS ' . $this->driver->escapeIdentifier($v)); } else { $pair = explode('%', $v, 2); // split into identifier & modifier $vx[] = $this->identifiers->{$pair[0]}; diff --git a/tests/dibi/Fluent.select.phpt b/tests/dibi/Fluent.select.phpt index 0d957962..45a85eca 100644 --- a/tests/dibi/Fluent.select.phpt +++ b/tests/dibi/Fluent.select.phpt @@ -26,19 +26,19 @@ Assert::same( (string) $fluent ); -$fluent->from('table')->as('tableAlias') +$fluent->from('table')->as('table.Alias') ->innerJoin('table1')->on('table.col = table1.col') ->innerJoin('table2')->on('table.col = table2.col'); Assert::same( - reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [table] AS [tableAlias] INNER JOIN [table1] ON table.col = table1.col INNER JOIN [table2] ON table.col = table2.col'), + reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [table] AS [table.Alias] INNER JOIN [table1] ON table.col = table1.col INNER JOIN [table2] ON table.col = table2.col'), (string) $fluent ); $fluent->from('anotherTable'); Assert::same( - reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [table] AS [tableAlias] INNER JOIN [table1] ON table.col = table1.col INNER JOIN [table2] ON table.col = table2.col , [anotherTable]'), + reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [table] AS [table.Alias] INNER JOIN [table1] ON table.col = table1.col INNER JOIN [table2] ON table.col = table2.col , [anotherTable]'), (string) $fluent ); diff --git a/tests/dibi/Translator.phpt b/tests/dibi/Translator.phpt index c616a5c5..5f760125 100644 --- a/tests/dibi/Translator.phpt +++ b/tests/dibi/Translator.phpt @@ -280,7 +280,7 @@ $array2 = ['one', 'two', 'three']; $array3 = [ 'col1' => 'one', 'col2' => 'two', - 'col3' => 'three', + 'col3' => 'thr.ee', ]; $array4 = [ 'a' => 12, @@ -301,8 +301,8 @@ WHERE (`test`.`a` LIKE '1995-03-01' OR `b2` IN ('1', '2', '3' ) OR `b3` IN ( ) OR `b4` IN ( 'one', 'two', 'three' ) - OR `b5` IN (`col1` AS `one`, `col2` AS `two`, `col3` AS `three` ) - OR `b6` IN ('one', 'two', 'three') + OR `b5` IN (`col1` AS `one`, `col2` AS `two`, `col3` AS `thr.ee` ) + OR `b6` IN ('one', 'two', 'thr.ee') OR `b7` IN (NULL) OR `b8` IN (RAND() `col1` > `col2` ) OR `b9` IN (RAND(), [col1] > [col2] ) @@ -322,8 +322,8 @@ WHERE ("test"."a" LIKE \'1995-03-01\' OR "b2" IN (\'1\', \'2\', \'3\' ) OR "b3" IN ( ) OR "b4" IN ( \'one\', \'two\', \'three\' ) - OR "b5" IN ("col1" AS "one", "col2" AS "two", "col3" AS "three" ) - OR "b6" IN (\'one\', \'two\', \'three\') + OR "b5" IN ("col1" AS "one", "col2" AS "two", "col3" AS "thr.ee" ) + OR "b6" IN (\'one\', \'two\', \'thr.ee\') OR "b7" IN (NULL) OR "b8" IN (RAND() "col1" > "col2" ) OR "b9" IN (RAND(), [col1] > [col2] ) @@ -343,8 +343,8 @@ WHERE ([test].[a] LIKE #03/01/1995# OR [b2] IN ('1', '2', '3' ) OR [b3] IN ( ) OR [b4] IN ( 'one', 'two', 'three' ) - OR [b5] IN ([col1] AS [one], [col2] AS [two], [col3] AS [three] ) - OR [b6] IN ('one', 'two', 'three') + OR [b5] IN ([col1] AS [one], [col2] AS [two], [col3] AS [thr.ee] ) + OR [b6] IN ('one', 'two', 'thr.ee') OR [b7] IN (NULL) OR [b8] IN (RAND() [col1] > [col2] ) OR [b9] IN (RAND(), [col1] > [col2] ) @@ -364,8 +364,8 @@ WHERE ([test].[a] LIKE '1995-03-01' OR [b2] IN ('1', '2', '3' ) OR [b3] IN ( ) OR [b4] IN ( 'one', 'two', 'three' ) - OR [b5] IN ([col1] AS [one], [col2] AS [two], [col3] AS [three] ) - OR [b6] IN ('one', 'two', 'three') + OR [b5] IN ([col1] AS [one], [col2] AS [two], [col3] AS [thr.ee] ) + OR [b6] IN ('one', 'two', 'thr.ee') OR [b7] IN (NULL) OR [b8] IN (RAND() [col1] > [col2] ) OR [b9] IN (RAND(), [col1] > [col2] )