Stored procedures in c++ via odbc
438135Feb 10 2005 — edited Feb 14 2005I just want to access access result sets. On trying to find out how this works, I just read the documentation and found an example which I followed and came up with this.
I have the following done in sql*plus
DROP PACKAGE ODBCRefCus;
CREATE PACKAGE ODBCRefCus AS
TYPE firstname_cus IS REF CURSOR;
TYPE familyname_cus IS REF CURSOR;
TYPE address_cus IS REF CURSOR;
TYPE telno_cus IS REF CURSOR;
PROCEDURE spEmpCus(Firstname IN OUT firstname_cus, Familyname IN OUT
familyname_cus, Address IN OUT address_cus, Telno IN OUT telno_cus,
comp IN
VARCHAR2);
END;
/
CREATE PACKAGE BODY ODBCRefCus AS
PROCEDURE spEmpCus(Firstname IN OUT firstname_cus, Familyname IN OUT
familyname_cus, Address IN OUT address_cus, Telno IN OUT telno_cus,
comp IN
VARCHAR2)
AS
BEGIN
IF NOT Firstname%ISOPEN
THEN
OPEN Firstname for SELECT firstname FROM customers WHERE
firm = comp;
END IF;
IF NOT Familyname%ISOPEN
THEN
OPEN Familyname for SELECT familyname FROM customers WHERE firm =
comp;
END IF;
IF NOT Address%ISOPEN
THEN
OPEN Address for SELECT address FROM customers WHERE firm = comp;
END IF;
IF NOT Telno%ISOPEN
THEN
OPEN Telno for SELECT telno FROM customers WHERE firm = comp;
END IF;
END;
END;
/
I was able to compile successfully.
And in my c++ program:
char firstname[25];
char familyname[25];
#define DATA_LEN 100
char address[50];
char telno[15];
SQLINTEGER firstnameId = 25; //these are the types provided by odbc-api
SQLINTEGER familynameId = 25;
SQLINTEGER addressId = 50;
SQLINTEGER telnoId = 15;
SQLINTEGER compId = 25;
SQLINTEGER sqlnts=SQL_NTS;
Assuming that all about the connections were okay
AnsiString stmt = "CALL ODBCRefCus.spEmpCus(?,?,?,?,'firm')";
//AnisString(borlands) is just a string
retcode =
SQLBindParameter(hstmt,1,SQL_PARAM_INPUT_OUTPUT,SQL_C_CHAR,SÂQL_C_CHAR,
sizeof(firstname),0,firstname,0,&firstnameId);
//same is for familyname, address, telno
ret = SQLBindParameter(hstmt,5,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_C_CHAR, DATA_LEN,0,comp,0,&sqlnts);
My problem is: what type do I use to bind for ? as parameters. If I use
AnsiString/string/char* - it gets problem with execution.
retcode = SQLExecute(hstmt);
And gives error message of ora-06553: pls-306 wrong number or type of
arguments.
NB: I do use oracle9i, c++builder6
I'm quite in need of your help.
Regards,
Harp