2 new revisions:

Revision: 3b4e2f99c5fd
Author:   paul cannon <[email protected]>
Date:     Sat Mar 24 12:56:27 2012
Log:      fix recognition of named params within 1 char...
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=3b4e2f99c5fd

Revision: 5ac6b7467053
Author:   paul cannon <[email protected]>
Date:     Sat Mar 24 13:09:16 2012
Log:      skip cql3 tests when not supported...
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=5ac6b7467053

==============================================================================
Revision: 3b4e2f99c5fd
Author:   paul cannon <[email protected]>
Date:     Sat Mar 24 12:56:27 2012
Log:      fix recognition of named params within 1 char

the regex matched the preceding and succeeding character, so two params
separated by only one character (like ':a,:b') were considered
overlapping, so the second was unmatched.

can't come up with something better and of similar simplicity without
doing a lookahead assertion, so I guess that's what we'll do.

also, fix tests to know that comments are no longer elided from queries
during prepare.

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

Modified:
 /cql/marshal.py
 /test/test_query_inline_prep.py

=======================================
--- /cql/marshal.py     Fri Mar 23 17:10:42 2012
+++ /cql/marshal.py     Sat Mar 24 12:56:27 2012
@@ -69,11 +69,11 @@
 stringlit_re = re.compile(r"""('[^']*'|"[^"]*")""")
comments_re = re.compile(r'(/\*(?:[^*]|\*[^/])*\*/|//.*$|--.*$)', re.MULTILINE)
 param_re = re.compile(r'''
- ( [^a-z0-9_] ) # don't match : at the beginning of the text (meaning it + ( \W ) # don't match : at the beginning of the text (meaning it
                       # immediately follows a comment or string literal) or
                       # right after an identifier character
-    : ( [a-z0-9_]+ )
- ( [^a-z0-9_] ) # and don't match a param that is immediately followed by
+    : ( \w+ )
+ (?= \W ) # and don't match a param that is immediately followed by
                       # a comment or string literal either
 ''', re.IGNORECASE | re.VERBOSE)

@@ -115,7 +115,7 @@
     """

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

 def prepare_query(querytext):
@@ -123,9 +123,8 @@
     def found_param(match):
         pre_param_text = match.group(1)
         paramname = match.group(2)
-        post_param_text = match.group(3)
         paramnames.append(paramname)
-        return pre_param_text + '?' + post_param_text
+        return pre_param_text + '?'
     transformed_query = replace_param_substitutions(querytext, found_param)
     return transformed_query, paramnames

=======================================
--- /test/test_query_inline_prep.py     Fri Feb 10 08:31:22 2012
+++ /test/test_query_inline_prep.py     Sat Mar 24 12:56:27 2012
@@ -76,7 +76,7 @@
 ':suffix;
 """,
 """
-SELECT ' '..':hi' FROM ColumnFamily WHERE KEY=':dontsubstthis' AND col
                   0.2;
+SELECT ' '..':hi' FROM ColumnFamily WHERE KEY=':dontsubstthis' AND col > /* ignore :this */ 0.2;
 """,
 """
 USE 'abc';

==============================================================================
Revision: 5ac6b7467053
Author:   paul cannon <[email protected]>
Date:     Sat Mar 24 13:09:16 2012
Log:      skip cql3 tests when not supported

fixes #16.

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

Modified:
 /test/test_prepared_queries.py

=======================================
--- /test/test_prepared_queries.py      Fri Feb 10 08:31:22 2012
+++ /test/test_prepared_queries.py      Sat Mar 24 13:09:16 2012
@@ -37,11 +37,19 @@
     dbconn = None

     def setUp(self):
- self.dbconn = cql.connect(TEST_HOST, TEST_PORT, cql_version=TEST_CQL_VERSION)
+        try:
+ self.dbconn = cql.connect(TEST_HOST, TEST_PORT, cql_version=TEST_CQL_VERSION)
+        except cql.cursor.TApplicationException:
+ # set_cql_version (and thus, cql3) not supported; skip all of these
+            self.cursor = None
+            return
+
         self.cursor = self.dbconn.cursor()
         self.keyspace = self.create_schema()

     def tearDown(self):
+        if self.cursor is None:
+            return
         try:
             self.cursor.execute("drop keyspace %s" % self.keyspace)
         except:
@@ -71,6 +79,9 @@
         return ksname

     def test_prepared_select(self):
+        if self.cursor is None:
+            return
+
q = self.cursor.prepare_query("select thekey, thedecimal, theblob from abc where thekey=:key")

         self.cursor.execute_prepared(q, {'key': '1999-12-31+0000'})
@@ -82,6 +93,9 @@
         self.assertEqual(results[2], '\x00\xff\x80\x08')

     def test_prepared_insert(self):
+        if self.cursor is None:
+            return
+
q = self.cursor.prepare_query("insert into abc (thekey, theint) values (:key, :ival)")

self.cursor.execute_prepared(q, {'key': '1991-10-05+0000', 'ival': 2})
@@ -95,6 +109,9 @@
         self.assertEqual(results[1], -200000)

     def test_prepared_update(self):
+        if self.cursor is None:
+            return
+
q = self.cursor.prepare_query("update abc set theblob=:myblob where thekey = :mykey")

self.cursor.execute_prepared(q, {'mykey': '2305-07-13+0000', 'myblob': '\0foo\0'})
@@ -108,6 +125,9 @@
         self.assertEqual(results[1], '')

     def test_prepared_increment(self):
+        if self.cursor is None:
+            return
+
q = self.cursor.prepare_query("update counterito set feet=feet + :inc where id = :id and name = 'krang'")

         self.cursor.execute_prepared(q, {'inc': 12, 'id': 1})
@@ -121,6 +141,9 @@
         self.assertEqual(results[1], 8)

     def test_prepared_decrement(self):
+        if self.cursor is None:
+            return
+
q = self.cursor.prepare_query("update counterito set feet=feet - :inc where id = :id and name = 'krang'")

         self.cursor.execute_prepared(q, {'inc': -100, 'id': 2})

Reply via email to