[sql] preprocess_entity uses lgdb helper's SQL converters.
authorVincent Michel <vincent.michel@logilab.fr>
Tue, 23 Apr 2013 14:13:58 +0200
changeset 8944 b167f039b6cb
parent 8943 58b3b2d9c965
child 8945 ba9e3fbfa5a5
[sql] preprocess_entity uses lgdb helper's SQL converters. The preprocess_entity does not yield anymore the conversion logic for different base types, but relies on a new SQL_CONVERTERS dictionary of the db helper. This will allow later inclusion of new base types.
__pkginfo__.py
debian/control
server/sqlutils.py
--- a/__pkginfo__.py	Wed Apr 24 14:42:43 2013 +0200
+++ b/__pkginfo__.py	Tue Apr 23 14:13:58 2013 +0200
@@ -51,7 +51,7 @@
     'Twisted': '',
     # XXX graphviz
     # server dependencies
-    'logilab-database': '>= 1.8.2',
+    'logilab-database': '>= 1.10',
     'pysqlite': '>= 2.5.5', # XXX install pysqlite2
     'passlib': '',
     }
--- a/debian/control	Wed Apr 24 14:42:43 2013 +0200
+++ b/debian/control	Tue Apr 23 14:13:58 2013 +0200
@@ -42,7 +42,7 @@
 Conflicts: cubicweb-multisources
 Replaces: cubicweb-multisources
 Provides: cubicweb-multisources
-Depends: ${misc:Depends}, ${python:Depends}, cubicweb-common (= ${source:Version}), cubicweb-ctl (= ${source:Version}), python-logilab-database (>= 1.8.2), cubicweb-postgresql-support | cubicweb-mysql-support | python-pysqlite2, python-passlib
+Depends: ${misc:Depends}, ${python:Depends}, cubicweb-common (= ${source:Version}), cubicweb-ctl (= ${source:Version}), python-logilab-database (>= 1.10.0), cubicweb-postgresql-support | cubicweb-mysql-support | python-pysqlite2, python-passlib
 Recommends: pyro (<< 4.0.0), cubicweb-documentation (= ${source:Version})
 Suggests: python-zmq
 Description: server part of the CubicWeb framework
--- a/server/sqlutils.py	Wed Apr 24 14:42:43 2013 +0200
+++ b/server/sqlutils.py	Tue Apr 23 14:13:58 2013 +0200
@@ -297,12 +297,16 @@
         """
         attrs = {}
         eschema = entity.e_schema
+        converters = getattr(self.dbhelper, 'TYPE_CONVERTERS', {})
         for attr, value in entity.cw_edited.iteritems():
             if value is not None and eschema.subjrels[attr].final:
                 atype = str(entity.e_schema.destination(attr))
-                if atype == 'Boolean':
-                    value = self.dbhelper.boolean_value(value)
-                elif atype == 'Password':
+                if atype in converters:
+                    # It is easier to modify preprocess_entity rather
+                    # than add_entity (native) as this behavior
+                    # may also be used for update.
+                    value = converters[atype](value)
+                elif atype == 'Password': # XXX could be done using a TYPE_CONVERTERS callback
                     # if value is a Binary instance, this mean we got it
                     # from a query result and so it is already encrypted
                     if isinstance(value, Binary):
@@ -310,16 +314,6 @@
                     else:
                         value = crypt_password(value)
                     value = self._binary(value)
-                # XXX needed for sqlite but I don't think it is for other backends
-                # Note: use is __class__ since issubclass(datetime, date)
-                elif atype in ('Datetime', 'TZDatetime') and type(value) is date:
-                    value = todatetime(value)
-                elif atype == 'Date' and isinstance(value, datetime):
-                    value = todate(value)
-                elif atype == 'TZDatetime' and getattr(value, 'tzinfo', None):
-                    value = utcdatetime(value)
-                elif atype == 'TZTime' and getattr(value, 'tzinfo', None):
-                    value = utctime(value)
                 elif isinstance(value, Binary):
                     value = self._binary(value.getvalue())
             attrs[SQL_PREFIX+str(attr)] = value