diff roundup/backends/back_sqlite.py @ 3728:b476fef16ccc

fixed support for pysqlite2 (version 2.1.0 is the minimum version supported)
author Richard Jones <richard@users.sourceforge.net>
date Tue, 10 Oct 2006 03:55:31 +0000
parents 0d561b24ceff
children c92687dce135
line wrap: on
line diff
--- a/roundup/backends/back_sqlite.py	Mon Oct 09 23:49:32 2006 +0000
+++ b/roundup/backends/back_sqlite.py	Tue Oct 10 03:55:31 2006 +0000
@@ -1,4 +1,4 @@
-# $Id: back_sqlite.py,v 1.47 2006-10-04 01:12:00 richard Exp $
+# $Id: back_sqlite.py,v 1.48 2006-10-10 03:55:31 richard Exp $
 '''Implements a backend for SQLite.
 
 See https://pysqlite.sourceforge.net/ for pysqlite info
@@ -13,15 +13,17 @@
 
 from roundup import hyperdb, date, password
 from roundup.backends import rdbms_common
-is_sqlite3 = False
+sqlite_version = None
 try:
     import sqlite
+    sqlite_version = 1
 except ImportError:
     try:
         from pysqlite2 import dbapi2 as sqlite
+        sqlite_version = 2
     except ImportError:
         import sqlite3 as sqlite
-        is_sqlite3 = True
+        sqlite_version = 3
 
 def db_exists(config):
     return os.path.exists(os.path.join(config.DATABASE, 'db'))
@@ -31,7 +33,7 @@
 
 class Database(rdbms_common.Database):
     # char to use for positional arguments
-    if is_sqlite3:
+    if sqlite_version in (2,3):
         arg = '?'
     else:
         arg = '%s'
@@ -98,12 +100,12 @@
         logging.getLogger('hyperdb').info('open database %r'%db)
         # set a 30 second timeout (extraordinarily generous) for handling
         # locked database
-        if is_sqlite3:
-            conn = sqlite.connect(db, 30)
-            conn.row_factory = sqlite.Row
-        else:
+        if sqlite_version == 1:
             conn = sqlite.connect(db=db)
             conn.db.sqlite_busy_handler(self.sqlite_busy_handler)
+        else:
+            conn = sqlite.connect(db, timeout=30)
+            conn.row_factory = sqlite.Row
         cursor = conn.cursor()
         return (conn, cursor)
 
@@ -264,7 +266,7 @@
                     # generate the new value for the Interval int column
                     if name.endswith('_int__'):
                         name = name[2:-6]
-                        if is_sqlite3:
+                        if sqlite_version in (2,3):
                             try:
                                 v = hyperdb.Interval(entry[name]).as_seconds()
                             except IndexError:
@@ -273,12 +275,12 @@
                             v = hyperdb.Interval(entry[name]).as_seconds()
                         else:
                             v = None
-                    elif is_sqlite3:
+                    elif sqlite_version in (2,3):
                         try:
                             v = entry[name]
                         except IndexError:
                             v = None
-                    elif (not is_sqlite3 and entry.has_key(name)):
+                    elif (sqlite_version == 1 and entry.has_key(name)):
                         v = entry[name]
                     else:
                         v = None
@@ -368,7 +370,7 @@
         vals = (spec.classname, 1)
         self.sql(sql, vals)
 
-    if is_sqlite3:
+    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
             unpacked'''

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