From ea46e556f9f691735bc14885648a92e8cf7177d5 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 10 Nov 2007 03:02:16 +0000 Subject: - anonymous column expressions are automatically labeled. e.g. select([x* 5]) produces "SELECT x * 5 AS anon_1". This allows the labelname to be present in the cursor.description which can then be appropriately matched to result-column processing rules. (we can't reliably use positional tracking for result-column matches since text() expressions may represent multiple columns). - operator overloading is now controlled by TypeEngine objects - the one built-in operator overload so far is String types overloading '+' to be the string concatenation operator. User-defined types can also define their own operator overloading by overriding the adapt_operator(self, op) method. - untyped bind parameters on the right side of a binary expression will be assigned the type of the left side of the operation, to better enable the appropriate bind parameter processing to take effect [ticket:819] --- lib/sqlalchemy/sql/expression.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/sqlalchemy/sql/expression.py') diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index e066632af..7c42ae9a2 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1200,11 +1200,7 @@ class _CompareMixin(ColumnOperators): type_ = self._compare_type(obj) - # TODO: generalize operator overloading like this out into the - # types module - if op == operators.add and isinstance(type_, (sqltypes.Concatenable)): - op = operators.concat_op - return _BinaryExpression(self.expression_element(), obj, op, type_=type_) + return _BinaryExpression(self.expression_element(), obj, type_.adapt_operator(op), type_=type_) # a mapping of operators with the method they use, along with their negated # operator for comparison operators @@ -1289,7 +1285,10 @@ class _CompareMixin(ColumnOperators): return self.__compare(operators.like_op, po) def label(self, name): - """Produce a column label, i.e. `` AS ``""" + """Produce a column label, i.e. `` AS ``. + + if 'name' is None, an anonymous label name will be generated. + """ return _Label(name, self, self.type) def desc(self): @@ -1333,7 +1332,10 @@ class _CompareMixin(ColumnOperators): return _BindParamClause('literal', obj, type_=self.type, unique=True) def _check_literal(self, other): - if isinstance(other, Operators): + if isinstance(other, _BindParamClause) and isinstance(other.type, sqltypes.NullType): + other.type = self.type + return other + elif isinstance(other, Operators): return other.expression_element() elif _is_literal(other): return self._bind_param(other) -- cgit v1.2.1