@@ -158,6 +158,7 @@ def setUp(self):
158
158
self .con .create_function ("isblob" , 1 , func_isblob )
159
159
self .con .create_function ("islonglong" , 1 , func_islonglong )
160
160
self .con .create_function ("spam" , - 1 , func )
161
+ self .con .execute ("create table test(t text)" )
161
162
162
163
def tearDown (self ):
163
164
self .con .close ()
@@ -276,18 +277,24 @@ def CheckAnyArguments(self):
276
277
val = cur .fetchone ()[0 ]
277
278
self .assertEqual (val , 2 )
278
279
280
+ @unittest .skipIf (sqlite .sqlite_version_info < (3 , 8 , 3 ), "Requires SQLite 3.8.3 or higher" )
279
281
def CheckFuncNonDeterministic (self ):
282
+ """Non-deterministic functions cannot be used with partial indices"""
280
283
mock = unittest .mock .Mock (return_value = None )
281
- self .con .create_function ("deterministic" , 0 , mock , deterministic = False )
282
- self .con .execute ("select deterministic() = deterministic()" )
283
- self .assertEqual (mock .call_count , 2 )
284
+ self .con .create_function ("nondeterministic" , 0 , mock , deterministic = False )
285
+ with self .assertRaises (sqlite .OperationalError ) as cm :
286
+ self .con .execute ("create index t on test(t) where nondeterministic() is not null" )
287
+ self .assertEqual (str (cm .exception ), "non-deterministic functions prohibited in partial index WHERE clauses" )
284
288
285
- @unittest .skipIf (sqlite .sqlite_version_info < (3 , 8 , 3 ), "deterministic parameter not supported " )
289
+ @unittest .skipIf (sqlite .sqlite_version_info < (3 , 8 , 3 ), "Requires SQLite 3.8.3 or higher " )
286
290
def CheckFuncDeterministic (self ):
291
+ """Deterministic functions can be used with partial indices"""
287
292
mock = unittest .mock .Mock (return_value = None )
288
293
self .con .create_function ("deterministic" , 0 , mock , deterministic = True )
289
- self .con .execute ("select deterministic() = deterministic()" )
290
- self .assertEqual (mock .call_count , 1 )
294
+ try :
295
+ self .con .execute ("create index t on test(t) where deterministic() is not null" )
296
+ except sqlite .OperationalError :
297
+ self .fail ("Unexpected failure while creating partial index" )
291
298
292
299
@unittest .skipIf (sqlite .sqlite_version_info >= (3 , 8 , 3 ), "SQLite < 3.8.3 needed" )
293
300
def CheckFuncDeterministicNotSupported (self ):
0 commit comments