From af34e9435cab57ec92072d540ff9c53b651ab491 Mon Sep 17 00:00:00 2001
From: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Date: Tue, 2 Aug 2011 17:34:10 -0400
Subject: [PATCH] Fixed some syntax errors, but getting no results when I'd
 expect some

I searched with this

    container(bre,bookbag,12,$authtoken)

where $authtoken is substituted with an actual live authtoken for the
user that owns that container, and here is the example generated query
that returns no results:

  SELECT * FROM  search.query_parser_fts(
            4::INT,
            2::INT,
            $core_query_3553$SELECT  m.source AS id,
ARRAY_ACCUM(DISTINCT m.source) AS records,
1.0/((AVG(
        (1)
) * COALESCE( NULLIF( FIRST(mrd.attrs @> hstore('item_lang', $_3553$eng$_3553$)), FALSE )::INT * 5, 1)))::NUMERIC AS rel,
1.0/((AVG(
        (1)
) * COALESCE( NULLIF( FIRST(mrd.attrs @> hstore('item_lang', $_3553$eng$_3553$)), FALSE )::INT * 5, 1)))::NUMERIC AS rank,
FIRST(mrd.attrs->'date1') AS tie_break
FROM  metabib.metarecord_source_map m
JOIN metabib.record_attr mrd ON (m.source = mrd.id)

JOIN ( SELECT ci.target_biblio_record_entry AS container_item
        FROM  container.biblio_record_entry_bucket_item ci
              JOIN container.biblio_record_entry_bucket c ON (c.id = ci.bucket)

        WHERE c.btype = $_3553$bookbag$_3553$ AND c.id = 12
              AND (c.pub IS TRUE OR c.owner = 1)) container ON (container.container_item = mrd.id)

WHERE 1=1

AND (TRUE)
GROUP BY 1
ORDER BY 4 ASC NULLS LAST, 5 DESC NULLS LAST, 3 DESC
LIMIT 10000
$core_query_3553$::TEXT,
            $${}$$::INT[],
            $${}$$::INT[],
            NULL::INT,
            1000::INT,
            10000::INT,
            'f'::BOOL,
            't'::BOOL
        );

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
---
 .../lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm  | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
index b57870e8b0..d10016d5c9 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
@@ -621,16 +621,15 @@ sub toSQL {
             my ($u,$e) = $apputils->checksesperm($token) if ($token);
             $perm_join = 'OR c.owner = ' . $u->id if ($u && !$e);
 
-            $container = <<"            SQL";
+            $container = qq<
         JOIN ( SELECT $rec_field AS container_item
                 FROM  container.${class}_bucket_item ci
                       JOIN container.${class}_bucket c ON (c.id = ci.bucket)
                       $rec_join
-                WHERE c.btype = $ctype
-                      AND c.id = $cid
-                      AND (c.pub IS TRUE $perm_join)) container ON ON (container.container_item = mrd.id)
-            SQL
-
+                WHERE c.btype = > . $self->QueryParser->quote_value($ctype) .
+                    qq< AND c.id = $cid
+                      AND (c.pub IS TRUE $perm_join)) container ON (container.container_item = mrd.id)
+            >;
         } else {$container = ''};
     } else {
         $container = '';
-- 
2.11.0