Commits

Mike Bayer  committed eb07b51

- more oracle tweaks for returning; the method here is still kind of brittle and might have issues with
pks, multiple function calls

  • Participants
  • Parent commits 7f624de

Comments (0)

Files changed (3)

File lib/sqlalchemy/dialects/oracle/cx_oracle.py

                     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)] = \

File lib/sqlalchemy/sql/compiler.py

             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,

File test/dialect/test_oracle.py

                 "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(