From 4a66683c9f7853370849b78a1cb8adb6db1687f2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 27 Jun 2008 20:12:11 +0000 Subject: - Modified SQLite's representation of "microseconds" to match the output of str(somedatetime), i.e. in that the microseconds are represented as fractional seconds in string format. [ticket:1090] - implemented a __legacy_microseconds__ flag on DateTimeMixin which can be used per-class or per-type instances to get the old behavior, for compatibility with existing SQLite databases encoded by a previous version of SQLAlchemy. - will implement the reverse legacy behavior in 0.4. --- lib/sqlalchemy/databases/sqlite.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/databases/sqlite.py') diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 1b85fb016..4f1fa9da5 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -42,7 +42,8 @@ class SLSmallInteger(sqltypes.Smallinteger): class DateTimeMixin(object): __format__ = "%Y-%m-%d %H:%M:%S" - + __legacy_microseconds__ = False + def bind_processor(self, dialect): def process(value): if isinstance(value, basestring): @@ -50,7 +51,10 @@ class DateTimeMixin(object): return value elif value is not None: if self.__microsecond__ and getattr(value, 'microsecond', None) is not None: - return value.strftime(self.__format__ + "." + str(value.microsecond)) + if self.__legacy_microseconds__: + return value.strftime(self.__format__ + '.' + str(value.microsecond)) + else: + return value.strftime(self.__format__ + ('.%06d' % value.microsecond)) else: return value.strftime(self.__format__) else: @@ -62,7 +66,10 @@ class DateTimeMixin(object): return None try: (value, microsecond) = value.split('.') - microsecond = int(microsecond) + if self.__legacy_microseconds__: + microsecond = int(microsecond) + else: + microsecond = int((microsecond + '000000')[0:6]) except ValueError: microsecond = 0 return time.strptime(value, self.__format__)[0:6] + (microsecond,) -- cgit v1.2.1