]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added ROWID type to the Oracle dialect, for those
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Aug 2010 19:16:02 +0000 (15:16 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Aug 2010 19:16:02 +0000 (15:16 -0400)
cases where an explicit CAST might be needed.
[ticket:1879]

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

diff --git a/CHANGES b/CHANGES
index 6ac7acd74c0d16fe54c92db604aac51603425dd3..056f695199e069cf295d67d804855da98be5741a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -222,6 +222,11 @@ CHANGES
   - Fixed "default schema" query to work with
     pymssql backend.
 
+- oracle
+  - Added ROWID type to the Oracle dialect, for those
+    cases where an explicit CAST might be needed.
+    [ticket:1879]
+    
 - examples
   - The beaker_caching example has been reorgnized
     such that the Session, cache manager, 
index 78d3c8faba5c0faf780c988873b3e49c58edccf3..f6734013dcb3f6b08d39c31a4805e7cfc350fd69 100644 (file)
@@ -13,5 +13,5 @@ __all__ = (
 'VARCHAR', 'NVARCHAR', 'CHAR', 'DATE', 'DATETIME', 'NUMBER',
 'BLOB', 'BFILE', 'CLOB', 'NCLOB', 'TIMESTAMP', 'RAW',
 'FLOAT', 'DOUBLE_PRECISION', 'LONG', 'dialect', 'INTERVAL',
-'VARCHAR2', 'NVARCHAR2'
+'VARCHAR2', 'NVARCHAR2', 'ROWID'
 )
index cb37f95583095c141f2c034adc02b1e6199bbf65..4c153dac29e3ab7b025c6c6150b7367f3a93ae84 100644 (file)
@@ -222,6 +222,16 @@ class INTERVAL(sqltypes.TypeEngine):
     @property
     def _type_affinity(self):
         return sqltypes.Interval
+
+class ROWID(sqltypes.TypeEngine):
+    """Oracle ROWID type.
+    
+    When used in a cast() or similar, generates ROWID.
+    
+    """
+    __visit_name__ = 'ROWID'
+    
+    
     
 class _OracleBoolean(sqltypes.Boolean):
     def get_dbapi_type(self, dbapi):
@@ -336,6 +346,9 @@ class OracleTypeCompiler(compiler.GenericTypeCompiler):
     def visit_RAW(self, type_):
         return "RAW(%(length)s)" % {'length' : type_.length}
 
+    def visit_ROWID(self, type_):
+        return "ROWID"
+        
 class OracleCompiler(compiler.SQLCompiler):
     """Oracle compiler modifies the lexical structure of Select
     statements to work under non-ANSI configured Oracle databases, if
index 01bb663049dea0f0328d3668dfa1cfce31d505b9..eb25e614e6915ef37a6d20ad8a1065dbf6d044d2 100644 (file)
@@ -220,6 +220,10 @@ class _OracleInterval(oracle.INTERVAL):
 class _OracleRaw(oracle.RAW):
     pass
 
+class _OracleRowid(oracle.ROWID):
+    def get_dbapi_type(self, dbapi):
+        return dbapi.ROWID
+        
 class OracleCompiler_cx_oracle(OracleCompiler):
     def bindparam_string(self, name):
         if self.preparer._bindparam_requires_quotes(name):
@@ -392,6 +396,7 @@ class OracleDialect_cx_oracle(OracleDialect):
         oracle.RAW: _OracleRaw,
         sqltypes.Unicode: _OracleNVarChar,
         sqltypes.NVARCHAR : _OracleNVarChar,
+        oracle.ROWID: _OracleRowid,
     }
 
     
index a65fe084a76095361f61f790c54cd3601ef21fe4..384066c41f626b4fc712c0435e39d252a3112019 100644 (file)
@@ -679,6 +679,27 @@ class TypesTest(TestBase, AssertsCompiledSQL):
         finally:
             t1.drop()
     
+    @testing.provide_metadata
+    def test_rowid(self):
+        t = Table('t1', metadata,
+            Column('x', Integer)
+        )
+        t.create()
+        t.insert().execute(x=5)
+        s1 = select([t])
+        s2 = select([column('rowid')]).select_from(s1)
+        rowid = s2.scalar()
+        
+        # the ROWID type is not really needed here,
+        # as cx_oracle just treats it as a string,
+        # but we want to make sure the ROWID works...
+        rowid_col= column('rowid', oracle.ROWID)
+        s3 = select([t.c.x, rowid_col]).\
+                    where(rowid_col == cast(rowid, oracle.ROWID))
+        eq_(s3.select().execute().fetchall(),
+        [(5, rowid)]
+        )
+        
     @testing.fails_on('+zxjdbc',
                       'Not yet known how to pass values of the '
                       'INTERVAL type')