diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-17 13:37:39 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-29 11:54:25 -0400 |
| commit | 099522075088a3e1a333a2285c10a8a33b203c19 (patch) | |
| tree | b1359c9ff50d19e4787d8ead0bfe5b03ad1fb69a /lib/sqlalchemy/sql/functions.py | |
| parent | 2f55c844051d9fe8865576bd77107e94c6de16c1 (diff) | |
| download | sqlalchemy-099522075088a3e1a333a2285c10a8a33b203c19.tar.gz | |
Reimplement .compare() in terms of a visitor
Reworked the :meth:`.ClauseElement.compare` methods in terms of a new
visitor-based approach, and additionally added test coverage ensuring that
all :class:`.ClauseElement` subclasses can be accurately compared
against each other in terms of structure. Structural comparison
capability is used to a small degree within the ORM currently, however
it also may form the basis for new caching features.
Fixes: #4336
Change-Id: I581b667d8e1642a6c27165cc9f4aded1c66effc6
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
| -rw-r--r-- | lib/sqlalchemy/sql/functions.py | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index fcc843d91..f48a20ec7 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -74,7 +74,9 @@ class FunctionElement(Executable, ColumnElement, FromClause): def __init__(self, *clauses, **kwargs): """Construct a :class:`.FunctionElement`. """ - args = [_literal_as_binds(c, self.name) for c in clauses] + args = [ + _literal_as_binds(c, getattr(self, "name", None)) for c in clauses + ] self._has_args = self._has_args or bool(args) self.clause_expr = ClauseList( operator=operators.comma_op, group_contents=True, *args @@ -376,12 +378,11 @@ class FunctionAsBinary(BinaryExpression): self.left_index = left_index self.right_index = right_index - super(FunctionAsBinary, self).__init__( - left, - right, - operators.function_as_comparison_op, - type_=sqltypes.BOOLEANTYPE, - ) + self.operator = operators.function_as_comparison_op + self.type = sqltypes.BOOLEANTYPE + self.negate = None + self._is_implicitly_boolean = True + self.modifiers = {} @property def left(self): @@ -399,10 +400,11 @@ class FunctionAsBinary(BinaryExpression): def right(self, value): self.sql_function.clauses.clauses[self.right_index - 1] = value - def _copy_internals(self, **kw): - clone = kw.pop("clone") + def _copy_internals(self, clone=_clone, **kw): self.sql_function = clone(self.sql_function, **kw) - super(FunctionAsBinary, self)._copy_internals(**kw) + + def get_children(self, **kw): + yield self.sql_function class _FunctionGenerator(object): @@ -682,6 +684,18 @@ class next_value(GenericFunction): self._bind = kw.get("bind", None) self.sequence = seq + def compare(self, other, **kw): + return ( + isinstance(other, next_value) + and self.sequence.name == other.sequence.name + ) + + def get_children(self, **kwargs): + return [] + + def _copy_internals(self, **kw): + pass + @property def _from_objects(self): return [] |
