diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-10-21 16:49:46 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-10-21 16:49:46 -0400 |
| commit | 9caa92b96fef0b3e6d9d280407bc6a092a77b584 (patch) | |
| tree | 04100e4b13f32d9c3604a208146dc08a372a8e73 /test | |
| parent | 56976624169af6d0d329b4834ee9caa7243573dc (diff) | |
| download | sqlalchemy-9caa92b96fef0b3e6d9d280407bc6a092a77b584.tar.gz | |
- A :func:`.bindparam` construct with a "null" type (e.g. no type
specified) is now copied when used in a typed expression, and the
new copy is assigned the actual type of the compared column. Previously,
this logic would occur on the given :func:`.bindparam` in place.
Additionally, a similar process now occurs for :func:`.bindparam` constructs
passed to :meth:`.ValuesBase.values` for a :class:`.Insert` or
:class:`.Update` construct. [ticket:2850]
Diffstat (limited to 'test')
| -rw-r--r-- | test/sql/test_types.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py index f739707f3..13d4e378e 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -1057,6 +1057,8 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled def process(value): return value / 10 return process + + class MyOldCustomType(MyCustomType): def adapt_operator(self, op): return {operators.add: operators.sub, operators.sub: operators.add}.get(op, op) @@ -1133,6 +1135,26 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled datetime.date(2007, 10, 15), 25, 'BIND_INfooBIND_OUT')] ) + def test_bind_adapt_update(self): + bp = bindparam("somevalue") + stmt = test_table.update().values(avalue=bp) + compiled = stmt.compile() + eq_(bp.type._type_affinity, types.NullType) + eq_(compiled.binds['somevalue'].type._type_affinity, MyCustomType) + + def test_bind_adapt_insert(self): + bp = bindparam("somevalue") + stmt = test_table.insert().values(avalue=bp) + compiled = stmt.compile() + eq_(bp.type._type_affinity, types.NullType) + eq_(compiled.binds['somevalue'].type._type_affinity, MyCustomType) + + def test_bind_adapt_expression(self): + bp = bindparam("somevalue") + stmt = test_table.c.avalue == bp + eq_(bp.type._type_affinity, types.NullType) + eq_(stmt.right.type._type_affinity, MyCustomType) + def test_literal_adapt(self): # literals get typed based on the types dictionary, unless # compatible with the left side type @@ -1264,7 +1286,9 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled assert expr.right.type._type_affinity is MyFoobarType # untyped bind - it gets assigned MyFoobarType - expr = column("foo", MyFoobarType) + bindparam("foo") + bp = bindparam("foo") + expr = column("foo", MyFoobarType) + bp + assert bp.type._type_affinity is types.NullType assert expr.right.type._type_affinity is MyFoobarType expr = column("foo", MyFoobarType) + bindparam("foo", type_=Integer) |
