1- # $Id: back_sqlite.py,v 1.47 2006-10-04 01:12:00 richard Exp $
1+ # $Id: back_sqlite.py,v 1.48 2006-10-10 03:55:31 richard Exp $
22'''Implements a backend for SQLite.
33
44See https://pysqlite.sourceforge.net/ for pysqlite info
1313
1414from roundup import hyperdb , date , password
1515from roundup .backends import rdbms_common
16- is_sqlite3 = False
16+ sqlite_version = None
1717try :
1818 import sqlite
19+ sqlite_version = 1
1920except ImportError :
2021 try :
2122 from pysqlite2 import dbapi2 as sqlite
23+ sqlite_version = 2
2224 except ImportError :
2325 import sqlite3 as sqlite
24- is_sqlite3 = True
26+ sqlite_version = 3
2527
2628def db_exists (config ):
2729 return os .path .exists (os .path .join (config .DATABASE , 'db' ))
@@ -31,7 +33,7 @@ def db_nuke(config):
3133
3234class Database (rdbms_common .Database ):
3335 # char to use for positional arguments
34- if is_sqlite3 :
36+ if sqlite_version in ( 2 , 3 ) :
3537 arg = '?'
3638 else :
3739 arg = '%s'
@@ -98,12 +100,12 @@ def sql_open_connection(self):
98100 logging .getLogger ('hyperdb' ).info ('open database %r' % db )
99101 # set a 30 second timeout (extraordinarily generous) for handling
100102 # locked database
101- if is_sqlite3 :
102- conn = sqlite .connect (db , 30 )
103- conn .row_factory = sqlite .Row
104- else :
103+ if sqlite_version == 1 :
105104 conn = sqlite .connect (db = db )
106105 conn .db .sqlite_busy_handler (self .sqlite_busy_handler )
106+ else :
107+ conn = sqlite .connect (db , timeout = 30 )
108+ conn .row_factory = sqlite .Row
107109 cursor = conn .cursor ()
108110 return (conn , cursor )
109111
@@ -264,7 +266,7 @@ def update_class(self, spec, old_spec, force=0, adding_v2=0):
264266 # generate the new value for the Interval int column
265267 if name .endswith ('_int__' ):
266268 name = name [2 :- 6 ]
267- if is_sqlite3 :
269+ if sqlite_version in ( 2 , 3 ) :
268270 try :
269271 v = hyperdb .Interval (entry [name ]).as_seconds ()
270272 except IndexError :
@@ -273,12 +275,12 @@ def update_class(self, spec, old_spec, force=0, adding_v2=0):
273275 v = hyperdb .Interval (entry [name ]).as_seconds ()
274276 else :
275277 v = None
276- elif is_sqlite3 :
278+ elif sqlite_version in ( 2 , 3 ) :
277279 try :
278280 v = entry [name ]
279281 except IndexError :
280282 v = None
281- elif (not is_sqlite3 and entry .has_key (name )):
283+ elif (sqlite_version == 1 and entry .has_key (name )):
282284 v = entry [name ]
283285 else :
284286 v = None
@@ -368,7 +370,7 @@ def create_class(self, spec):
368370 vals = (spec .classname , 1 )
369371 self .sql (sql , vals )
370372
371- if is_sqlite3 :
373+ if sqlite_version in ( 2 , 3 ) :
372374 def load_journal (self , classname , cols , nodeid ):
373375 '''We need to turn the sqlite3.Row into a tuple so it can be
374376 unpacked'''
0 commit comments