From: Mike Bayer Date: Thu, 20 Dec 2007 01:45:36 +0000 (+0000) Subject: - sqlite SLDate type will not erroneously render "microseconds" portion X-Git-Tag: rel_0_4_2~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=267523e4da6a6575fae507eabd003e975fc7094f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - sqlite SLDate type will not erroneously render "microseconds" portion of a datetime or time object when sent to the DB. --- diff --git a/CHANGES b/CHANGES index 081ba89dba..85acf228d3 100644 --- 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] diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index e028b1c539..0d673e9ab6 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -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" diff --git a/test/sql/testtypes.py b/test/sql/testtypes.py index 59acaff2ff..cb6a3385f5 100644 --- a/test/sql/testtypes.py +++ b/test/sql/testtypes.py @@ -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)