OCI to PL/SQL Function using Cursor Variables - GPF's

From: Roderick Prince <rrprince_at_comdisco.com>
Date: 1996/08/23
Message-ID: <321E1130.51E8_at_comdisco.com>


Posted something similar to this but it seems to have gotten lost...

Trying to prove that it is possible to create a named stored procedure (not an anonymous block - plenty of those samples around) that accepts a cursor variable and fills it with results.

The stored procedure at this point is fairly simple (see below). The application is a modification of the WinOCI sample provided by Oracle - attempting to replace the selection of the employee set (see below).

Based on some Trace output it appears that the stored procedure is being called and some fluff code in it is being executed. But the population of the cursor causes the application to GPF.

I would appreciate any pointers to sample code, references to good! books on OCI to PL/SQL, or whatever else you can suggest...

Happy trails,
Roderick...

CREATE OR REPLACE PACKAGE EmployeePkg As

	TYPE EmployeeRec IS REF CURSOR RETURN Emp%ROWTYPE;
	PROCEDURE GetEmployees(p_Cursor IN OUT EmployeeRec);
END EmployeePkg;

CREATE OR REPLACE PACKAGE BODY EmployeePkg AS

	PROCEDURE GetEmployees (p_Cursor IN OUT EmployeeRec) IS
	BEGIN
		/* did a trace on the following to prove to myself that
		something was happening inside the procedure - trace
		shows that this line executes! */
		UPDATE EMP SET EmpNo = EmpNo Where EmpNo > 0;
		COMMIT;

		OPEN p_Cursor FOR
		SELECT EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, 
DEPTNO FROM EMP;         END GetEmployees;

END EmployeePkg;

void COraEmployee::OnEmployeesSelect()
{

	if	(session.opened == FALSE) 
	{
		/* open a cursor for the select from emp */
        if	((*lpfnoopen)(&dml_curs, &lda, (unsigned char  *)0, -1, 
-1, (unsigned char  *)0, -1))  

{
MessageBox("open dml_cur error","Oracle Error"); } /* parse cursor */ if ((*lpfnoparse)(&dml_curs, (unsigned char *)Select.GetBuffer(Select.GetLength()), (sb4)-1, (sword)0, (ub4)1))
{
ProcessError(&dml_curs); } // bind the select cursor for cursor opened in procedure... if ((*lpfnobndra)(&dml_curs, (text *) ":Cursor", -1, (ub1 *) &sel_curs, -1, SQLT_CUR, -1, (sb2 *)0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *) 0, (text *)0, 0, 0))
{
ProcessError(&dml_curs); } } /* execute the query to get a new active set */ THIS IS WHERE THE GPF HAPPENS... if ((*lpfnoexec)(&dml_curs)) {

STEP PAST THE GPF GIVES A 3113 ERROR WHICH INDICATES THAT THE GPF ENDED THE COMMUNCATIONS SESSION WITH THE DATABASE.
		ProcessError(&dml_curs);
		MessageBox("execute query error","Oracle Error");
	}
	else
	{
			(*lpfnoclose)(&dml_curs);
        /* define output buffers for the all fields
           in the select list of our query */
        if	((*lpfnodefin)(&sel_curs, 
					1, 
					(unsigned char  *)emp_empno,
                    sizeof(emp_empno),
                    NULLTERM, 
					-1, 
					(short  *)&ind_emp_empno,
                    (unsigned char  *)0, 
					-1, 
					-1, 
					(unsigned short  *)0,
                    (unsigned short*)0)) 

{
MessageBox("define output buffer error","Oracle Error"); } if ((*lpfnodefin)(&sel_curs, 2, (unsigned char *)emp_ename, sizeof(emp_ename), NULLTERM, -1, (short *)&ind_emp_ename, (unsigned char *)0, -1, -1, (unsigned short *)0, (unsigned short *)0))
{
MessageBox("define output buffer error","Oracle Error"); } if ((*lpfnodefin)(&sel_curs, 3, (unsigned char *)emp_job, sizeof(emp_job), NULLTERM, -1, (short *)&ind_emp_job, (unsigned char *)0, -1, -1, (unsigned short *)0, (unsigned short *)0))
{
MessageBox("define output buffer error","Oracle Error"); } if ((*lpfnodefin)(&sel_curs, 4, (unsigned char *)emp_mgr, sizeof(emp_mgr), NULLTERM, -1, (short *)&ind_emp_mgr, (unsigned char *)0, -1, -1, (unsigned short *)0, (unsigned short *)0))
{
MessageBox("define output buffer error","Oracle Error"); } if ((*lpfnodefin)(&sel_curs, 5, (unsigned char *)emp_hiredate, sizeof(emp_hiredate), NULLTERM, -1, (short *)&ind_emp_hiredate, (unsigned char *)0, -1, -1, (unsigned short *)0, (unsigned short *)0))
{
MessageBox("define output buffer error","Oracle Error"); } if ((*lpfnodefin)(&sel_curs, 6, (unsigned char *)emp_sal, sizeof(emp_sal), NULLTERM, -1, (short *)&ind_emp_sal, (unsigned char *)0, -1, -1, (unsigned short *)0, (unsigned short *)0))
{
MessageBox("define output buffer error","Oracle Error"); } if ((*lpfnodefin)(&sel_curs, 7, (unsigned char *)emp_comm, sizeof(emp_comm), NULLTERM, -1, (short *)&ind_emp_comm, (unsigned char *)0, -1, -1, (unsigned short *)0, (unsigned short *)0))
{
MessageBox("define output buffer error","Oracle Error"); } if ((*lpfnodefin)(&sel_curs, 8, (unsigned char *)emp_deptno, sizeof(emp_deptno), NULLTERM, -1, (short *)&ind_emp_deptno, (unsigned char *)0, -1, -1, (unsigned short *)0, (unsigned short *)0))
{
MessageBox("define output buffer error","Oracle Error"); } session.opened = TRUE; session.nomore = FALSE; OnEmployeesFetch(); }

} Received on Fri Aug 23 1996 - 00:00:00 CEST

Original text of this message