]> granicus.if.org Git - python/commitdiff
Issue #27190: Raise NotSupportedError if sqlite3 is older than 3.3.1
authorBerker Peksag <berker.peksag@gmail.com>
Sun, 12 Jun 2016 11:09:51 +0000 (14:09 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Sun, 12 Jun 2016 11:09:51 +0000 (14:09 +0300)
Patch by Dave Sawyer.

Lib/sqlite3/test/dbapi.py
Misc/NEWS
Modules/_sqlite/connection.c

index 04d04794c79d0435ebcb6c191f9b333565bbd9ee..78c27d7a7139417a56d739ebe6324c3687afc364 100644 (file)
@@ -180,6 +180,12 @@ class ConnectionTests(unittest.TestCase):
             with self.assertRaises(sqlite.OperationalError):
                 cx.execute('insert into test(id) values(1)')
 
+    def CheckSameThreadErrorOnOldVersion(self):
+        if sqlite.sqlite_version_info >= (3, 3, 1):
+            self.skipTest('test needs sqlite3 versions older than 3.3.1')
+        with self.assertRaises(sqlite.NotSupportedError) as cm:
+            sqlite.connect(':memory:', check_same_thread=False)
+        self.assertEqual(str(cm.exception), 'shared connections not available')
 
 class CursorTests(unittest.TestCase):
     def setUp(self):
index 3189824866ce26692f0f5505f600bbaefea1d4dd..3e374f816207464592aabf76f370e8b18ab4031f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: tba
 Core and Builtins
 -----------------
 
+- Issue #27190: Raise NotSupportedError if sqlite3 is older than 3.3.1.
+  Patch by Dave Sawyer.
+
 - Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode.  Calling
   function with generalized unpacking (PEP 448) and conflicting keyword names
   could cause undefined behavior.
index 7570624e04e704419ee366d94b042d25bfa7cdbe..6aa4764b6c6b0b01cfbc772bdb462caefd73e0b0 100644 (file)
@@ -164,6 +164,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
 #ifdef WITH_THREAD
     self->thread_ident = PyThread_get_thread_ident();
 #endif
+    if (!check_same_thread && sqlite3_libversion_number() < 3003001) {
+        PyErr_SetString(pysqlite_NotSupportedError, "shared connections not available");
+        return -1;
+    }
     self->check_same_thread = check_same_thread;
 
     self->function_pinboard = PyDict_New();