Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '3.1/develop' into 3.2/develop

  • Loading branch information...
commit a261eb9adc30e7adf9beb398d01b5d8625905c5d 2 parents 06aacea + 9ef34f4
@cbandy cbandy authored
View
55 classes/kohana/database/query/builder.php
@@ -118,8 +118,16 @@ protected function _compile_conditions(Database $db, array $conditions)
if ($column)
{
- // Apply proper quoting to the column
- $column = $db->quote_column($column);
+ if (is_array($column))
+ {
+ // Use the column alias
+ $column = $db->quote_identifier(end($column));
+ }
+ else
+ {
+ // Apply proper quoting to the column
+ $column = $db->quote_column($column);
+ }
}
// Append the statement to the query
@@ -164,6 +172,36 @@ protected function _compile_set(Database $db, array $values)
}
/**
+ * Compiles an array of GROUP BY columns into an SQL partial.
+ *
+ * @param object Database instance
+ * @param array columns
+ * @return string
+ */
+ protected function _compile_group_by(Database $db, array $columns)
+ {
+ $group = array();
+
+ foreach ($columns as $column)
+ {
+ if (is_array($column))
+ {
+ // Use the column alias
+ $column = $db->quote_identifier(end($column));
+ }
+ else
+ {
+ // Apply proper quoting to the column
+ $column = $db->quote_column($column);
+ }
+
+ $group[] = $column;
+ }
+
+ return 'GROUP BY '.implode(', ', $group);
+ }
+
+ /**
* Compiles an array of ORDER BY statements into an SQL partial.
*
* @param object Database instance
@@ -177,13 +215,24 @@ protected function _compile_order_by(Database $db, array $columns)
{
list ($column, $direction) = $group;
+ if (is_array($column))
+ {
+ // Use the column alias
+ $column = $db->quote_identifier(end($column));
+ }
+ else
+ {
+ // Apply proper quoting to the column
+ $column = $db->quote_column($column);
+ }
+
if ($direction)
{
// Make the direction uppercase
$direction = ' '.strtoupper($direction);
}
- $sort[] = $db->quote_column($column).$direction;
+ $sort[] = $column.$direction;
}
return 'ORDER BY '.implode(', ', $sort);
View
4 classes/kohana/database/query/builder/select.php
@@ -372,8 +372,8 @@ public function compile(Database $db)
if ( ! empty($this->_group_by))
{
- // Add sorting
- $query .= ' GROUP BY '.implode(', ', array_map($quote_column, $this->_group_by));
+ // Add grouping
+ $query .= ' '.$this->_compile_group_by($db, $this->_group_by);
}
if ( ! empty($this->_having))
Please sign in to comment.
Something went wrong with that request. Please try again.