Skip to content

Commit

Permalink
Quote aliased field names.
Browse files Browse the repository at this point in the history
Aliased fields need to be quoted for postgres to properly return the
names in the result sets. Without quoting names are returned as
lowercase version. An alternative workaround would be to snake_case
aliases and inflect them back when building results.
  • Loading branch information
markstory committed Jun 28, 2013
1 parent be1c45d commit 0ebfd4e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Cake/Database/Query.php
Expand Up @@ -410,12 +410,13 @@ public function distinct($on = [], $overwrite = false) {
* @return string
*/
protected function _buildSelectPart($parts) {
$driver = $this->_connection->driver();
$select = 'SELECT %s%s';
$distinct = null;
$normalized = [];
foreach ($parts as $k => $p) {
if (!is_numeric($k)) {
$p = $p . ' AS ' . $k;
$p = $p . ' AS ' . $driver->quoteIdentifier($k);
}
$normalized[] = $p;
}
Expand Down

0 comments on commit 0ebfd4e

Please sign in to comment.