Skip to content

Commit

Permalink
Clean up formatting for Travis CI build error messages, try #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcculley committed Feb 3, 2015
1 parent fb6fd90 commit 6001b8f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion libraries/joomla/database/query/sqlsrv.php
Expand Up @@ -373,8 +373,10 @@ public function group($columns)
{
// Transform $columns into an array for filtering purposes
$columns = explode(",", str_replace(" ", "", $columns));

// Get the _formatted_ FROM string and remove everything except `table AS alias`
$fromStr = str_replace(array("[","]"), "", str_replace("#__", $this->db->getPrefix(), str_replace("FROM ", "", (string) $this->from)));

// Start setting up an array of alias => table
list($table, $alias) = preg_split("/\sAS\s/i", $fromStr);
$tmpCols = $this->db->getTableColumns(trim($table));
Expand All @@ -383,6 +385,7 @@ public function group($columns)
{
$cols[] = $alias . "." . $name;
}

// Now we need to get all tables from any joins
// Go through all joins and add them to the tables array
$joins = array();
Expand All @@ -397,15 +400,20 @@ public function group($columns)
}
}

$selectStr = str_replace("SELECT ", "", (string)$this->select);
$selectStr = str_replace("SELECT ", "", (string) $this->select);

// Remove any functions (e.g. COUNT(), SUM(), CONCAT())
$selectCols = preg_replace("/([^,]*\([^\)]*\)[^,]*,?)/", "", $selectStr);

// Remove any "as alias" statements
$selectCols = preg_replace("/(\sas\s[^,]*)/i", "", $selectCols);

// Remove any extra commas
$selectCols = preg_replace("/,{2,}/", ",", $selectCols);

// Remove any trailing commas and all whitespaces
$selectCols = trim(str_replace(" ", "", preg_replace("/,?$/", "", $selectCols)));

// Get an array to compare against
$selectCols = explode(",", $selectCols);

Expand All @@ -414,15 +422,19 @@ public function group($columns)
{
if (preg_match("/.+\*/", $aliasColName, $match))
{

// Grab the table alias minus the .*
$aliasStar = preg_replace("/(.+)\.\*/", "$1", $aliasColName);

// Unset the array key
unset($selectCols[$key]);

// Get the table name
$tableColumns = preg_grep("/{$aliasStar}\.+/", $cols);
$columns = array_merge($columns, $tableColumns);
}
}

// Finally, get a unique string of all column names that need to be included in the group statement
$columns = array_unique(array_merge($columns, $selectCols));
$columns = implode(",", $columns);
Expand Down

0 comments on commit 6001b8f

Please sign in to comment.