diff --git a/src/Sql/AbstractSql.php b/src/Sql/AbstractSql.php index 1c5c8b6383..a014a32a3d 100644 --- a/src/Sql/AbstractSql.php +++ b/src/Sql/AbstractSql.php @@ -14,6 +14,7 @@ use Zend\Db\Adapter\Platform\PlatformInterface; use Zend\Db\Sql\Platform\PlatformDecoratorInterface; use Zend\Db\Adapter\Platform\Sql92 as DefaultAdapterPlatform; +use Zend\Db\Exception\RuntimeException; abstract class AbstractSql implements SqlInterface { @@ -405,9 +406,31 @@ protected function resolveColumnValue( if ($column === null) { return 'NULL'; } - return $isIdentifier - ? $fromTable . $platform->quoteIdentifierInFragment($column) - : $platform->quoteValue($column); + + if ($isIdentifier) { + $matches = []; + preg_match( + '#(?:(?[^\s].*?)\.(?=\S)){0,1}(?:(?\.{0,1}\*(?=\s*$))|(?[^\s].*?)(?:\s*$|(?:\s+as\s+(?.*(?:\S)))))#i', + $column, + $matches + ); + if (!empty($matches['table'])) { + $fromTable = $platform->quoteIdentifier($matches['table']) . $platform->getIdentifierSeparator(); + } + if (Select::SQL_STAR === $matches['star']) { + return $fromTable . Select::SQL_STAR; + } + if (array_key_exists('column', $matches) && !empty($matches['column'])) { + $column = $platform->quoteIdentifier($matches['column']); + if (array_key_exists('alias', $matches)) { + $column .= ' AS ' . $platform->quoteIdentifier($matches['alias']); + } + return $fromTable . $column; + } + throw new RuntimeException('Invalid column name'); + } + + return $platform->quoteValue($column); } /**