[Zope-CVS] CVS: Products/Ape/lib/apelib/sql - dbapi.py:1.10 properties.py:1.11

Shane Hathaway shane at zope.com
Thu Mar 25 22:32:26 EST 2004


Update of /cvs-repository/Products/Ape/lib/apelib/sql
In directory cvs.zope.org:/tmp/cvs-serv25695/lib/apelib/sql

Modified Files:
	dbapi.py properties.py 
Log Message:
Augmented the fixed property tests and fixed the breakage.

Some property types are not safely portable to databases, especially
floats and dates.  MySQL, for instance, doesn't have the
date-with-timezone type that Zope 2 needs for storing DateTime objects.
To be safe, the fixed property table code now only creates certain kinds
of columns, placing the rest in the variable properties table.



=== Products/Ape/lib/apelib/sql/dbapi.py 1.9 => 1.10 ===
--- Products/Ape/lib/apelib/sql/dbapi.py:1.9	Wed Mar 24 22:17:08 2004
+++ Products/Ape/lib/apelib/sql/dbapi.py	Thu Mar 25 22:31:52 2004
@@ -388,7 +388,7 @@
         'long':   'bigint',
         'string': 'character varying(255)',
         'blob':   'bytea',
-        'date_international': 'date',
+        'datetime': 'timestamp',
         }
 
     column_name_translations = {
@@ -450,7 +450,6 @@
         'long':   'bigint',
         'string': 'character varying(255)',
         'blob':   'longblob',
-        'date_international': 'date',
         'boolean': 'tinyint(1)',
         }
 


=== Products/Ape/lib/apelib/sql/properties.py 1.10 => 1.11 ===
--- Products/Ape/lib/apelib/sql/properties.py:1.10	Wed Mar 24 23:28:22 2004
+++ Products/Ape/lib/apelib/sql/properties.py	Thu Mar 25 22:31:52 2004
@@ -21,6 +21,23 @@
 from sqlbase import SQLGatewayBase
 
 
+# safe_property_types lists the property types that are safe to store
+# in table columns.  Floats are not permitted because their value can
+# change when converting to/from strings.  Dates (based on Zope's
+# DateTime class) are not permitted because their precision is not
+# well defined, some databases don't store time zones, and Zope's
+# DateTime class is hard to convert to other date/time types without
+# losing information.
+
+safe_property_types = {
+    'string': 1,
+    'int': 1,
+    'long': 1,
+    'text': 1,
+    'boolean': 1,
+    }
+
+
 class SQLProperties (SQLGatewayBase):
     """SQL properties gateway
     """
@@ -73,7 +90,7 @@
             return (), ()
         if len(recs) > 1:
             raise ValueError("Multiple records where only one expected")
-        record = recs[0]
+        record = [str(value) for value in recs[0]]
         items = []
         cols = self.column_defs
         for n in range(len(cols)):
@@ -83,7 +100,7 @@
             else:
                 prop_name = name
             items.append((prop_name, typ, record[n]))
-        return items, tuple([str(value) for value in record])
+        return items, tuple(record)
 
 
     def store(self, event, state, leftover=None):
@@ -91,7 +108,6 @@
         statedict = {}  # prop name -> (type, value)
         for name, typ, value in state:
             statedict[name] = (typ, value)
-        data = {}
         record = []
         for col in cols:
             name = col[0]
@@ -100,13 +116,11 @@
             else:
                 prop_name = name
             if statedict.has_key(prop_name):
-                value = statedict[prop_name][1]
+                typ, value = statedict[prop_name]
                 record.append(str(value))
-                data[name] = value
                 del statedict[prop_name]
             else:
-                record.append(None)
-                data[name] = None  # Hopefully this translates to NULL.
+                record.append(None)  # Hopefully this translates to null.
         if statedict:
             if leftover is not None:
                 # Pass back a dictionary of properties not stored yet.
@@ -170,6 +184,10 @@
         if not props:
             return None
         for p in props:
+            if not safe_property_types.has_key(p['type']):
+                # Don't store this property in its own column.
+                # It is of a type that's hard to convert faithfully.
+                continue
             prop_name = p['id']
             if prop_name == 'oid':
                 name = '_oid'




More information about the Zope-CVS mailing list