@@ -53,6 +53,8 @@ def wrapper(self, *args, **kwargs):
5353
5454def func_returntext ():
5555 return "foo"
56+ def func_returntextwithnull ():
57+ return "1\x00 2"
5658def func_returnunicode ():
5759 return "bar"
5860def func_returnint ():
@@ -163,11 +165,21 @@ def step(self, val):
163165 def finalize (self ):
164166 return self .val
165167
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+
166177class FunctionTests (unittest .TestCase ):
167178 def setUp (self ):
168179 self .con = sqlite .connect (":memory:" )
169180
170181 self .con .create_function ("returntext" , 0 , func_returntext )
182+ self .con .create_function ("returntextwithnull" , 0 , func_returntextwithnull )
171183 self .con .create_function ("returnunicode" , 0 , func_returnunicode )
172184 self .con .create_function ("returnint" , 0 , func_returnint )
173185 self .con .create_function ("returnfloat" , 0 , func_returnfloat )
@@ -211,6 +223,12 @@ def test_func_return_text(self):
211223 self .assertEqual (type (val ), str )
212224 self .assertEqual (val , "foo" )
213225
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+
214232 def test_func_return_unicode (self ):
215233 cur = self .con .cursor ()
216234 cur .execute ("select returnunicode()" )
@@ -390,6 +408,7 @@ def setUp(self):
390408 self .con .create_aggregate ("checkType" , 2 , AggrCheckType )
391409 self .con .create_aggregate ("checkTypes" , - 1 , AggrCheckTypes )
392410 self .con .create_aggregate ("mysum" , 1 , AggrSum )
411+ self .con .create_aggregate ("aggtxt" , 1 , AggrText )
393412
394413 def tearDown (self ):
395414 #self.cur.close()
@@ -486,6 +505,15 @@ def test_aggr_no_match(self):
486505 val = cur .fetchone ()[0 ]
487506 self .assertIsNone (val )
488507
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+
489517class AuthorizerTests (unittest .TestCase ):
490518 @staticmethod
491519 def authorizer_cb (action , arg1 , arg2 , dbname , source ):
0 commit comments