comparison roundup/backends/back_sqlite.py @ 2191:f7f6b6981a13

sqlite backend uses the global lock again roundup-server uses ForkingMixIn (yay, simultaneous accesses with mysql and postgresql)
author Richard Jones <richard@users.sourceforge.net>
date Wed, 07 Apr 2004 01:12:26 +0000
parents 7e595abb781e
children 98d3bf8ffb19
comparison
equal deleted inserted replaced
2190:c20c9d62cf99 2191:f7f6b6981a13
1 # $Id: back_sqlite.py,v 1.23 2004-03-31 23:08:08 richard Exp $ 1 # $Id: back_sqlite.py,v 1.24 2004-04-07 01:12:26 richard Exp $
2 '''Implements a backend for SQLite. 2 '''Implements a backend for SQLite.
3 3
4 See https://pysqlite.sourceforge.net/ for pysqlite info 4 See https://pysqlite.sourceforge.net/ for pysqlite info
5 5
6 6
10 __docformat__ = 'restructuredtext' 10 __docformat__ = 'restructuredtext'
11 11
12 import os, base64, marshal 12 import os, base64, marshal
13 13
14 from roundup import hyperdb, date, password 14 from roundup import hyperdb, date, password
15 from roundup.backends import locking
15 from roundup.backends import rdbms_common 16 from roundup.backends import rdbms_common
16 import sqlite 17 import sqlite
17 18
18 class Database(rdbms_common.Database): 19 class Database(rdbms_common.Database):
19 # char to use for positional arguments 20 # char to use for positional arguments
55 56
56 def open_connection(self): 57 def open_connection(self):
57 # ensure files are group readable and writable 58 # ensure files are group readable and writable
58 os.umask(0002) 59 os.umask(0002)
59 60
61 # lock the database
62 lockfilenm = os.path.join(self.dir, 'lock')
63 self.lockfile = locking.acquire_lock(lockfilenm)
64 self.lockfile.write(str(os.getpid()))
65 self.lockfile.flush()
66
60 (self.conn, self.cursor) = self.sql_open_connection() 67 (self.conn, self.cursor) = self.sql_open_connection()
61 68
62 try: 69 try:
63 self.load_dbschema() 70 self.load_dbschema()
64 except sqlite.DatabaseError, error: 71 except sqlite.DatabaseError, error:
208 def sql_close(self): 215 def sql_close(self):
209 ''' Squash any error caused by us already having closed the 216 ''' Squash any error caused by us already having closed the
210 connection. 217 connection.
211 ''' 218 '''
212 try: 219 try:
213 self.conn.close() 220 try:
214 except sqlite.ProgrammingError, value: 221 self.conn.close()
215 if str(value) != 'close failed - Connection is closed.': 222 except sqlite.ProgrammingError, value:
216 raise 223 if str(value) != 'close failed - Connection is closed.':
224 raise
225 finally:
226 # always release the lock
227 if self.lockfile is not None:
228 locking.release_lock(self.lockfile)
229 self.lockfile.close()
230 self.lockfile = None
217 231
218 def sql_rollback(self): 232 def sql_rollback(self):
219 ''' Squash any error caused by us having closed the connection (and 233 ''' Squash any error caused by us having closed the connection (and
220 therefore not having anything to roll back) 234 therefore not having anything to roll back)
221 ''' 235 '''

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