diff roundup/backends/back_sqlite.py @ 7921:e3975f679bf1

issue2551302 - Remove support for sqlite version 1 from back_sqlite.py Remove sqlite v1 support and document.
author John Rouillard <rouilj@ieee.org>
date Tue, 30 Apr 2024 22:16:22 -0400
parents e10d0b262abd
children 95f91b6f0386
line wrap: on
line diff
--- a/roundup/backends/back_sqlite.py	Mon Apr 29 04:17:10 2024 -0400
+++ b/roundup/backends/back_sqlite.py	Tue Apr 30 22:16:22 2024 -0400
@@ -38,8 +38,7 @@
                              '- %s found' % sqlite.version)
         sqlite_version = 2
     except ImportError:
-        import sqlite
-        sqlite_version = 1
+        raise ValueError("Unable to import sqlite3 or sqlite 2.")
 
 
 def db_exists(config):
@@ -61,10 +60,7 @@
     """
 
     # char to use for positional arguments
-    if sqlite_version in (2, 3):
-        arg = '?'
-    else:
-        arg = '%s'
+    arg = '?'
 
     dbtype = "sqlite"
 
@@ -144,21 +140,6 @@
                 self.Otk = sessions_sqlite.OneTimeKeys(self)
         return self.Otk
 
-    def sqlite_busy_handler(self, data, table, count):
-        """invoked whenever SQLite tries to access a database that is locked"""
-        now = time.time()
-        if count == 1:
-            # Timeout for handling locked database (default 30s)
-            self._busy_handler_endtime = now + self.config.RDBMS_SQLITE_TIMEOUT
-        elif now > self._busy_handler_endtime:
-            # timeout expired - no more retries
-            return 0
-        # sleep adaptively as retry count grows,
-        # starting from about half a second
-        time_to_sleep = 0.01 * (2 << min(5, count))
-        time.sleep(time_to_sleep)
-        return 1
-
     def sql_open_connection(self, dbname=None):
         """Open a standard, non-autocommitting connection.
 
@@ -174,14 +155,8 @@
         else:
             db = os.path.join(self.config.DATABASE, 'db')
         logging.getLogger('roundup.hyperdb').info('open database %r' % db)
-        # set timeout (30 second default is extraordinarily generous)
-        # for handling locked database
-        if sqlite_version == 1:
-            conn = sqlite.connect(db=db)
-            conn.db.sqlite_busy_handler(self.sqlite_busy_handler)
-        else:
-            conn = sqlite.connect(db, timeout=self.config.RDBMS_SQLITE_TIMEOUT)
-            conn.row_factory = sqlite.Row
+        conn = sqlite.connect(db, timeout=self.config.RDBMS_SQLITE_TIMEOUT)
+        conn.row_factory = sqlite.Row
 
         # pysqlite2 / sqlite3 want us to store Unicode in the db but
         # that's not what's been done historically and it's definitely
@@ -398,8 +373,6 @@
                             v = entry[name]
                         except IndexError:
                             v = None
-                    elif (sqlite_version == 1 and name in entry):
-                        v = entry[name]
                     else:
                         v = None
                     if name == 'id':
@@ -543,14 +516,13 @@
         vals = (spec.classname, 1)
         self.sql(sql, vals)
 
-    if sqlite_version in (2, 3):
-        def load_journal(self, classname, cols, nodeid):
-            """We need to turn the sqlite3.Row into a tuple so it can be
+    def load_journal(self, classname, cols, nodeid):
+        """We need to turn the sqlite3.Row into a tuple so it can be
             unpacked"""
-            l = rdbms_common.Database.load_journal(self,
-                                                   classname, cols, nodeid)
-            cols = range(5)
-            return [[row[col] for col in cols] for row in l]
+        l = rdbms_common.Database.load_journal(self,
+                                               classname, cols, nodeid)
+        cols = range(5)
+        return [[row[col] for col in cols] for row in l]
 
 
 class sqliteClass:

Roundup Issue Tracker: http://roundup-tracker.org/