summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-08-18 12:40:18 -0400
committerStefan Urbanek <stefan@agentfarms.net>2015-08-25 23:56:12 -0700
commitc18f616b930eefd6b3fa39aadecb7b8a198707f7 (patch)
treefb2513e46b98ffc417b8e3725ec545b87182e265
parent473ebd8d8aa58d354f76b8d896d095059f88cfd3 (diff)
downloadsqlalchemy-c18f616b930eefd6b3fa39aadecb7b8a198707f7.tar.gz
- as the Concatenable mixin was changed to support calling down to
"super" instead of hardcoding to "self.type" for the default return value, the base Comparator was returning other_comparator.type. It's not clear what the rationale for this was, though in theory the base Comparator should possibly even throw an exception if the two types aren't the same (or of the same affinity?) . - mysql.SET was broken on this because the bitwise version adds "0" to the value to force an integer within column_expression, we are doing type_coerces here now in any case so that there is no type ambiguity for this operation
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py5
-rw-r--r--lib/sqlalchemy/sql/type_api.py2
-rw-r--r--test/sql/test_operators.py56
3 files changed, 60 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index 33cffb140..733610505 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -1584,7 +1584,10 @@ class SET(_EnumeratedValues):
def column_expression(self, colexpr):
if self.retrieve_as_bitwise:
- return colexpr + 0
+ return sql.type_coerce(
+ sql.type_coerce(colexpr, sqltypes.Integer) + 0,
+ self
+ )
else:
return colexpr
diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py
index 701e2a44a..c4e830b7f 100644
--- a/lib/sqlalchemy/sql/type_api.py
+++ b/lib/sqlalchemy/sql/type_api.py
@@ -91,7 +91,7 @@ class TypeEngine(Visitable):
boolean comparison or special SQL keywords like MATCH or BETWEEN.
"""
- return op, other_comparator.type
+ return op, self.type
def __reduce__(self):
return _reconstitute_comparator, (self.expr, )
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index fbbdd7b62..f3dfd2daf 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -14,7 +14,7 @@ from sqlalchemy.sql.elements import _literal_as_text
from sqlalchemy.schema import Column, Table, MetaData
from sqlalchemy.sql import compiler
from sqlalchemy.types import TypeEngine, TypeDecorator, UserDefinedType, \
- Boolean, NullType, MatchType, Indexable
+ Boolean, NullType, MatchType, Indexable, Concatenable
from sqlalchemy.dialects import mysql, firebird, postgresql, oracle, \
sqlite, mssql
from sqlalchemy import util
@@ -210,6 +210,60 @@ class DefaultColumnComparatorTest(fixtures.TestBase):
def test_concat(self):
self._do_operate_test(operators.concat_op)
+ def test_default_adapt(self):
+ class TypeOne(TypeEngine):
+ pass
+
+ class TypeTwo(TypeEngine):
+ pass
+
+ expr = column('x', TypeOne()) - column('y', TypeTwo())
+ is_(
+ expr.type._type_affinity, TypeOne
+ )
+
+ def test_concatenable_adapt(self):
+ class TypeOne(Concatenable, TypeEngine):
+ pass
+
+ class TypeTwo(Concatenable, TypeEngine):
+ pass
+
+ class TypeThree(TypeEngine):
+ pass
+
+ expr = column('x', TypeOne()) - column('y', TypeTwo())
+ is_(
+ expr.type._type_affinity, TypeOne
+ )
+ is_(
+ expr.operator, operator.sub
+ )
+
+ expr = column('x', TypeOne()) + column('y', TypeTwo())
+ is_(
+ expr.type._type_affinity, TypeOne
+ )
+ is_(
+ expr.operator, operators.concat_op
+ )
+
+ expr = column('x', TypeOne()) - column('y', TypeThree())
+ is_(
+ expr.type._type_affinity, TypeOne
+ )
+ is_(
+ expr.operator, operator.sub
+ )
+
+ expr = column('x', TypeOne()) + column('y', TypeThree())
+ is_(
+ expr.type._type_affinity, TypeOne
+ )
+ is_(
+ expr.operator, operator.add
+ )
+
class CustomUnaryOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__dialect__ = 'default'