From faa9b2c8da63aa116579fc6c43a30ce479b92ac2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 22 Jul 2012 16:36:29 -0400 Subject: - [feature] Revised the rules used to determine the operator precedence for the user-defined operator, i.e. that granted using the ``op()`` method. Previously, the smallest precedence was applied in all cases, now the default precedence is zero, lower than all operators except "comma" (such as, used in the argument list of a ``func`` call) and "AS", and is also customizable via the "precedence" argument on the ``op()`` method. [ticket:2537] --- lib/sqlalchemy/sql/compiler.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 3304cff43..2588de6b4 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -663,15 +663,16 @@ class SQLCompiler(engine.Compiled): (' ESCAPE ' + self.render_literal_value(escape, None)) or '') + def visit_custom_op(self, element, dispatch_operator, dispatch_fn, **kw): + return dispatch_fn(" " + dispatch_operator.opstring + " ") + def _operator_dispatch(self, operator, element, fn, **kw): - if util.callable(operator): - disp = getattr(self, "visit_%s" % operator.__name__, None) - if disp: - return disp(element, **kw) - else: - return fn(OPERATORS[operator]) + disp = getattr(self, "visit_%s" % operator.__name__, None) + if disp: + kw.update(dispatch_operator=operator, dispatch_fn=fn) + return disp(element, **kw) else: - return fn(" " + operator + " ") + return fn(OPERATORS[operator]) def visit_bindparam(self, bindparam, within_columns_clause=False, literal_binds=False, **kwargs): -- cgit v1.2.1