Commit 75048b21 authored by flip111's avatar flip111

Made cleaner code and remove unneccessary checks.

1. combine the regexes into one. The only thing that needs to be captured
is the alias. Used a non-capturing group for "AS " to avoid confusion and
have cleaner regex. It tries to match "Table.Column Alias" or
"Table.Column AS Alias". (line 861)
2. No fallback on line 865 like "$column['table'] . '.' .
$column['column']" this wouldn't make sense as this can not be possible
when it's a wrapped query. Better not insert some random SQL that's gonna
confuse the hell out of everybody.
3. Removed "($column['hasTable'] ? $column['table']  . '.' : '') .
$column['column']" because the original regex always tries to match the
table name. Therefor hasTable will always be true or the entire function
fails anyway. (this references line 868 now) (this was unit tested on
mysql, postgresql and sql server and did not increase errors/failures)
parent 572398c2
......@@ -852,24 +852,20 @@ class SQLServerPlatform extends AbstractPlatform
}
}
if (preg_match('/SELECT DISTINCT .* FROM \(.*\) dctrn_result/', $query)) {
$isWrapped = true;
} else {
$isWrapped = false;
}
$isWrapped = (preg_match('/SELECT DISTINCT .* FROM \(.*\) dctrn_result/', $query)) ? true : false;
//Find alias for each colum used in ORDER BY
if ( ! empty($orderbyColumns)) {
foreach ($orderbyColumns as $column) {
$pattern = sprintf('/%s\.%s\s+(?:AS\s+)?([^,\s)]+)/i', $column['table'], $column['column']);
if ($isWrapped) {
$pattern = sprintf('/%s\.%s\s+(AS\s+)?([^,\s\)]+)/i', $column['table'], $column['column']);
$overColumn = preg_match($pattern, $query, $matches) ? $matches[2] : $column['column'];
$overColumn = preg_match($pattern, $query, $matches)
? $matches[1] : '';
} else {
$pattern = sprintf('/%s\.(%s)\s*(AS)?\s*([^,\s\)]*)/i', $column['table'], $column['column']);
$overColumn = preg_match($pattern, $query, $matches)
? ($column['hasTable'] ? $column['table'] . '.' : '') . $column['column']
: $column['column'];
? $column['table'] . '.' . $column['column'] : '';
}
if (isset($column['sort'])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment