Add explicit support for varchar

Fixes PYTHON-40
This commit is contained in:
Tyler Hobbs
2013-12-19 10:41:27 -06:00
parent 2766377dfa
commit b090b555f5
2 changed files with 13 additions and 6 deletions

View File

@@ -510,6 +510,10 @@ class UTF8Type(_CassandraType):
return ustr.encode('utf8') return ustr.encode('utf8')
class VarcharType(UTF8Type):
typename = 'varchar'
class _ParameterizedType(_CassandraType): class _ParameterizedType(_CassandraType):
def __init__(self, val): def __init__(self, val):
if not self.subtypes: if not self.subtypes:

View File

@@ -124,7 +124,8 @@ class TypeTests(unittest.TestCase):
p timestamp, p timestamp,
q uuid, q uuid,
r timeuuid, r timeuuid,
s varint, s varchar,
t varint,
PRIMARY KEY (a, b) PRIMARY KEY (a, b)
) )
""") """)
@@ -151,6 +152,7 @@ class TypeTests(unittest.TestCase):
mydatetime, # timestamp mydatetime, # timestamp
v4_uuid, # uuid v4_uuid, # uuid
v1_uuid, # timeuuid v1_uuid, # timeuuid
u"sometext\u1234", # varchar
123456789123456789123456789 # varint 123456789123456789123456789 # varint
] ]
@@ -172,12 +174,13 @@ class TypeTests(unittest.TestCase):
mydatetime, # timestamp mydatetime, # timestamp
v4_uuid, # uuid v4_uuid, # uuid
v1_uuid, # timeuuid v1_uuid, # timeuuid
u"sometext\u1234", # varchar
123456789123456789123456789 # varint 123456789123456789123456789 # varint
) )
s.execute(""" s.execute("""
INSERT INTO mytable (a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s) INSERT INTO mytable (a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
""", params) """, params)
results = s.execute("SELECT * FROM mytable") results = s.execute("SELECT * FROM mytable")
@@ -187,8 +190,8 @@ class TypeTests(unittest.TestCase):
# try the same thing with a prepared statement # try the same thing with a prepared statement
prepared = s.prepare(""" prepared = s.prepare("""
INSERT INTO mytable (a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s) INSERT INTO mytable (a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""") """)
s.execute(prepared.bind(params)) s.execute(prepared.bind(params))
@@ -200,7 +203,7 @@ class TypeTests(unittest.TestCase):
# query with prepared statement # query with prepared statement
prepared = s.prepare(""" prepared = s.prepare("""
SELECT a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s FROM mytable SELECT a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t FROM mytable
""") """)
results = s.execute(prepared.bind(())) results = s.execute(prepared.bind(()))