address the empty-query case
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 22 Apr 2011 21:34:56 +0000 (21:34 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 22 Apr 2011 21:34:56 +0000 (21:34 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@20295 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/QueryParser.pm

index 1915424..b858fd5 100644 (file)
@@ -585,6 +585,13 @@ sub toSQL {
 
     my $core_limit = $self->QueryParser->core_limit || 25000;
 
+    my $flat_where = $$flat_plan{where};
+    if ($flat_where eq '()') {
+        $flat_where = '';
+    } else {
+        $flat_where = "AND $flat_where";
+    }
+
     my $sql = <<SQL;
 SELECT  $key AS id,
         ARRAY_ACCUM(DISTINCT m.source) AS records,
@@ -600,7 +607,7 @@ SELECT  $key AS id,
         $during
         $between
         $combined_dyn_filters
-        AND $$flat_plan{where}
+        $flat_where
   GROUP BY 1
   ORDER BY 4 $desc NULLS LAST, 5 DESC NULLS LAST, 3 DESC
   LIMIT $core_limit
index 479bd40..1b3a37f 100644 (file)
@@ -685,7 +685,7 @@ sub decompose {
 
     }
 
-    $struct = undef if (scalar(@{$struct->query_nodes}) == 0);
+    $struct = undef if (scalar(@{$struct->query_nodes}) == 0 && !$struct->top_plan);
 
     return $struct if !wantarray;
     return ($struct, $remainder);