cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cassandra-dbapi2.apache-extras....@codespot.com
Subject [cassandra-dbapi2] push by alek...@yeschenko.com - Fix CQL3+boolean quoting on 2013-05-31 02:48 GMT
Date Fri, 31 May 2013 02:48:17 GMT
Revision: 38ed5babd818
Author:   Aleksey Yeschenko <aleksey@yeschenko.com>
Date:     Thu May 30 19:47:46 2013
Log:      Fix CQL3+boolean quoting

http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=38ed5babd818

Modified:
  /cql/cursor.py
  /cql/query.py

=======================================
--- /cql/cursor.py	Thu Oct 18 16:19:52 2012
+++ /cql/cursor.py	Thu May 30 19:47:46 2013
@@ -64,7 +64,7 @@

      def prepare_inline(self, query, params):
          try:
-            return prepare_inline(query, params)
+            return prepare_inline(query, params, self.cql_major_version)
          except KeyError, e:
              raise cql.ProgrammingError("Unmatched named substitution: " +
                                         "%s not given for %r" % (e, query))
=======================================
--- /cql/query.py	Sun Aug 19 13:16:40 2012
+++ /cql/query.py	Thu May 30 19:47:46 2013
@@ -59,7 +59,7 @@
      def encode_params(self, params):
          return [t.to_binary(t.validate(params[n])) for (n, t) in  
zip(self.paramnames, self.vartypes)]

-def prepare_inline(query, params):
+def prepare_inline(query, params, cql_major_version=3):
      """
      For every match of the form ":param_name", call cql_quote
      on kwargs['param_name'] and replace that section of the query
@@ -67,7 +67,7 @@
      """

      def param_replacer(match):
-        return match.group(1) + cql_quote(params[match.group(2)])
+        return match.group(1) + cql_quote(params[match.group(2)],  
cql_major_version)
      return replace_param_substitutions(query, param_replacer)

  def prepare_query(querytext):
@@ -80,11 +80,13 @@
      transformed_query = replace_param_substitutions(querytext, found_param)
      return transformed_query, paramnames

-def cql_quote(term):
+def cql_quote(term, cql_major_version=3):
      if isinstance(term, unicode):
          return "'%s'" % __escape_quotes(term.encode('utf8'))
-    elif isinstance(term, (str, bool)):
+    elif isinstance(term, str):
          return "'%s'" % __escape_quotes(str(term))
+    elif isinstance(term, bool) and cql_major_version == 2:
+        return "'%s'" % str(term)
      else:
          return str(term)


Mime
View raw message