38
38
'- %s found' % sqlite .version )
39
39
sqlite_version = 2
40
40
except ImportError :
41
- import sqlite
42
- sqlite_version = 1
41
+ raise ValueError ("Unable to import sqlite3 or sqlite 2." )
43
42
44
43
45
44
def db_exists (config ):
@@ -61,10 +60,7 @@ class Database(rdbms_common.Database):
61
60
"""
62
61
63
62
# char to use for positional arguments
64
- if sqlite_version in (2 , 3 ):
65
- arg = '?'
66
- else :
67
- arg = '%s'
63
+ arg = '?'
68
64
69
65
dbtype = "sqlite"
70
66
@@ -144,21 +140,6 @@ def getOTKManager(self):
144
140
self .Otk = sessions_sqlite .OneTimeKeys (self )
145
141
return self .Otk
146
142
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
-
162
143
def sql_open_connection (self , dbname = None ):
163
144
"""Open a standard, non-autocommitting connection.
164
145
@@ -174,14 +155,8 @@ def sql_open_connection(self, dbname=None):
174
155
else :
175
156
db = os .path .join (self .config .DATABASE , 'db' )
176
157
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
185
160
186
161
# pysqlite2 / sqlite3 want us to store Unicode in the db but
187
162
# 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):
398
373
v = entry [name ]
399
374
except IndexError :
400
375
v = None
401
- elif (sqlite_version == 1 and name in entry ):
402
- v = entry [name ]
403
376
else :
404
377
v = None
405
378
if name == 'id' :
@@ -543,14 +516,13 @@ def create_class(self, spec):
543
516
vals = (spec .classname , 1 )
544
517
self .sql (sql , vals )
545
518
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
549
521
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 ]
554
526
555
527
556
528
class sqliteClass :
0 commit comments