diff roundup/backends/back_sqlite.py @ 2082:c091cacdc505

Finished implementation of session and one-time-key stores for RDBMS backends. Refactored the API of sessions and their interaction with the backend database a fair bit too. Added some session tests. Nothing testing ageing yet, 'cos that's a pain inna ass to test :) Note: metakit backend still uses the *dbm implementation. It might want to implement its own session store some day, as it'll be faster than the *dbm one.
author Richard Jones <richard@users.sourceforge.net>
date Thu, 18 Mar 2004 01:58:46 +0000
parents 3e0961d6d44d
children 3f6024ab2c7a
line wrap: on
line diff
--- a/roundup/backends/back_sqlite.py	Wed Mar 17 22:01:37 2004 +0000
+++ b/roundup/backends/back_sqlite.py	Thu Mar 18 01:58:46 2004 +0000
@@ -1,4 +1,4 @@
-# $Id: back_sqlite.py,v 1.16 2004-03-15 05:50:20 richard Exp $
+# $Id: back_sqlite.py,v 1.17 2004-03-18 01:58:45 richard Exp $
 '''Implements a backend for SQLite.
 
 See https://pysqlite.sourceforge.net/ for pysqlite info
@@ -17,18 +17,24 @@
     arg = '%s'
 
     def sql_open_connection(self):
+        db = os.path.join(self.config.DATABASE, 'db')
+        conn = sqlite.connect(db=db)
+        cursor = conn.cursor()
+        return (conn, cursor)
+
+    def open_connection(self):
         # ensure files are group readable and writable
         os.umask(0002)
+
+        # lock the database
         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()
+        (self.conn, self.cursor) = self.sql_open_connection()
+
         try:
             self.load_dbschema()
         except sqlite.DatabaseError, error:
@@ -40,13 +46,24 @@
             self.cursor.execute('create index ids_name_idx on ids(name)')
             self.create_version_2_tables()
 
+    def close(self):
+        ''' Close off the connection.
+        '''
+        self.sql_close()
+        if self.lockfile is not None:
+            locking.release_lock(self.lockfile)
+        if self.lockfile is not None:
+            self.lockfile.close()
+            self.lockfile = None
+
     def create_version_2_tables(self):
         self.cursor.execute('create table otks (otk_key varchar, '
-            'otk_value varchar, otk_time varchar)')
+            'otk_value varchar, otk_time integer)')
         self.cursor.execute('create index otks_key_idx on otks(otk_key)')
-        self.cursor.execute('create table sessions (s_key varchar, '
-            's_last_use varchar, s_user varchar)')
-        self.cursor.execute('create index sessions_key_idx on sessions(s_key)')
+        self.cursor.execute('create table sessions (session_key varchar, '
+            'session_time integer, session_value varchar)')
+        self.cursor.execute('create index sessions_key_idx on '
+                'sessions(session_key)')
 
     def add_actor_column(self):
         # update existing tables to have the new actor column

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