"literal" is first derived from the Python type of the
literal, assuming standard native Python types + date
types, before falling back to that of the known type
- on the other side of the expression. Also part
- of [ticket:1683].
+ on the other side of the expression. If the
+ "fallback" type is compatible (i.e. CHAR from String),
+ the literal side will use that. Also part of
+ [ticket:1683].
- Made sqlalchemy.sql.expressions.Executable part of public
API, used for any expression construct that can be sent to
"""
kwargs.setdefault('convert_unicode', True)
- super(Unicode, self).__init__(length=length, _warn_on_bytestring=True, **kwargs)
+ kwargs.setdefault('_warn_on_bytestring', True)
+ super(Unicode, self).__init__(length=length, **kwargs)
class UnicodeText(Text):
"""An unbounded-length Unicode string.
"""
kwargs.setdefault('convert_unicode', True)
- super(UnicodeText, self).__init__(length=length, _warn_on_bytestring=True, **kwargs)
+ kwargs.setdefault('_warn_on_bytestring', True)
+ super(UnicodeText, self).__init__(length=length, **kwargs)
class Integer(_DateAffinity, TypeEngine):
# try:
# from fastdec import mpd as Decimal
# except ImportError:
- return processors.to_decimal_processor_factory(_python_Decimal, self.scale)
+ if self.scale is not None:
+ return processors.to_decimal_processor_factory(_python_Decimal, self.scale)
+ else:
+ return processors.to_decimal_processor_factory(_python_Decimal)
else:
return None
import datetime, os, re
from sqlalchemy import *
from sqlalchemy import exc, types, util, schema
-from sqlalchemy.sql import operators
+from sqlalchemy.sql import operators, column
from sqlalchemy.test.testing import eq_
import sqlalchemy.engine.url as url
from sqlalchemy.databases import *
)
def test_bind_adapt(self):
+ # test an untyped bind gets the left side's type
expr = test_table.c.atimestamp == bindparam("thedate")
- assert expr.right.type.__class__ == test_table.c.atimestamp.type.__class__
+ eq_(expr.right.type._type_affinity, Date)
eq_(
testing.db.execute(
)
expr = test_table.c.avalue == bindparam("somevalue")
- eq_(expr.right.type.__class__, test_table.c.avalue.type.__class__)
+ eq_(expr.right.type._type_affinity, MyCustomType)
eq_(
testing.db.execute(test_table.select().where(expr), {"somevalue":25}).fetchall(),
[(1, 'somedata', datetime.date(2007, 10, 15), 25)]
)
+
+ def test_literal_adapt(self):
+ # literals get typed based on the types dictionary, unless compatible
+ # with the left side type
+
+ expr = column('foo', String) == 5
+ eq_(expr.right.type._type_affinity, Integer)
+
+ expr = column('foo', String) == "asdf"
+ eq_(expr.right.type._type_affinity, String)
+
+ expr = column('foo', CHAR) == 5
+ eq_(expr.right.type._type_affinity, Integer)
+ expr = column('foo', CHAR) == "asdf"
+ eq_(expr.right.type.__class__, CHAR)
+
+
+
@testing.fails_on('firebird', 'Data type unknown on the parameter')
def test_operator_adapt(self):
"""test type-based overloading of operators"""