From: Mike Bayer Date: Sun, 29 Aug 2010 19:16:02 +0000 (-0400) Subject: - Added ROWID type to the Oracle dialect, for those X-Git-Tag: rel_0_6_4~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c63679bdb50491120e205820c2c29cf42cfa9ea;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Added ROWID type to the Oracle dialect, for those cases where an explicit CAST might be needed. [ticket:1879] --- diff --git a/CHANGES b/CHANGES index 6ac7acd74c..056f695199 100644 --- 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, diff --git a/lib/sqlalchemy/dialects/oracle/__init__.py b/lib/sqlalchemy/dialects/oracle/__init__.py index 78d3c8faba..f6734013dc 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 cb37f95583..4c153dac29 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 01bb663049..eb25e614e6 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 a65fe084a7..384066c41f 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')