summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--lib/sqlalchemy/types.py36
2 files changed, 24 insertions, 15 deletions
diff --git a/CHANGES b/CHANGES
index e33c33854..2187433a6 100644
--- 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
----------
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 02e36e0f3..1f18201d7 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -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