Commit 3da85699 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 582209: Bugzilla::DB::Oracle::adjust_statement() LIMIT code corrupts sub-selects

r/a=mkanat
parent d9a39044
...@@ -379,20 +379,17 @@ sub adjust_statement { ...@@ -379,20 +379,17 @@ sub adjust_statement {
if ($new_sql !~ /\bWHERE\b/) { if ($new_sql !~ /\bWHERE\b/) {
$new_sql = $new_sql." WHERE 1=1"; $new_sql = $new_sql." WHERE 1=1";
} }
my ($before_where, $after_where) = split /\bWHERE\b/i,$new_sql; my ($before_where, $after_where) = split(/\bWHERE\b/i, $new_sql, 2);
if (defined($offset)) { if (defined($offset)) {
if ($new_sql =~ /(.*\s+)FROM(\s+.*)/i) { my ($before_from, $after_from) = split(/\bFROM\b/i, $new_sql, 2);
my ($before_from,$after_from) = ($1,$2); $before_where = "$before_from FROM ($before_from,"
$before_where = "$before_from FROM ($before_from," . " ROW_NUMBER() OVER (ORDER BY 1) R "
. " ROW_NUMBER() OVER (ORDER BY 1) R " . " FROM $after_from ) ";
. " FROM $after_from ) "; $after_where = " R BETWEEN $offset+1 AND $limit+$offset";
$after_where = " R BETWEEN $offset+1 AND $limit+$offset"; } else {
} $after_where = " rownum <=$limit AND ".$after_where;
} else { }
$after_where = " rownum <=$limit AND ".$after_where; $new_sql = $before_where." WHERE ".$after_where;
}
$new_sql = $before_where." WHERE ".$after_where;
} }
return $new_sql; return $new_sql;
} }
......
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