Skip to content

Commit b090b55

Browse files
committed
Add explicit support for varchar
Fixes PYTHON-40
1 parent 2766377 commit b090b55

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

cassandra/cqltypes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ def serialize(ustr):
510510
return ustr.encode('utf8')
511511

512512

513+
class VarcharType(UTF8Type):
514+
typename = 'varchar'
515+
516+
513517
class _ParameterizedType(_CassandraType):
514518
def __init__(self, val):
515519
if not self.subtypes:

tests/integration/test_types.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def test_basic_types(self):
124124
p timestamp,
125125
q uuid,
126126
r timeuuid,
127-
s varint,
127+
s varchar,
128+
t varint,
128129
PRIMARY KEY (a, b)
129130
)
130131
""")
@@ -151,6 +152,7 @@ def test_basic_types(self):
151152
mydatetime, # timestamp
152153
v4_uuid, # uuid
153154
v1_uuid, # timeuuid
155+
u"sometext\u1234", # varchar
154156
123456789123456789123456789 # varint
155157
]
156158

@@ -172,12 +174,13 @@ def test_basic_types(self):
172174
mydatetime, # timestamp
173175
v4_uuid, # uuid
174176
v1_uuid, # timeuuid
177+
u"sometext\u1234", # varchar
175178
123456789123456789123456789 # varint
176179
)
177180

178181
s.execute("""
179-
INSERT INTO mytable (a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s)
180-
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
182+
INSERT INTO mytable (a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)
183+
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
181184
""", params)
182185

183186
results = s.execute("SELECT * FROM mytable")
@@ -187,8 +190,8 @@ def test_basic_types(self):
187190

188191
# try the same thing with a prepared statement
189192
prepared = s.prepare("""
190-
INSERT INTO mytable (a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s)
191-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
193+
INSERT INTO mytable (a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)
194+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
192195
""")
193196

194197
s.execute(prepared.bind(params))
@@ -200,7 +203,7 @@ def test_basic_types(self):
200203

201204
# query with prepared statement
202205
prepared = s.prepare("""
203-
SELECT a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s FROM mytable
206+
SELECT a, b, c, d, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t FROM mytable
204207
""")
205208
results = s.execute(prepared.bind(()))
206209

0 commit comments

Comments
 (0)