]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- adjusted operator precedence of NOT to match '==' and others, so that
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 8 Sep 2007 20:28:26 +0000 (20:28 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 8 Sep 2007 20:28:26 +0000 (20:28 +0000)
  ~(x <operator> y) produces NOT (x <op> y), which is better compatible with MySQL.
   [ticket:764].  this doesn't apply to "~(x==y)" as it does in 0.3 since ~(x==y)
   compiles to "x != y", but still applies to operators like BETWEEN.

CHANGES
lib/sqlalchemy/sql/expression.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index fe43273003a1fb57768737d1d5f0e331b747df40..efcc57e70a8241f6813919d58144acdca0576ea3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,11 @@ CHANGES
   and can be used to determine correct shard id (since execute() doesn't
   take an instance) 
 
+- adjusted operator precedence of NOT to match '==' and others, so that 
+  ~(x <operator> y) produces NOT (x <op> y), which is better compatible with MySQL.
+   [ticket:764].  this doesn't apply to "~(x==y)" as it does in 0.3 since ~(x==y)
+   compiles to "x != y", but still applies to operators like BETWEEN.
+
 - other tickets: [ticket:768]
 
 0.4.0beta5
@@ -65,7 +70,7 @@ CHANGES
 
 - postgres reflects tables with autoincrement=False for primary key
   columns which have no defaults.
-    
+      
 - postgres no longer wraps executemany() with 
   individual execute() calls, instead favoring performance.  
   "rowcount"/"concurrency" checks with deleted items (which use executemany) 
index b1a5bf96f189dc85f8062b4af4721386bcd8542e..f7514fec9d74a17db0a36a8a5fdf8cbfc3267edc 100644 (file)
@@ -1159,7 +1159,7 @@ PRECEDENCE = {
     operators.le:5,
     operators.between_op:5,
     operators.distinct_op:5,
-    operators.inv:4,
+    operators.inv:5,
     operators.and_:3,
     operators.or_:2,
     operators.comma_op:-1,
index 6a81310460d43ca7bd319656c1d43a7793acc8d0..1114f17358fa8bae710df8bcdc995c7264992f87 100644 (file)
@@ -339,7 +339,6 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
         )
         
     def testoperators(self):
-
         # exercise arithmetic operators
         for (py_op, sql_op) in ((operator.add, '+'), (operator.mul, '*'),
                                 (operator.sub, '-'), (operator.div, '/'),
@@ -389,6 +388,11 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
          "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid != :mytable_myid AND mytable.name != :mytable_name"
         )
 
+        self.assert_compile(
+         table1.select((table1.c.myid != 12) & ~(table1.c.name.between('jack','john'))), 
+         "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid != :mytable_myid AND NOT (mytable.name BETWEEN :mytable_name AND :mytable_name_1)"
+        )
+
         self.assert_compile(
          table1.select((table1.c.myid != 12) & ~and_(table1.c.name=='john', table1.c.name=='ed', table1.c.name=='fred')), 
          "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid != :mytable_myid AND NOT (mytable.name = :mytable_name AND mytable.name = :mytable_name_1 AND mytable.name = :mytable_name_2)"
@@ -1083,6 +1087,10 @@ UNION SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE
             "SELECT op.field FROM op WHERE :op_field + op.field IN (:literal, :literal_1)")
         self.assert_compile(table.select(not_(and_(table.c.field == 5, table.c.field == 7))),
             "SELECT op.field FROM op WHERE NOT (op.field = :op_field AND op.field = :op_field_1)")
+        self.assert_compile(table.select(not_(table.c.field == 5)),
+            "SELECT op.field FROM op WHERE op.field != :op_field")
+        self.assert_compile(table.select(not_(table.c.field.between(5, 6))),
+            "SELECT op.field FROM op WHERE NOT (op.field BETWEEN :op_field AND :op_field_1)")
         self.assert_compile(table.select(not_(table.c.field) == 5),
             "SELECT op.field FROM op WHERE (NOT op.field) = :literal")
         self.assert_compile(table.select((table.c.field == table.c.field).between(False, True)),