index e5f64b0a8598ad73d8f33bcb4b87399c69943f8c..69d258523dbd1e335b435b710c0775b18bce85b2 100644 (file)
-# $Id: back_sqlite.py,v 1.4 2002-09-23 06:48:35 richard Exp $
+# $Id: back_sqlite.py,v 1.8 2002-12-12 09:31:04 richard Exp $
__doc__ = '''
See https://pysqlite.sourceforge.net/ for pysqlite info
'''
import base64, marshal
from roundup.backends.rdbms_common import *
+from roundup.backends import locking
import sqlite
class Database(Database):
# ensure files are group readable and writable
os.umask(0002)
db = os.path.join(self.config.DATABASE, 'db')
+
+ # lock it
+ lockfilenm = db[:-3] + 'lck'
+ self.lockfile = locking.acquire_lock(lockfilenm)
+ self.lockfile.write(str(os.getpid()))
+ self.lockfile.flush()
+
self.conn = sqlite.connect(db=db)
self.cursor = self.conn.cursor()
try:
self.cursor.execute('create table schema (schema varchar)')
self.cursor.execute('create table ids (name varchar, num integer)')
+ def close(self):
+ ''' Close off the connection.
+
+ Squash any error caused by us already having closed the
+ connection.
+ '''
+ try:
+ self.conn.close()
+ except sqlite.ProgrammingError, value:
+ if str(value) != 'close failed - Connection is closed.':
+ raise
+
+ # release the lock too
+ if self.lockfile is not None:
+ locking.release_lock(self.lockfile)
+ if self.lockfile is not None:
+ self.lockfile.close()
+ self.lockfile = None
+
+ def rollback(self):
+ ''' Reverse all actions from the current transaction.
+
+ Undo all the changes made since the database was opened or the
+ last commit() or rollback() was performed.
+
+ Squash any error caused by us having closed the connection (and
+ therefore not having anything to roll back)
+ '''
+ if __debug__:
+ print >>hyperdb.DEBUG, 'rollback', (self,)
+
+ # roll back
+ try:
+ self.conn.rollback()
+ except sqlite.ProgrammingError, value:
+ if str(value) != 'rollback failed - Connection is closed.':
+ raise
+
+ # roll back "other" transaction stuff
+ for method, args in self.transactions:
+ # delete temporary files
+ if method == self.doStoreFile:
+ self.rollbackStoreFile(*args)
+ self.transactions = []
+
def __repr__(self):
return '<roundlite 0x%x>'%id(self)
'''
return self.cursor.fetchone()
+ def sql_fetchall(self):
+ ''' Fetch a single row. If there's nothing to fetch, return [].
+ '''
+ return self.cursor.fetchall()
+
def sql_commit(self):
''' Actually commit to the database.
d[k] = date.Date(v)
elif isinstance(prop, Interval) and v is not None:
d[k] = date.Interval(v)
- elif isinstance(prop, Password):
+ elif isinstance(prop, Password) and v is not None:
p = password.Password()
p.unpack(v)
d[k] = p