]> 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:44:21 +0000 (11:44 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 19 Jul 2011 15:44:21 +0000 (11:44 -0400)
generate the correct DDL.  [ticket:2220]
Also in 0.6.9.

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

diff --git a/CHANGES b/CHANGES
index daf1919ef7f0ee780d6807b90e4487d801ebb01f..74668f1e8cd651f2d514f9184f436e64bcd16497 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -146,6 +146,10 @@ CHANGES
     can be caught during a connection 
     event.  [ticket:2201]
 
+  - repaired the oracle.RAW type which did not
+    generate the correct DDL.  [ticket:2220]
+    Also in 0.6.9.
+
 -ext
   - Fixed bug in the mutable extension whereby
     if the same type were used twice in one
index 14e6309cb1c11ff5cbb5382d584bf0a01eb415bb..b83eb0ffa06cb84f0220bf680b6be9e449ee4efa 100644 (file)
@@ -163,8 +163,8 @@ RESERVED_WORDS = \
 NO_ARG_FNS = set('UID CURRENT_DATE SYSDATE USER '
                 'CURRENT_TIME CURRENT_TIMESTAMP'.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 f3cdcc3a9b8b01e0f77cc870d2f6c5a622f981ef..4b53500b3590ae6d389af616cfa6c98680329c5a 100644 (file)
@@ -1010,7 +1010,7 @@ class TypesTest(fixtures.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),
@@ -1019,31 +1019,47 @@ class TypesTest(fixtures.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):
+        metadata = self.metadata
+        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)
+        metadata = self.metadata
         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)")
@@ -1088,7 +1104,7 @@ class TypesTest(fixtures.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),