]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- sqlite SLDate type will not erroneously render "microseconds" portion
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Dec 2007 01:45:36 +0000 (01:45 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Dec 2007 01:45:36 +0000 (01:45 +0000)
of a datetime or time object when sent to the DB.

CHANGES
lib/sqlalchemy/databases/sqlite.py
test/sql/testtypes.py

diff --git a/CHANGES b/CHANGES
index 081ba89dba77a75f94ee25e134de9f204a2c0caf..85acf228d3d8837d10a65cbdc4679661d697dfac 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -226,6 +226,9 @@ CHANGES
 
 - dialects
 
+   - sqlite SLDate type will not erroneously render "microseconds" portion 
+     of a datetime or time object.
+     
    - MSSQL
       - PyODBC no longer has a global "set nocount on".
       - Fix non-identity integer PKs on autload [ticket:824]
index e028b1c539b65417dddd5b9cfb78ea2e2900a758..0d673e9ab629952280780b34a14b35443492dab9 100644 (file)
@@ -50,7 +50,7 @@ class DateTimeMixin(object):
                 # pass string values thru
                 return value
             elif value is not None:
-                if getattr(value, 'microsecond', None) is not None:
+                if self.__microsecond__ and getattr(value, 'microsecond', None) is not None:
                     return value.strftime(self.__format__ + "." + str(value.microsecond))
                 else:
                     return value.strftime(self.__format__)
@@ -70,6 +70,7 @@ class DateTimeMixin(object):
 
 class SLDateTime(DateTimeMixin,sqltypes.DateTime):
     __format__ = "%Y-%m-%d %H:%M:%S"
+    __microsecond__ = True
     
     def get_col_spec(self):
         return "TIMESTAMP"
@@ -82,6 +83,7 @@ class SLDateTime(DateTimeMixin,sqltypes.DateTime):
         
 class SLDate(DateTimeMixin, sqltypes.Date):
     __format__ = "%Y-%m-%d"
+    __microsecond__ = False
 
     def get_col_spec(self):
         return "DATE"
@@ -94,6 +96,7 @@ class SLDate(DateTimeMixin, sqltypes.Date):
         
 class SLTime(DateTimeMixin, sqltypes.Time):
     __format__ = "%H:%M:%S"
+    __microsecond__ = True
 
     def get_col_spec(self):
         return "TIME"
index 59acaff2fff10ce300b42f55ccdd1e4e4f0197ba..cb6a3385f58e9fe4f15998cd8e9823aeb3b637d3 100644 (file)
@@ -616,6 +616,13 @@ class DateTest(AssertMixin):
             self.assert_(x.adate.__class__ == datetime.date)
             self.assert_(x.adatetime.__class__ == datetime.datetime)
 
+            t.delete().execute()
+            
+            # test mismatched date/datetime
+            t.insert().execute(adate=d2, adatetime=d2)
+            self.assertEquals(select([t.c.adate, t.c.adatetime], t.c.adate==d1).execute().fetchall(), [(d1, d2)])
+            self.assertEquals(select([t.c.adate, t.c.adatetime], t.c.adate==d1).execute().fetchall(), [(d1, d2)])
+            
         finally:
             t.drop(checkfirst=True)