Correct handling of statements and rowids in DML returning statements.
This commit is contained in:
parent
211298209b
commit
c31eef50de
|
@ -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,
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
/
|
||||
|
||||
|
|
Loading…
Reference in New Issue