]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
similar type optimization for the Interval type
authorGaëtan de Menten <gdementen@gmail.com>
Wed, 10 Oct 2007 16:15:29 +0000 (16:15 +0000)
committerGaëtan de Menten <gdementen@gmail.com>
Wed, 10 Oct 2007 16:15:29 +0000 (16:15 +0000)
CHANGES
lib/sqlalchemy/types.py

diff --git a/CHANGES b/CHANGES
index e33c3385490a347ca5a8c4f95d3de7aee69522e2..2187433a6d5d23ca04e52209338d141ced0b1067 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -58,7 +58,8 @@ CHANGES
 
 - fixed Oracle non-ansi join syntax
 
-- The PickleType is now slightly faster.
+- PickleType and Interval types (on db not supporting it natively) are now 
+  slightly faster.
 
 0.4.0beta6
 ----------
index 02e36e0f343c2b3dd7bdadd4edd395b4a3283983..1f18201d7f8651716da599eba1939f9fa9806490 100644 (file)
@@ -535,14 +535,17 @@ class Interval(TypeDecorator):
         if self.__hasNativeImpl(dialect):
             return impl_processor
         else:
-            def process(value):
-                if value is None:
-                    return None
-                tmpval = dt.datetime.utcfromtimestamp(0) + value
-                if impl_processor is not None:
-                    return impl_processor(tmpval)
-                else:
-                    return tmpval
+            zero_timestamp = dt.datetime.utcfromtimestamp(0)
+            if impl_processor is None:
+                def process(value):
+                    if value is None:
+                        return None
+                    return zero_timestamp + value
+            else:
+                def process(value):
+                    if value is None:
+                        return None
+                    return impl_processor(zero_timestamp + value)
             return process
             
     def result_processor(self, dialect):
@@ -550,12 +553,17 @@ class Interval(TypeDecorator):
         if self.__hasNativeImpl(dialect):
             return impl_processor
         else:
-            def process(value):
-                if value is None:
-                    return None
-                if impl_processor is not None:
-                    value = impl_processor(value)
-                return value - dt.datetime.utcfromtimestamp(0)
+            zero_timestamp = dt.datetime.utcfromtimestamp(0)
+            if impl_processor is None:
+                def process(value):
+                    if value is None:
+                        return None
+                    return value - zero_timestamp
+            else:
+                def process(value):
+                    if value is None:
+                        return None
+                    return impl_processor(value) - zero_timestamp
             return process
             
 class FLOAT(Float):pass