When trying to execute a statement on Oracle RDBMS I always get OCI_INVALID_HANDLE as status (checked with gdb) and the statement therefore is not executed.
May someone could help to get this working:
OCIEnv* envh;
OCISvcCtx* svch;
OCIError* errh;
sword stat;
stat = OCIExtProcGetEnv (context, &envh, &svch, &errh);
OCIStmt* stmthp;
char errbuf[512];
sb4 errcode = 0;
char * cmd = "alter session set NLS_DATE_FORMAT='dd/mm/yyyy hh24:mi:ss'";
sword status = OCIStmtPrepare(stmthp, errh, (const OraText*)cmd, (ub4) strlen(cmd), (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
if ( status != OCI_SUCCESS )
{
OCIErrorGet((void*)errh, (ub4) 1, (text *) NULL, &errcode,
(text*)errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
OCIExtProcRaiseExcpWithMsg((OCIExtProcContext*)context, errcode, (text*)errbuf, sizeof(errbuf));
}
context is an OCIExProcContext* passed from PL/SQL to this external procedure
A simple OCIExtProcRaiseExcpWithMsg((OCIExtProcContext*)context, 34, (text*)"custom", 6); work without problems. Furthermore I checked all other pointer with gdb and they seem quite nice. May I missed some initialization?
You forgot to allocate a statement handle. The variable
stmthpyou’re passing intoOCIStmtPrepareis not initialized: