Mercurial > p > roundup > code
comparison roundup/backends/back_postgresql.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 | 93f03c6714d8 |
comparison
equal
deleted
inserted
replaced
| 2081:fb4bf55b94d7 | 2082:c091cacdc505 |
|---|---|
| 81 | 81 |
| 82 class Database(rdbms_common.Database): | 82 class Database(rdbms_common.Database): |
| 83 arg = '%s' | 83 arg = '%s' |
| 84 | 84 |
| 85 def sql_open_connection(self): | 85 def sql_open_connection(self): |
| 86 db = getattr(self.config, 'POSTGRESQL_DATABASE') | |
| 87 try: | |
| 88 conn = psycopg.connect(**db) | |
| 89 except psycopg.OperationalError, message: | |
| 90 raise hyperdb.DatabaseError, message | |
| 91 | |
| 92 cursor = conn.cursor() | |
| 93 | |
| 94 return (conn, cursor) | |
| 95 | |
| 96 def open_connection(self): | |
| 86 if not db_exists(self.config): | 97 if not db_exists(self.config): |
| 87 db_create(self.config) | 98 db_create(self.config) |
| 88 | 99 |
| 89 if __debug__: | 100 if __debug__: |
| 90 print >>hyperdb.DEBUG, '+++ open database connection +++' | 101 print >>hyperdb.DEBUG, '+++ open database connection +++' |
| 91 | 102 |
| 92 db = getattr(self.config, 'POSTGRESQL_DATABASE') | 103 self.conn, self.cursor = self.sql_open_connection() |
| 93 try: | |
| 94 self.conn = psycopg.connect(**db) | |
| 95 except psycopg.OperationalError, message: | |
| 96 raise hyperdb.DatabaseError, message | |
| 97 | |
| 98 self.cursor = self.conn.cursor() | |
| 99 | 104 |
| 100 try: | 105 try: |
| 101 self.load_dbschema() | 106 self.load_dbschema() |
| 102 except: | 107 except: |
| 103 self.rollback() | 108 self.rollback() |
| 109 | 114 |
| 110 def create_version_2_tables(self): | 115 def create_version_2_tables(self): |
| 111 self.cursor.execute('CREATE TABLE otks (otk_key VARCHAR(255), ' | 116 self.cursor.execute('CREATE TABLE otks (otk_key VARCHAR(255), ' |
| 112 'otk_value VARCHAR(255), otk_time FLOAT(20))') | 117 'otk_value VARCHAR(255), otk_time FLOAT(20))') |
| 113 self.cursor.execute('CREATE INDEX otks_key_idx ON otks(otk_key)') | 118 self.cursor.execute('CREATE INDEX otks_key_idx ON otks(otk_key)') |
| 114 self.cursor.execute('CREATE TABLE sessions (s_key VARCHAR(255), ' | 119 self.cursor.execute('CREATE TABLE sessions (session_key VARCHAR(255), ' |
| 115 's_last_use FLOAT(20), s_user VARCHAR(255))') | 120 'session_time FLOAT(20), session_value VARCHAR(255))') |
| 116 self.cursor.execute('CREATE INDEX sessions_key_idx ON sessions(s_key)') | 121 self.cursor.execute('CREATE INDEX sessions_key_idx ON ' |
| 122 'sessions(session_key)') | |
| 117 | 123 |
| 118 def add_actor_column(self): | 124 def add_actor_column(self): |
| 119 # update existing tables to have the new actor column | 125 # update existing tables to have the new actor column |
| 120 tables = self.database_schema['tables'] | 126 tables = self.database_schema['tables'] |
| 121 for name in tables.keys(): | 127 for name in tables.keys(): |
