3838 '- %s found' % sqlite .version )
3939 sqlite_version = 2
4040 except ImportError :
41- import sqlite
42- sqlite_version = 1
41+ raise ValueError ("Unable to import sqlite3 or sqlite 2." )
4342
4443
4544def db_exists (config ):
@@ -61,10 +60,7 @@ class Database(rdbms_common.Database):
6160 """
6261
6362 # char to use for positional arguments
64- if sqlite_version in (2 , 3 ):
65- arg = '?'
66- else :
67- arg = '%s'
63+ arg = '?'
6864
6965 dbtype = "sqlite"
7066
@@ -144,21 +140,6 @@ def getOTKManager(self):
144140 self .Otk = sessions_sqlite .OneTimeKeys (self )
145141 return self .Otk
146142
147- def sqlite_busy_handler (self , data , table , count ):
148- """invoked whenever SQLite tries to access a database that is locked"""
149- now = time .time ()
150- if count == 1 :
151- # Timeout for handling locked database (default 30s)
152- self ._busy_handler_endtime = now + self .config .RDBMS_SQLITE_TIMEOUT
153- elif now > self ._busy_handler_endtime :
154- # timeout expired - no more retries
155- return 0
156- # sleep adaptively as retry count grows,
157- # starting from about half a second
158- time_to_sleep = 0.01 * (2 << min (5 , count ))
159- time .sleep (time_to_sleep )
160- return 1
161-
162143 def sql_open_connection (self , dbname = None ):
163144 """Open a standard, non-autocommitting connection.
164145
@@ -174,14 +155,8 @@ def sql_open_connection(self, dbname=None):
174155 else :
175156 db = os .path .join (self .config .DATABASE , 'db' )
176157 logging .getLogger ('roundup.hyperdb' ).info ('open database %r' % db )
177- # set timeout (30 second default is extraordinarily generous)
178- # for handling locked database
179- if sqlite_version == 1 :
180- conn = sqlite .connect (db = db )
181- conn .db .sqlite_busy_handler (self .sqlite_busy_handler )
182- else :
183- conn = sqlite .connect (db , timeout = self .config .RDBMS_SQLITE_TIMEOUT )
184- conn .row_factory = sqlite .Row
158+ conn = sqlite .connect (db , timeout = self .config .RDBMS_SQLITE_TIMEOUT )
159+ conn .row_factory = sqlite .Row
185160
186161 # pysqlite2 / sqlite3 want us to store Unicode in the db but
187162 # that's not what's been done historically and it's definitely
@@ -398,8 +373,6 @@ def update_class(self, spec, old_spec, force=0, adding_v2=0):
398373 v = entry [name ]
399374 except IndexError :
400375 v = None
401- elif (sqlite_version == 1 and name in entry ):
402- v = entry [name ]
403376 else :
404377 v = None
405378 if name == 'id' :
@@ -543,14 +516,13 @@ def create_class(self, spec):
543516 vals = (spec .classname , 1 )
544517 self .sql (sql , vals )
545518
546- if sqlite_version in (2 , 3 ):
547- def load_journal (self , classname , cols , nodeid ):
548- """We need to turn the sqlite3.Row into a tuple so it can be
519+ def load_journal (self , classname , cols , nodeid ):
520+ """We need to turn the sqlite3.Row into a tuple so it can be
549521 unpacked"""
550- l = rdbms_common .Database .load_journal (self ,
551- classname , cols , nodeid )
552- cols = range (5 )
553- return [[row [col ] for col in cols ] for row in l ]
522+ l = rdbms_common .Database .load_journal (self ,
523+ classname , cols , nodeid )
524+ cols = range (5 )
525+ return [[row [col ] for col in cols ] for row in l ]
554526
555527
556528class sqliteClass :
0 commit comments