[server] fix SQLite patch to ensure TZDatetime are properly typed
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 18 Dec 2015 09:37:15 +0100
changeset 11032 38afb7e23c6c
parent 11031 780939fc06da
child 11033 63d860a14a17
[server] fix SQLite patch to ensure TZDatetime are properly typed NB: at this point, the TZ info is completely ignored. It will be properly handled in later commits.
server/sqlutils.py
server/test/unittest_querier.py
--- a/server/sqlutils.py	Fri Dec 18 09:10:20 2015 +0100
+++ b/server/sqlutils.py	Fri Dec 18 09:37:15 2015 +0100
@@ -495,7 +495,8 @@
                 found_date = False
                 for row, rowdesc in zip(rset, rset.description):
                     for cellindex, (value, vtype) in enumerate(zip(row, rowdesc)):
-                        if vtype in ('Date', 'Datetime') and isinstance(value, text_type):
+                        if vtype in ('TZDatetime', 'Date', 'Datetime') \
+                           and isinstance(value, text_type):
                             found_date = True
                             value = value.rsplit('.', 1)[0]
                             try:
--- a/server/test/unittest_querier.py	Fri Dec 18 09:10:20 2015 +0100
+++ b/server/test/unittest_querier.py	Fri Dec 18 09:37:15 2015 +0100
@@ -847,7 +847,13 @@
         self.assertIsInstance(rset.rows[0][0], datetime)
         rset = self.qexecute('Tag X WHERE X creation_date TODAY')
         self.assertEqual(len(rset.rows), 2)
-        rset = self.qexecute('Any MAX(D) WHERE X is Tag, X creation_date D')
+
+    def test_sqlite_patch(self):
+        """this test monkey patch done by sqlutils._install_sqlite_querier_patch"""
+        self.qexecute("INSERT Personne X: X nom 'bidule', X datenaiss NOW, X tzdatenaiss NOW")
+        rset = self.qexecute('Any MAX(D) WHERE X is Personne, X datenaiss D')
+        self.assertIsInstance(rset[0][0], datetime)
+        rset = self.qexecute('Any MAX(D) WHERE X is Personne, X tzdatenaiss D')
         self.assertIsInstance(rset[0][0], datetime)
 
     def test_today(self):