mirror / sqlalchemy (http://svn.sqlalchemy.org/sqlalchemy/trunk/)
Mirror of the SQLAlchemy trunk.
$ hg clone http://bitbucket.org/mirror/sqlalchemy/
| commit 4802: | 909378d5ac41 |
| parent 4801: | ca142a6be8ff |
| branch: | default |
Changed (Δ799 bytes):
CHANGES (4 lines added, 0 lines removed)
lib/sqlalchemy/sql/compiler.py (1 lines added, 0 lines removed)
lib/sqlalchemy/sql/expression.py (6 lines added, 0 lines removed)
lib/sqlalchemy/sql/operators.py (2 lines added, 1 lines removed)
test/orm/test_query.py (4 lines added, 0 lines removed)
test/sql/test_select.py (14 lines added, 1 lines removed)
3 |
3 |
======= |
4 |
4 |
CHANGES |
5 |
5 |
======= |
6 |
0.6beta2 |
|
7 |
- sql |
|
8 |
- Added math negation operator support, -x. |
|
9 |
||
6 |
10 |
0.6beta1 |
7 |
11 |
======== |
8 |
12 |
- Major Release |
Up to file-list lib/sqlalchemy/sql/compiler.py:
| … | … | @@ -73,6 +73,7 @@ OPERATORS = { |
73 |
73 |
# end Py2K |
74 |
74 |
operators.mod : ' % ', |
75 |
75 |
operators.truediv : ' / ', |
76 |
operators.neg : '-', |
|
76 |
77 |
operators.lt : ' < ', |
77 |
78 |
operators.le : ' <= ', |
78 |
79 |
operators.ne : ' != ', |
Up to file-list lib/sqlalchemy/sql/expression.py:
| … | … | @@ -1363,6 +1363,9 @@ class ColumnOperators(Operators): |
1363 |
1363 |
def __ge__(self, other): |
1364 |
1364 |
return self.operate(operators.ge, other) |
1365 |
1365 |
|
1366 |
def __neg__(self): |
|
1367 |
return self.operate(operators.neg) |
|
1368 |
||
1366 |
1369 |
def concat(self, other): |
1367 |
1370 |
return self.operate(operators.concat_op, other) |
1368 |
1371 |
|
| … | … | @@ -1537,6 +1540,9 @@ class _CompareMixin(ColumnOperators): |
1537 |
1540 |
|
1538 |
1541 |
return self.__compare(op, ClauseList(*args).self_group(against=op), negate=negate_op) |
1539 |
1542 |
|
1543 |
def __neg__(self): |
|
1544 |
return _UnaryExpression(self, operator=operators.neg) |
|
1545 |
||
1540 |
1546 |
def startswith(self, other, escape=None): |
1541 |
1547 |
"""Produce the clause ``LIKE '<other>%'``""" |
1542 |
1548 |
Up to file-list lib/sqlalchemy/sql/operators.py:
4 |
4 |
"""Defines operators used in SQL expressions.""" |
5 |
5 |
|
6 |
6 |
from operator import ( |
7 |
and_, or_, inv, add, mul, sub, mod, truediv, lt, le, ne, gt, ge, eq |
|
7 |
and_, or_, inv, add, mul, sub, mod, truediv, lt, le, ne, gt, ge, eq, neg |
|
8 |
8 |
) |
9 |
9 |
|
10 |
10 |
# Py2K |
| … | … | @@ -98,6 +98,7 @@ _PRECEDENCE = { |
98 |
98 |
div: 7, |
99 |
99 |
# end Py2K |
100 |
100 |
mod: 7, |
101 |
neg: 7, |
|
101 |
102 |
add: 6, |
102 |
103 |
sub: 6, |
103 |
104 |
concat_op: 6, |
Up to file-list test/orm/test_query.py:
| … | … | @@ -480,6 +480,10 @@ class OperatorTest(QueryTest, AssertsCom |
480 |
480 |
|
481 |
481 |
def test_in_on_relation_not_supported(self): |
482 |
482 |
assert_raises(NotImplementedError, Address.user.in_, [User(id=5)]) |
483 |
||
484 |
def test_neg(self): |
|
485 |
self._test(-User.id, "-users.id") |
|
486 |
self._test(User.id + -User.id, "users.id + -users.id") |
|
483 |
487 |
|
484 |
488 |
def test_between(self): |
485 |
489 |
self._test(User.id.between('a', 'b'), |
Up to file-list test/sql/test_select.py:
| … | … | @@ -568,7 +568,20 @@ sq.myothertable_othername AS sq_myothert |
568 |
568 |
self.assert_(compiled == fwd_sql or compiled == rev_sql, |
569 |
569 |
"\n'" + compiled + "'\n does not match\n'" + |
570 |
570 |
fwd_sql + "'\n or\n'" + rev_sql + "'") |
571 |
||
571 |
||
572 |
for (py_op, op) in ( |
|
573 |
(operator.neg, '-'), |
|
574 |
(operator.inv, 'NOT '), |
|
575 |
): |
|
576 |
for expr, sql in ( |
|
577 |
(table1.c.myid, "mytable.myid"), |
|
578 |
(literal("foo"), ":param_1"), |
|
579 |
): |
|
580 |
||
581 |
compiled = str(py_op(expr)) |
|
582 |
sql = "%s%s" % (op, sql) |
|
583 |
eq_(compiled, sql) |
|
584 |
||
572 |
585 |
self.assert_compile( |
573 |
586 |
table1.select((table1.c.myid != 12) & ~(table1.c.name=='john')), |
574 |
587 |
"SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid != :myid_1 AND mytable.name != :name_1" |
