]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Workaround for datetime quirk, LHS comparisons to SA expressions now work.
authorJason Kirtland <jek@discorporate.us>
Thu, 31 Jan 2008 21:32:38 +0000 (21:32 +0000)
committerJason Kirtland <jek@discorporate.us>
Thu, 31 Jan 2008 21:32:38 +0000 (21:32 +0000)
CHANGES
lib/sqlalchemy/sql/expression.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index 5ef21fa2468506523af546c99d82720fcb6cd8fd..6070b97d8b731a183e9f3c72dc04e005c45d0257 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -13,7 +13,7 @@ CHANGES
       now concatenate the wildcard operator with the given
       operand in SQL, i.e. "'%' || <bindparam>" in all cases,
       accept text('something') operands properly [ticket:962]
-      
+
     - cast() accepts text('something') and other non-literal
       operands properly [ticket:962]
 
@@ -24,7 +24,7 @@ CHANGES
       DELETE etc., this flag will enable "autocommit" behavior
       during execution if no transaction is in progress 
       [ticket:915]
-      
+
     - The '.c.' attribute on a selectable now gets an entry
       for every column expression in its columns clause.
       Previously, "unnamed" columns like functions and CASE
@@ -46,12 +46,17 @@ CHANGES
       up their ".c." collection based on the names present in
       the first selectable only; corresponding_column() now
       works fully for all embedded selectables.
-    
+
     - Oracle and others properly encode SQL used for defaults
       like sequences, etc., even if no unicode idents are used
       since identifier preparer may return a cached unicode
       identifier.
-      
+
+    - Column and clause comparisons to datetime objects on the
+      left hand side of the expression now work (d < table.c.col).
+      (datetimes on the RHS have always worked, the LHS exception
+      is a quirk of the datetime implementation.)
+
 - orm
     - Every Session.begin() must now be accompanied by a 
       corresponding commit() or rollback() unless the session
index ee867a2f9c63c9f4493cf442d40e5e7ed093c154..c0b46a182331d6042489220cedf3fe6d50caa58c 100644 (file)
@@ -1111,6 +1111,9 @@ class Operators(object):
 class ColumnOperators(Operators):
     """Defines comparison and math operations."""
 
+    timetuple = None
+    """Hack, allows datetime objects to be compared on the LHS."""
+
     def __lt__(self, other):
         return self.operate(operators.lt, other)
 
index 522f9a2ffd5d80ed4196e70a6e083084d65cadba..3585a2cd7ccd8064d3b237f3c5027c8f2342d011 100644 (file)
@@ -1,5 +1,5 @@
 import testenv; testenv.configure_for_tests()
-import re, operator
+import datetime, re, operator
 from sqlalchemy import *
 from sqlalchemy import exceptions, sql, util
 from sqlalchemy.sql import table, column
@@ -387,6 +387,7 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
                 ):
                 self.assert_compile(py_op(lhs, rhs), res % sql_op)
 
+        dt = datetime.datetime.today()
         # exercise comparison operators
         for (py_op, fwd_op, rev_op) in ((operator.lt, '<', '>'),
                                         (operator.gt, '>', '<'),
@@ -403,6 +404,8 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
                 (literal('a'), 'b', ':param_1', ':param_2'),
                 (literal('a'), table1.c.myid, ':param_1', 'mytable.myid'),
                 (literal('a'), literal('b'), ':param_1', ':param_2'),
+                (dt, literal('b'), ':param_2', ':param_1'),
+                (literal('b'), dt, ':param_1', ':param_2'),
                 ):
 
                 # the compiled clause should match either (e.g.):