From 14a5879c88497c05db452e52bc5ebe876368194f Mon Sep 17 00:00:00 2001
From: Ryan Williams <rdw@lindenlab.com>
Date: Tue, 9 Dec 2008 22:41:28 +0000
Subject: [PATCH] svn merge -r104949:105037
 svn+ssh://svn.lindenlab.com/svn/linden/branches/rad-chilies/rad-chilies-06-release-merge
 QAR-1048: Distributed L$ Transactions > Rad Chilies 06 Indra items

---
 indra/lib/python/indra/util/named_query.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/indra/lib/python/indra/util/named_query.py b/indra/lib/python/indra/util/named_query.py
index e1f1ad2002e..bb27730e9fa 100644
--- a/indra/lib/python/indra/util/named_query.py
+++ b/indra/lib/python/indra/util/named_query.py
@@ -47,6 +47,8 @@
 from indra.base import llsd
 from indra.base import config
 
+DEBUG = False
+
 NQ_FILE_SUFFIX = config.get('named-query-file-suffix', '.nq')
 NQ_FILE_SUFFIX_LEN  = len(NQ_FILE_SUFFIX)
 
@@ -63,7 +65,9 @@ def _init_g_named_manager(sql_dir = None):
 
     # extra fallback directory in case config doesn't return what we want
     if sql_dir is None:
-        sql_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "web", "dataservice", "sql")
+        sql_dir = os.path.abspath(
+            os.path.join(
+            os.path.realpath(os.path.dirname(__file__)), "..", "..", "..", "..", "web", "dataservice", "sql"))
 
     global _g_named_manager
     _g_named_manager = NamedQueryManager(
@@ -188,6 +192,16 @@ def _convert_sql(self, sql):
         ready them for use in LIKE statements"""
         if sql:
             #print >>sys.stderr, "sql:",sql
+            
+            # This first sub is to properly escape any % signs that
+            # are meant to be literally passed through to mysql in the
+            # query.  It leaves any %'s that are used for
+            # like-expressions.
+            expr = re.compile("(?<=[^a-zA-Z0-9_-])%(?=[^:])")
+            sql = expr.sub('%%', sql)
+
+            # This should tackle the rest of the %'s in the query, by
+            # converting them to LIKE clauses.
             expr = re.compile("(%?):([a-zA-Z][a-zA-Z0-9_-]*)%")
             sql = expr.sub(self._prepare_like, sql)
             expr = re.compile("#:([a-zA-Z][a-zA-Z0-9_-]*)")
@@ -339,7 +353,8 @@ def run(self, connection, params, expect_rows = None, use_dictcursor = True):
             cursor = connection.cursor()
         
         statement = self.sql(connection, params)
-        #print "SQL:", statement
+        if DEBUG:
+            print "SQL:", statement
         rows = cursor.execute(statement)
         
         # *NOTE: the expect_rows argument is a very cheesy way to get some
-- 
GitLab