@@ -53,6 +53,8 @@ def wrapper(self, *args, **kwargs):
53
53
54
54
def func_returntext ():
55
55
return "foo"
56
+ def func_returntextwithnull ():
57
+ return "1\x00 2"
56
58
def func_returnunicode ():
57
59
return "bar"
58
60
def func_returnint ():
@@ -163,11 +165,21 @@ def step(self, val):
163
165
def finalize (self ):
164
166
return self .val
165
167
168
+ class AggrText :
169
+ def __init__ (self ):
170
+ self .txt = ""
171
+ def step (self , txt ):
172
+ self .txt = self .txt + txt
173
+ def finalize (self ):
174
+ return self .txt
175
+
176
+
166
177
class FunctionTests (unittest .TestCase ):
167
178
def setUp (self ):
168
179
self .con = sqlite .connect (":memory:" )
169
180
170
181
self .con .create_function ("returntext" , 0 , func_returntext )
182
+ self .con .create_function ("returntextwithnull" , 0 , func_returntextwithnull )
171
183
self .con .create_function ("returnunicode" , 0 , func_returnunicode )
172
184
self .con .create_function ("returnint" , 0 , func_returnint )
173
185
self .con .create_function ("returnfloat" , 0 , func_returnfloat )
@@ -211,6 +223,12 @@ def test_func_return_text(self):
211
223
self .assertEqual (type (val ), str )
212
224
self .assertEqual (val , "foo" )
213
225
226
+ def test_func_return_text_with_null_char (self ):
227
+ cur = self .con .cursor ()
228
+ res = cur .execute ("select returntextwithnull()" ).fetchone ()[0 ]
229
+ self .assertEqual (type (res ), str )
230
+ self .assertEqual (res , "1\x00 2" )
231
+
214
232
def test_func_return_unicode (self ):
215
233
cur = self .con .cursor ()
216
234
cur .execute ("select returnunicode()" )
@@ -390,6 +408,7 @@ def setUp(self):
390
408
self .con .create_aggregate ("checkType" , 2 , AggrCheckType )
391
409
self .con .create_aggregate ("checkTypes" , - 1 , AggrCheckTypes )
392
410
self .con .create_aggregate ("mysum" , 1 , AggrSum )
411
+ self .con .create_aggregate ("aggtxt" , 1 , AggrText )
393
412
394
413
def tearDown (self ):
395
414
#self.cur.close()
@@ -486,6 +505,15 @@ def test_aggr_no_match(self):
486
505
val = cur .fetchone ()[0 ]
487
506
self .assertIsNone (val )
488
507
508
+ def test_aggr_text (self ):
509
+ cur = self .con .cursor ()
510
+ for txt in ["foo" , "1\x00 2" ]:
511
+ with self .subTest (txt = txt ):
512
+ cur .execute ("select aggtxt(?) from test" , (txt ,))
513
+ val = cur .fetchone ()[0 ]
514
+ self .assertEqual (val , txt )
515
+
516
+
489
517
class AuthorizerTests (unittest .TestCase ):
490
518
@staticmethod
491
519
def authorizer_cb (action , arg1 , arg2 , dbname , source ):
0 commit comments