Skip to content

Commit c31eef5

Browse files
Correct handling of statements and rowids in DML returning statements.
1 parent 2112982 commit c31eef5

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

test/CursorVar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def testBindCursorInPackage(self):
3131
"test binding in a cursor from a package"
3232
cursor = self.connection.cursor()
3333
self.assertEqual(cursor.description, None)
34-
self.cursor.callproc("pkg_TestOutCursors.TestOutCursor", (2, cursor))
34+
self.cursor.callproc("pkg_TestRefCursors.TestOutCursor", (2, cursor))
3535
self.assertEqual(cursor.description,
3636
[ ('INTCOL', cx_Oracle.NUMBER, 10, None, 9, 0, 0),
3737
('STRINGCOL', cx_Oracle.STRING, 20, 20 * CS_RATIO, None,

test/DMLReturning.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,38 @@ def testInsertAndReturnObject(self):
222222
cx_Oracle.__future__.dml_ret_array_val = False
223223
self.connection.rollback()
224224

225+
def testInsertAndReturnRowid(self):
226+
"test inserting a row and returning a rowid"
227+
self.cursor.execute("truncate table TestTempTable")
228+
var = self.cursor.var(cx_Oracle.ROWID)
229+
self.cursor.execute("""
230+
insert into TestTempTable values (278, 'String 278')
231+
returning rowid into :1""", (var,))
232+
rowid = var.getvalue()
233+
self.cursor.execute("select * from TestTempTable where rowid = :1",
234+
(rowid,))
235+
self.assertEqual(self.cursor.fetchall(), [(278, 'String 278')])
236+
237+
def testInsertWithRefCursor(self):
238+
"test inserting with a REF cursor and returning a rowid"
239+
self.cursor.execute("truncate table TestTempTable")
240+
var = self.cursor.var(cx_Oracle.ROWID)
241+
inCursor = self.connection.cursor()
242+
inCursor.execute("""
243+
select StringCol
244+
from TestStrings
245+
where IntCol >= 5
246+
order by IntCol""")
247+
self.cursor.execute("""
248+
insert into TestTempTable
249+
values (187, pkg_TestRefCursors.TestInCursor(:1))
250+
returning rowid into :2""", (inCursor, var))
251+
rowid = var.getvalue()
252+
self.cursor.execute("select * from TestTempTable where rowid = :1",
253+
(rowid,))
254+
self.assertEqual(self.cursor.fetchall(),
255+
[(187, 'String 7 (Modified)')])
256+
225257
def testDeleteReturningDecreasingRowsReturned(self):
226258
"test delete returning multiple times with decreasing number of rows"
227259
data = [(i, "Test String %d" % i) for i in range(1, 11)]

test/sql/SetupTest.sql

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ create or replace package body &main_user..pkg_TestDateArrays as
671671
end;
672672
/
673673

674-
create or replace package &main_user..pkg_TestOutCursors as
674+
create or replace package &main_user..pkg_TestRefCursors as
675675

676676
type udt_RefCursor is ref cursor;
677677

@@ -680,10 +680,14 @@ create or replace package &main_user..pkg_TestOutCursors as
680680
a_Cursor out udt_RefCursor
681681
);
682682

683+
function TestInCursor (
684+
a_Cursor udt_RefCursor
685+
) return varchar2;
686+
683687
end;
684688
/
685689

686-
create or replace package body &main_user..pkg_TestOutCursors as
690+
create or replace package body &main_user..pkg_TestRefCursors as
687691

688692
procedure TestOutCursor (
689693
a_MaxIntValue number,
@@ -699,6 +703,15 @@ create or replace package body &main_user..pkg_TestOutCursors as
699703
order by IntCol;
700704
end;
701705

706+
function TestInCursor (
707+
a_Cursor udt_RefCursor
708+
) return varchar2 is
709+
t_String varchar2(100);
710+
begin
711+
fetch a_Cursor into t_String;
712+
return t_String || ' (Modified)';
713+
end;
714+
702715
end;
703716
/
704717

0 commit comments

Comments
 (0)