[Zope-CVS] CVS: Products/AdaptableStorage/gateway_sql - PsycopgConnection.py:1.2 SQLClassification.py:1.2 SQLFolderItems.py:1.2 SQLItemId.py:1.2 SQLKeychainGenerator.py:1.2 SQLRemainder.py:1.2
Shane Hathaway
shane@zope.com
Tue, 10 Dec 2002 17:27:02 -0500
Update of /cvs-repository/Products/AdaptableStorage/gateway_sql
In directory cvs.zope.org:/tmp/cvs-serv26118/gateway_sql
Modified Files:
PsycopgConnection.py SQLClassification.py SQLFolderItems.py
SQLItemId.py SQLKeychainGenerator.py SQLRemainder.py
Log Message:
With a few corrections and duct tape, all tests pass. Woohoo!
=== Products/AdaptableStorage/gateway_sql/PsycopgConnection.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_sql/PsycopgConnection.py:1.1 Tue Dec 10 15:37:52 2002
+++ Products/AdaptableStorage/gateway_sql/PsycopgConnection.py Tue Dec 10 17:27:00 2002
@@ -24,24 +24,26 @@
_final = 0
def __init__(self, params='', prefix='zodb'):
+ self.params = params
self.db = psycopg.connect(params)
+ self.cursor = self.db.cursor()
self.prefix = prefix
self.error = psycopg.DatabaseError
+ def sortKey(self):
+ return self.getName()
+
+ def getName(self):
+ return 'Psycopg connection "%s"' % self.params
+
def execute(self, text, fetch=0, cursor=None, **kw):
- created = 0
if cursor is None:
- created = 1
- cursor = self.db.cursor()
- try:
- cursor.execute(text, kw)
- if fetch:
- return cursor.fetchall()
- else:
- return None
- finally:
- if created:
- cursor.close()
+ cursor = self.cursor
+ cursor.execute(text, kw)
+ if fetch:
+ return cursor.fetchall()
+ else:
+ return None
def begin(self):
pass
@@ -53,7 +55,10 @@
self._final = 0
def abort(self):
- self.reset()
+ try:
+ self.db.rollback()
+ finally:
+ self.reset()
def finish(self):
if self._final:
=== Products/AdaptableStorage/gateway_sql/SQLClassification.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_sql/SQLClassification.py:1.1 Tue Dec 10 15:37:52 2002
+++ Products/AdaptableStorage/gateway_sql/SQLClassification.py Tue Dec 10 17:27:00 2002
@@ -37,7 +37,7 @@
(key, meta_type, class_name)
VALUES (%(key)s, %(meta_type)s, %(class_name)s)'''
-drop_sql = '''DROP TABLE %(table)s'''
+clear_sql = '''DELETE FROM %(table)s'''
class SQLClassification:
@@ -52,14 +52,19 @@
try:
self.execute(checkexist_sql)
except conn.error:
+ conn.db.rollback()
self.execute(create_sql)
+ conn.db.commit()
- def execute(self, *args, **kw):
- kw['table'] = self.table
- return self.conn.execute(*args, **kw)
+ def getSchema(self):
+ return self.schema
- def drop(self):
- self.execute(drop_sql)
+ def execute(self, text, *args, **kw):
+ text = text.replace('%(table)s', self.table) # XXX workaround
+ return self.conn.execute(text, *args, **kw)
+
+ def clear(self):
+ self.execute(clear_sql)
def load(self, event):
key = int(event.getKeychain()[-1])
=== Products/AdaptableStorage/gateway_sql/SQLFolderItems.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_sql/SQLFolderItems.py:1.1 Tue Dec 10 15:37:52 2002
+++ Products/AdaptableStorage/gateway_sql/SQLFolderItems.py Tue Dec 10 17:27:00 2002
@@ -27,7 +27,7 @@
child_key int
)'''
-read_sql = '''SELECT name, child_key from %(table)s
+read_sql = '''SELECT name, child_key FROM %(table)s
WHERE key = %(key)s'''
update_sql = '''UPDATE %(table)s
@@ -38,7 +38,7 @@
(key, name, child_key)
VALUES (%(key)s, %(name)s, %(child_key)s)'''
-drop_sql = '''DROP TABLE %(table)s'''
+clear_sql = '''DELETE FROM %(table)s'''
class SQLFolderItems:
@@ -55,29 +55,36 @@
try:
self.execute(checkexist_sql)
except conn.error:
+ conn.db.rollback()
self.execute(create_sql)
+ conn.db.commit()
- def execute(self, *args, **kw):
- kw['table'] = self.table
- return self.conn.execute(*args, **kw)
+ def getSchema(self):
+ return self.schema
- def drop(self):
- self.execute(drop_sql)
+ def execute(self, text, *args, **kw):
+ text = text.replace('%(table)s', self.table) # XXX workaround
+ return self.conn.execute(text, *args, **kw)
+
+ def clear(self):
+ self.execute(clear_sql)
def load(self, event):
- key = int(event.getKeychain()[-1])
- items = self.execute(read_sql, 1, key=key)
- items.sort()
- res = [(rec[0], key + (rec[1],)) for rec in res]
+ keychain = event.getKeychain()
+ key = int(keychain[-1])
+ prefix = keychain[:-1]
+ rows = self.execute(read_sql, 1, key=key)
+ rows.sort()
+ res = [(row[0], prefix + (row[1],)) for row in rows]
return res, tuple(res)
def store(self, event, state):
keychain = event.getKeychain()
keychain1 = keychain[:-1]
key = int(keychain[-1])
- items = self.execute(read_sql, 1, key=key)
+ rows = self.execute(read_sql, 1, key=key)
dict = {}
- for name, child_key in items:
+ for name, child_key in rows:
dict[name] = child_key
state = list(state)
state.sort()
=== Products/AdaptableStorage/gateway_sql/SQLItemId.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_sql/SQLItemId.py:1.1 Tue Dec 10 15:37:52 2002
+++ Products/AdaptableStorage/gateway_sql/SQLItemId.py Tue Dec 10 17:27:00 2002
@@ -34,9 +34,12 @@
self.conn = conn
self.table = conn.prefix + '_folder_items'
- def execute(self, *args, **kw):
- kw['table'] = self.table
- return self.conn.execute(*args, **kw)
+ def getSchema(self):
+ return self.schema
+
+ def execute(self, text, *args, **kw):
+ text = text.replace('%(table)s', self.table) # XXX workaround
+ return self.conn.execute(text, *args, **kw)
def load(self, event):
key = int(event.getKeychain()[-1])
=== Products/AdaptableStorage/gateway_sql/SQLKeychainGenerator.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_sql/SQLKeychainGenerator.py:1.1 Tue Dec 10 15:37:52 2002
+++ Products/AdaptableStorage/gateway_sql/SQLKeychainGenerator.py Tue Dec 10 17:27:00 2002
@@ -25,7 +25,7 @@
read_sql = """SELECT nextval('%(sequence)s')"""
-drop_sql = '''DROP SEQUENCE %(sequence)s'''
+clear_sql = """SELECT setval('%(sequence)s', 1)"""
class SQLKeychainGenerator:
@@ -38,19 +38,24 @@
try:
self.execute(checkexist_sql)
except conn.error:
+ conn.db.rollback()
self.execute(create_sql)
+ conn.db.commit()
- def execute(self, *args, **kw):
- kw['sequence'] = self.sequence
- return self.conn.execute(*args, **kw)
+ def getSchema(self):
+ return self.schema
+
+ def execute(self, text, *args, **kw):
+ text = text.replace('%(sequence)s', self.sequence) # XXX workaround
+ return self.conn.execute(text, *args, **kw)
def makeKeychain(self, event, name, stored):
if not stored:
raise RuntimeError(
'Keychains generated by SQLKeychain must be stored')
- n = self.execute(read_sql, 1)[0]
- return event.getKeychain()[:-1] + (str(n),)
+ n = self.execute(read_sql, 1)[0][0]
+ return event.getKeychain()[:-1] + (n,)
- def drop(self):
- self.execute(drop_sql)
+ def clear(self):
+ self.execute(clear_sql)
=== Products/AdaptableStorage/gateway_sql/SQLRemainder.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_sql/SQLRemainder.py:1.1 Tue Dec 10 15:37:52 2002
+++ Products/AdaptableStorage/gateway_sql/SQLRemainder.py Tue Dec 10 17:27:00 2002
@@ -22,7 +22,7 @@
checkexist_sql = '''SELECT key FROM %(table)s LIMIT 1'''
create_sql = '''CREATE TABLE %(table)s (
- key int PRIMARY_KEY,
+ key int PRIMARY KEY,
pickle bytea
)'''
@@ -37,7 +37,7 @@
(key, pickle)
VALUES (%(key)s, %(pickle)s)'''
-drop_sql = '''DROP TABLE %(table)s'''
+clear_sql = '''DELETE FROM %(table)s'''
class SQLRemainder:
@@ -52,14 +52,19 @@
try:
self.execute(checkexist_sql)
except conn.error:
+ conn.db.rollback()
self.execute(create_sql)
+ conn.db.commit()
- def execute(self, *args, **kw):
- kw['table'] = self.table
- return self.conn.execute(*args, **kw)
+ def getSchema(self):
+ return self.schema
- def drop(self):
- self.execute(drop_sql)
+ def execute(self, text, *args, **kw):
+ text = text.replace('%(table)s', self.table) # XXX workaround
+ return self.conn.execute(text, *args, **kw)
+
+ def clear(self):
+ self.execute(clear_sql)
def load(self, event):
key = int(event.getKeychain()[-1])