Author: eevans
Date: Thu Mar 17 19:40:46 2011
New Revision: 1082660
URL: http://svn.apache.org/viewvc?rev=1082660&view=rev
Log:
escape single quotes in strings
Patch by eevans
Modified:
cassandra/trunk/drivers/py/cql/marshal.py
cassandra/trunk/drivers/py/test/test_query_preparation.py
Modified: cassandra/trunk/drivers/py/cql/marshal.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/drivers/py/cql/marshal.py?rev=1082660&r1=1082659&r2=1082660&view=diff
==============================================================================
--- cassandra/trunk/drivers/py/cql/marshal.py (original)
+++ cassandra/trunk/drivers/py/cql/marshal.py Thu Mar 17 19:40:46 2011
@@ -49,17 +49,17 @@ def marshal(term):
if isinstance(term, (long,int)):
return "%d" % term
elif isinstance(term, unicode):
- return "'%s'" % term.encode('utf8')
+ return "'%s'" % __escape_quotes(term.encode('utf8'))
elif isinstance(term, str):
- return "'%s'" % term
+ return "'%s'" % __escape_quotes(term)
elif isinstance(term, UUID):
if term.version == 1:
return "timeuuid(\"%s\")" % str(term)
else:
return str(term)
else:
- return str(term)
-
+ return str(term)
+
def unmarshal(bytestr, typestr):
if typestr == "org.apache.cassandra.db.marshal.BytesType":
return bytestr
@@ -84,3 +84,6 @@ def decode_bigint(term):
val = val - (1 << (len(term) * 8))
return val
+def __escape_quotes(term):
+ assert isinstance(term, (str, unicode))
+ return term.replace("\'", "''")
Modified: cassandra/trunk/drivers/py/test/test_query_preparation.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/drivers/py/test/test_query_preparation.py?rev=1082660&r1=1082659&r2=1082660&view=diff
==============================================================================
--- cassandra/trunk/drivers/py/test/test_query_preparation.py (original)
+++ cassandra/trunk/drivers/py/test/test_query_preparation.py Thu Mar 17
19:40:46 2011
@@ -11,11 +11,15 @@ SELECT ?,?,?,? FROM ColumnFamily WHERE K
"""
USE Keyspace;
""",
+"""
+SELECT ?..? FROM ColumnFamily;
+""",
)
ARGUMENTS = (
(1, 3, long(1000), long(3000), "key", unicode("val")),
tuple(),
+ ("a'b", "c'd'e"),
)
STANDARDS = (
@@ -25,6 +29,9 @@ SELECT 1,3,1000,3000 FROM ColumnFamily W
"""
USE Keyspace;
""",
+"""
+SELECT 'a''b'..'c''d''e' FROM ColumnFamily;
+""",
)
class TestPrepare(unittest.TestCase):