From: Mike Bayer Date: Tue, 19 Jul 2011 15:43:46 +0000 (-0400) Subject: - repaired the oracle.RAW type which did not X-Git-Tag: rel_0_6_9~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=105e7636b72347428373ae08ab3f8cef5986879e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - repaired the oracle.RAW type which did not generate the correct DDL. [ticket:2220] - Fixed bug whereby "warn on unicode" flag would get set for the String type when used with certain dialects. This bug is not in 0.7. --- diff --git a/CHANGES b/CHANGES index 973cbdf792..f7d5db828a 100644 --- a/CHANGES +++ b/CHANGES @@ -38,11 +38,19 @@ CHANGES when the label has been "grouped" and loses itself. Affects [ticket:2188]. + - Fixed bug whereby "warn on unicode" flag + would get set for the String type + when used with certain dialects. This + bug is not in 0.7. + - oracle - Added ORA-00028 to disconnect codes, use cx_oracle _Error.code to get at the code, [ticket:2200]. + - repaired the oracle.RAW type which did not + generate the correct DDL. [ticket:2220] + 0.6.8 ===== - orm diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 9db4e99233..9b284bbbfc 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -159,8 +159,8 @@ RESERVED_WORDS = set('SHARE RAW DROP BETWEEN FROM DESC OPTION PRIOR LONG THEN ' 'OF UNIQUE VARCHAR2 VARCHAR LOCK OR CHAR DECIMAL UNION PUBLIC ' 'AND START UID COMMENT'.split()) -class RAW(sqltypes.LargeBinary): - pass +class RAW(sqltypes._Binary): + __visit_name__ = 'RAW' OracleRaw = RAW class NCLOB(sqltypes.Text): @@ -361,7 +361,10 @@ class OracleTypeCompiler(compiler.GenericTypeCompiler): return self.visit_SMALLINT(type_) def visit_RAW(self, type_): - return "RAW(%(length)s)" % {'length' : type_.length} + if type_.length: + return "RAW(%(length)s)" % {'length' : type_.length} + else: + return "RAW" def visit_ROWID(self, type_): return "ROWID" diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 46c33eb33f..2d12e18ae0 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -946,7 +946,7 @@ class String(Concatenable, TypeEngine): length=self.length, convert_unicode=self.convert_unicode, unicode_error=self.unicode_error, - _warn_on_bytestring=True, + _warn_on_bytestring=self._warn_on_bytestring, ) def bind_processor(self, dialect): diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index 163364633a..58c2a64866 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -993,7 +993,7 @@ class TypesTest(TestBase, AssertsCompiledSQL): finally: metadata.drop_all() - def test_reflect_raw(self): + def test_reflect_all_types_schema(self): types_table = Table('all_types', MetaData(testing.db), Column('owner', String(30), primary_key=True), Column('type_name', String(30), primary_key=True), @@ -1002,31 +1002,45 @@ class TypesTest(TestBase, AssertsCompiledSQL): for row in types_table.select().execute().fetchall(): [row[k] for k in row.keys()] + def test_raw_compile(self): + self.assert_compile(oracle.RAW(), "RAW") + self.assert_compile(oracle.RAW(35), "RAW(35)") + + @testing.provide_metadata + def test_raw_roundtrip(self): + raw_table = Table('raw', metadata, + Column('id', Integer, primary_key=True), + Column('data', oracle.RAW(35)) + ) + metadata.create_all() + testing.db.execute(raw_table.insert(), id=1, data="ABCDEF") + eq_( + testing.db.execute(raw_table.select()).first(), + (1, "ABCDEF") + ) + + @testing.provide_metadata def test_reflect_nvarchar(self): - metadata = MetaData(testing.db) t = Table('t', metadata, Column('data', sqltypes.NVARCHAR(255)) ) metadata.create_all() - try: - m2 = MetaData(testing.db) - t2 = Table('t', m2, autoload=True) - assert isinstance(t2.c.data.type, sqltypes.NVARCHAR) - - if testing.against('oracle+cx_oracle'): - # nvarchar returns unicode natively. cx_oracle - # _OracleNVarChar type should be at play here. - assert isinstance( - t2.c.data.type.dialect_impl(testing.db.dialect), - cx_oracle._OracleNVarChar) - - data = u'm’a réveillé.' - t2.insert().execute(data=data) - res = t2.select().execute().first()['data'] - eq_(res, data) - assert isinstance(res, unicode) - finally: - metadata.drop_all() + m2 = MetaData(testing.db) + t2 = Table('t', m2, autoload=True) + assert isinstance(t2.c.data.type, sqltypes.NVARCHAR) + + if testing.against('oracle+cx_oracle'): + # nvarchar returns unicode natively. cx_oracle + # _OracleNVarChar type should be at play here. + assert isinstance( + t2.c.data.type.dialect_impl(testing.db.dialect), + cx_oracle._OracleNVarChar) + + data = u'm’a réveillé.' + t2.insert().execute(data=data) + res = t2.select().execute().first()['data'] + eq_(res, data) + assert isinstance(res, unicode) def test_char_length(self): self.assert_compile(VARCHAR(50),"VARCHAR(50 CHAR)") @@ -1071,7 +1085,7 @@ class TypesTest(TestBase, AssertsCompiledSQL): testing.db.execute("DROP TABLE Z_TEST") @testing.fails_on('+zxjdbc', 'auto_convert_lobs not applicable') - def test_raw_lobs(self): + def test_lobs_without_convert(self): engine = testing_engine(options=dict(auto_convert_lobs=False)) metadata = MetaData() t = Table("z_test", metadata, Column('id', Integer, primary_key=True),