diff options
| -rw-r--r-- | CHANGES | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/__init__.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/base.py | 13 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/cx_oracle.py | 5 | ||||
| -rw-r--r-- | test/dialect/test_oracle.py | 21 |
5 files changed, 45 insertions, 1 deletions
@@ -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, diff --git a/lib/sqlalchemy/dialects/oracle/__init__.py b/lib/sqlalchemy/dialects/oracle/__init__.py index 78d3c8fab..f6734013d 100644 --- a/lib/sqlalchemy/dialects/oracle/__init__.py +++ b/lib/sqlalchemy/dialects/oracle/__init__.py @@ -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' ) diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index cb37f9558..4c153dac2 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -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 diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 01bb66304..eb25e614e 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -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, } diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index a65fe084a..384066c41 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -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') |
