From: Mike Bayer Date: Sat, 25 Aug 2012 19:41:14 +0000 (+0000) Subject: - more oracle tweaks for returning; the method here is still kind of brittle and... X-Git-Tag: rel_0_8_0b1~206 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4d40f1b71ec293af5a7ce16a66429976895a8545;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - more oracle tweaks for returning; the method here is still kind of brittle and might have issues with pks, multiple function calls --- diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index e2d98fb788..ea1913c384 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -350,11 +350,12 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): if not hasattr(self, 'out_parameters'): self.out_parameters = {} if dbtype is None: - raise exc.InvalidRequestError("Cannot create out parameter for parameter " - "%r - it's type %r is not supported by" - " cx_oracle" % - (name, bindparam.type) - ) + raise exc.InvalidRequestError( + "Cannot create out parameter for parameter " + "%r - it's type %r is not supported by" + " cx_oracle" % + (bindparam.name, bindparam.type) + ) name = self.compiled.bind_names[bindparam] self.out_parameters[name] = self.cursor.var(dbtype) self.parameters[0][quoted_bind_names.get(name, name)] = \ diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index fffe3a9a5b..8e4f0288f8 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -958,7 +958,9 @@ class SQLCompiler(engine.Compiled): else: add_to_result_map = None - if isinstance(column, sql.Label): + if not within_columns_clause: + result_expr = col_expr + elif isinstance(column, sql.Label): if col_expr is not column: result_expr = _CompileLabel( col_expr, diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index fa6e4a85fe..1fbaf96dde 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -453,6 +453,23 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): "t1.c2, t1.c3 INTO :ret_0, :ret_1" ) + def test_returning_insert_functional(self): + t1 = table('t1', column('c1'), column('c2', String()), column('c3', String())) + fn = func.lower(t1.c.c2, type_=String()) + stmt = t1.insert().values(c1=1).returning(fn, t1.c.c3) + compiled = stmt.compile(dialect=oracle.dialect()) + eq_( + compiled.result_map, + {'c3': ('c3', (t1.c.c3, 'c3', 'c3'), t1.c.c3.type), + 'lower': ('lower', (), fn.type)} + + ) + self.assert_compile( + stmt, + "INSERT INTO t1 (c1) VALUES (:c1) RETURNING " + "lower(t1.c2), t1.c3 INTO :ret_0, :ret_1" + ) + def test_returning_insert_labeled(self): t1 = table('t1', column('c1'), column('c2'), column('c3')) self.assert_compile(