Skip to content

Commit b969ae5

Browse files
author
Erlend E. Aasland
committed
Use old test for sqlite < 3.15.0
1 parent 4664279 commit b969ae5

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

Lib/sqlite3/test/userfunctions.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,25 +277,39 @@ def CheckAnyArguments(self):
277277
val = cur.fetchone()[0]
278278
self.assertEqual(val, 2)
279279

280+
281+
#
282+
# Regarding deterministic functions:
283+
#
284+
# Between 3.8.3 and 3.15.0, deterministic functions were only used to
285+
# optimize inner loops, so for those versions we can only test if the
286+
# sqlite machinery has factored out a call or not. From 3.15.0 and onward,
287+
# deterministic functions were permitted in WHERE clauses of partial
288+
# indices, which allows testing based on syntax, iso. the query optimizer.
289+
#
280290
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher")
281291
def CheckFuncNonDeterministic(self):
282-
"""Non-deterministic functions cannot be used with partial indices"""
283292
mock = unittest.mock.Mock(return_value=None)
284293
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-
# non-deterministic functions prohibited in partial index WHERE clauses
288-
self.assertIn("non-deterministic functions prohibited", str(cm.exception))
294+
if sqlite.sqlite_version_info < (3, 15, 0):
295+
self.con.execute("select nondeterministic() = nondeterministic()")
296+
self.assertEqual(mock.call_count, 2)
297+
else:
298+
with self.assertRaises(sqlite.OperationalError):
299+
self.con.execute("create index t on test(t) where nondeterministic() is not null")
289300

290301
@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "Requires SQLite 3.8.3 or higher")
291302
def CheckFuncDeterministic(self):
292-
"""Deterministic functions can be used with partial indices"""
293303
mock = unittest.mock.Mock(return_value=None)
294304
self.con.create_function("deterministic", 0, mock, deterministic=True)
295-
try:
296-
self.con.execute("create index t on test(t) where deterministic() is not null")
297-
except sqlite.OperationalError:
298-
self.fail("Unexpected failure while creating partial index")
305+
if sqlite.sqlite_version_info < (3, 15, 0):
306+
self.con.execute("select deterministic() = deterministic()")
307+
self.assertEqual(mock.call_count, 1)
308+
else:
309+
try:
310+
self.con.execute("create index t on test(t) where deterministic() is not null")
311+
except sqlite.OperationalError:
312+
self.fail("Unexpected failure while creating partial index")
299313

300314
@unittest.skipIf(sqlite.sqlite_version_info >= (3, 8, 3), "SQLite < 3.8.3 needed")
301315
def CheckFuncDeterministicNotSupported(self):

0 commit comments

Comments
 (0)