[Zope-CVS] CVS: Products/AdaptableStorage/gateway_sql - SQLFolderItems.py:1.3 SQLItemId.py:1.3

Shane Hathaway shane@zope.com
Fri, 13 Dec 2002 16:21:45 -0500


Update of /cvs-repository/Products/AdaptableStorage/gateway_sql
In directory cvs.zope.org:/tmp/cvs-serv10180

Modified Files:
	SQLFolderItems.py SQLItemId.py 
Log Message:
Fixed two bugs in the SQL gateways: forgot to delete items from the folder
items table when they are removed from the folder (silly me), and discovered
that it's important not to return a serial from gateways that don't store
anything (otherwise you can't rename anything without a conflict!)


=== Products/AdaptableStorage/gateway_sql/SQLFolderItems.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/gateway_sql/SQLFolderItems.py:1.2	Tue Dec 10 17:27:00 2002
+++ Products/AdaptableStorage/gateway_sql/SQLFolderItems.py	Fri Dec 13 16:21:45 2002
@@ -38,6 +38,9 @@
   (key, name, child_key)
   VALUES (%(key)s, %(name)s, %(child_key)s)'''
 
+delete_sql = '''DELETE FROM %(table)s
+  WHERE key = %(key)s and name = %(name)s'''
+
 clear_sql = '''DELETE FROM %(table)s'''
 
 
@@ -82,10 +85,19 @@
         keychain = event.getKeychain()
         keychain1 = keychain[:-1]
         key = int(keychain[-1])
+        state_dict = {}
+        for name, child_keychain in state:
+            state_dict[name] = 1
+
         rows = self.execute(read_sql, 1, key=key)
-        dict = {}
+        db_dict = {}
         for name, child_key in rows:
-            dict[name] = child_key
+            if state_dict.has_key(name):
+                db_dict[name] = child_key
+            else:
+                # Remove this item from the database.
+                self.execute(delete_sql, key=key, name=name)
+
         state = list(state)
         state.sort()
         for name, child_keychain in state:
@@ -94,10 +106,12 @@
                     "SQLFolderItems cannot store cross-domain references")
             child_key = int(child_keychain[-1])
             kw = {'key': key, 'name': name, 'child_key': child_key}
-            if dict.has_key(name):
-                if dict[name] != child_key:
+            if db_dict.has_key(name):
+                if db_dict[name] != child_key:
+                    # Change the OID of this item.
                     self.execute(update_sql, **kw)
             else:
+                # Add this item to the database.
                 self.execute(insert_sql, **kw)
         return tuple(state)
 


=== Products/AdaptableStorage/gateway_sql/SQLItemId.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/gateway_sql/SQLItemId.py:1.2	Tue Dec 10 17:27:00 2002
+++ Products/AdaptableStorage/gateway_sql/SQLItemId.py	Fri Dec 13 16:21:45 2002
@@ -46,8 +46,8 @@
         rows = self.execute(read_sql, 1, child_key=key)
         assert len(rows) >= 1
         name = rows[0][0]
-        return name, name
+        return name, None
 
     def store(self, event, state):
         # Assume that SQLFolderItems stored or will store the name.
-        return state
+        return None