Skip to content
Permalink
Browse files

Added negative lookahead

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 24, 2015
1 parent ae2ea1e commit 0b28c2e83959cb6066cca772d9878facd7328947
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/Cake/Model/Datasource/Database/Sqlite.php
@@ -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]));

0 comments on commit 0b28c2e

Please sign in to comment.
You can’t perform that action at this time.