Skip to content

Commit

Permalink
Added negative lookahead
Browse files Browse the repository at this point in the history
It is possible to have multiple occurrences of 'as' in a field name.
Use the last occurrence of 'as' when extracting field name.

Tested with following examples:
"WeldCheck"."weld_id"
count(*) as WeldCheck__num_measurements
count(case decision when 2 then 1 else null end) as
WeldCheck__num_failures
avg(cast (WeldMeasurement.surface_indentation as bigint)) as
WeldCheck__avg_indentation
avg(cast (WeldMeasurement.circle_diameter as bigint)) as
WeldCheck__avg_diameter
  • Loading branch information
larryb82 authored and markstory committed Jun 26, 2015
1 parent ae2ea1e commit 0b28c2e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -323,7 +323,7 @@ public function resultSet($results) {
$j++;
continue;
}
if (preg_match('/\bAS\s+(.*)/i', $selects[$j], $matches)) {
if (preg_match('/\bAS(?!.*\bAS\b)\s+(.*)/i', $selects[$j], $matches)) {
$columnName = trim($matches[1], '"');
} else {
$columnName = trim(str_replace('"', '', $selects[$j]));
Expand Down

0 comments on commit 0b28c2e

Please sign in to comment.