]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- repaired the oracle.RAW type which did not
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 19 Jul 2011 15:43:46 +0000 (11:43 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 19 Jul 2011 15:43:46 +0000 (11:43 -0400)
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.

CHANGES
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/types.py
test/dialect/test_oracle.py

diff --git a/CHANGES b/CHANGES
index 973cbdf7923785113cf6663fdeb2e4d163b6de35..f7d5db828a04e7ebf79e821ba1500f97eb33a5b7 100644 (file)
--- 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
index 9db4e9923326963cce377352760a1a0cd23a3d56..9b284bbbfcabf4febf5b25563181e3492322bc55 100644 (file)
@@ -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"
index 46c33eb33f36f833684b1d3dbaf9aeba4df6770d..2d12e18ae0ed7dd7fdd3b69058356e971c453601 100644 (file)
@@ -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):
index 163364633ac8945df43a0a138686ca84e6565357..58c2a64866caa0b3ce30e9cd6834b20c756a06b8 100644 (file)
@@ -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),