From: Mike Bayer Date: Sat, 3 Oct 2009 19:58:19 +0000 (+0000) Subject: - usage of the CHAR type results in cx_oracle's X-Git-Tag: rel_0_6beta1~267 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=680f87c9ce1b31f057c9b25154e342bbaa006b1f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - usage of the CHAR type results in cx_oracle's FIXED_CHAR dbapi type being bound to statements. --- diff --git a/CHANGES b/CHANGES index c3380c0741..372496f0a4 100644 --- a/CHANGES +++ b/CHANGES @@ -288,7 +288,10 @@ CHANGES later of cx_oracle. - an NCLOB type is added to the base types. - + + - usage of the CHAR type results in cx_oracle's + FIXED_CHAR dbapi type being bound to statements. + - the Oracle dialect now features NUMBER which intends to act justlike Oracle's NUMBER type. It is the primary numeric type returned by table reflection and attempts diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index f409235914..721c455884 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -139,6 +139,10 @@ class _LOBMixin(object): else: return value return process + +class _OracleChar(sqltypes.CHAR): + def get_dbapi_type(self, dbapi): + return dbapi.FIXED_CHAR class _OracleText(_LOBMixin, sqltypes.Text): def get_dbapi_type(self, dbapi): @@ -176,10 +180,12 @@ colspecs = { sqltypes.Text : _OracleText, sqltypes.UnicodeText : _OracleUnicodeText, sqltypes.TIMESTAMP : _OracleTimestamp, + sqltypes.CHAR : _OracleChar, sqltypes.Integer : _OracleInteger, # this is only needed for OUT parameters. # it would be nice if we could not use it otherwise. oracle.NUMBER : oracle.NUMBER, # don't let this get converted oracle.RAW: _OracleRaw, + } class Oracle_cx_oracleCompiler(OracleCompiler): diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index 1701c72807..3296f47fce 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -346,7 +346,36 @@ class TypesTest(TestBase, AssertsCompiledSQL): b = bindparam("foo", u"hello world!") assert b.type.dialect_impl(dialect).get_dbapi_type(dbapi) == 'STRING' + + def test_fixed_char(self): + m = MetaData(testing.db) + t = Table('t1', m, + Column('id', Integer, primary_key=True), + Column('data', CHAR(30), nullable=False) + ) + + t.create() + try: + t.insert().execute( + dict(id=1, data="value 1"), + dict(id=2, data="value 2"), + dict(id=3, data="value 3") + ) + eq_(t.select().where(t.c.data=='value 2').execute().fetchall(), + [(2, 'value 2 ')] + ) + + m2 = MetaData(testing.db) + t2 = Table('t1', m2, autoload=True) + assert type(t2.c.data.type) is CHAR + eq_(t2.select().where(t2.c.data=='value 2').execute().fetchall(), + [(2, 'value 2 ')] + ) + + finally: + t.drop() + def test_type_adapt(self): dialect = cx_oracle.dialect()