diff --git a/test/CursorVar.py b/test/CursorVar.py index dfb34ef..392ae02 100644 --- a/test/CursorVar.py +++ b/test/CursorVar.py @@ -31,7 +31,7 @@ class TestCursorVar(BaseTestCase): "test binding in a cursor from a package" cursor = self.connection.cursor() self.assertEqual(cursor.description, None) - self.cursor.callproc("pkg_TestOutCursors.TestOutCursor", (2, cursor)) + self.cursor.callproc("pkg_TestRefCursors.TestOutCursor", (2, cursor)) self.assertEqual(cursor.description, [ ('INTCOL', cx_Oracle.NUMBER, 10, None, 9, 0, 0), ('STRINGCOL', cx_Oracle.STRING, 20, 20 * CS_RATIO, None, diff --git a/test/DMLReturning.py b/test/DMLReturning.py index 8dda014..5afc750 100644 --- a/test/DMLReturning.py +++ b/test/DMLReturning.py @@ -222,6 +222,38 @@ class TestDMLReturning(BaseTestCase): cx_Oracle.__future__.dml_ret_array_val = False self.connection.rollback() + def testInsertAndReturnRowid(self): + "test inserting a row and returning a rowid" + self.cursor.execute("truncate table TestTempTable") + var = self.cursor.var(cx_Oracle.ROWID) + self.cursor.execute(""" + insert into TestTempTable values (278, 'String 278') + returning rowid into :1""", (var,)) + rowid = var.getvalue() + self.cursor.execute("select * from TestTempTable where rowid = :1", + (rowid,)) + self.assertEqual(self.cursor.fetchall(), [(278, 'String 278')]) + + def testInsertWithRefCursor(self): + "test inserting with a REF cursor and returning a rowid" + self.cursor.execute("truncate table TestTempTable") + var = self.cursor.var(cx_Oracle.ROWID) + inCursor = self.connection.cursor() + inCursor.execute(""" + select StringCol + from TestStrings + where IntCol >= 5 + order by IntCol""") + self.cursor.execute(""" + insert into TestTempTable + values (187, pkg_TestRefCursors.TestInCursor(:1)) + returning rowid into :2""", (inCursor, var)) + rowid = var.getvalue() + self.cursor.execute("select * from TestTempTable where rowid = :1", + (rowid,)) + self.assertEqual(self.cursor.fetchall(), + [(187, 'String 7 (Modified)')]) + def testDeleteReturningDecreasingRowsReturned(self): "test delete returning multiple times with decreasing number of rows" data = [(i, "Test String %d" % i) for i in range(1, 11)] diff --git a/test/sql/SetupTest.sql b/test/sql/SetupTest.sql index 88690da..8e5fc3f 100644 --- a/test/sql/SetupTest.sql +++ b/test/sql/SetupTest.sql @@ -671,7 +671,7 @@ create or replace package body &main_user..pkg_TestDateArrays as end; / -create or replace package &main_user..pkg_TestOutCursors as +create or replace package &main_user..pkg_TestRefCursors as type udt_RefCursor is ref cursor; @@ -680,10 +680,14 @@ create or replace package &main_user..pkg_TestOutCursors as a_Cursor out udt_RefCursor ); + function TestInCursor ( + a_Cursor udt_RefCursor + ) return varchar2; + end; / -create or replace package body &main_user..pkg_TestOutCursors as +create or replace package body &main_user..pkg_TestRefCursors as procedure TestOutCursor ( a_MaxIntValue number, @@ -699,6 +703,15 @@ create or replace package body &main_user..pkg_TestOutCursors as order by IntCol; end; + function TestInCursor ( + a_Cursor udt_RefCursor + ) return varchar2 is + t_String varchar2(100); + begin + fetch a_Cursor into t_String; + return t_String || ' (Modified)'; + end; + end; /