Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> OCI - pass table to external procedure

OCI - pass table to external procedure

From: Sebastian Faust <sebastian.faust_at_googlemail.com>
Date: Sun, 03 Jun 2007 09:32:17 -0700
Message-ID: <1180888337.813195.254080@q66g2000hsg.googlegroups.com>


Hi,

we are trying to call an external C function from Oracle 9.2.0 and pass to it a table with 2 columns of type int. Unfortunately, we are not able to access the second column. The code of the C function is as follows:

struct MY_TABLE
{

    OCINumber* feld1;
    OCINumber* feld2;
};
typedef struct MY_TABLE MY_TABLE;

int tableTest(OCIExtProcContext* ctx, 	/* OCI context */
							char* error_msg, 				/* OUT - returns the error message */
							short* error_msgInd, 		/* OUT - returns if error_msg is a null
pointer */
							OCITable *table_obj,
							short table_obj_in)
{
	int i;
	char strOutput[4096] = {0};

	static XLOPER hl[MAX_HOLIDAY_DAYS];
	LPXLOPER Return_d_adj;

	OCIEnv    *env = (OCIEnv*)0;

  OCIError *err = (OCIError*)0;
	sb4 table_size, first_index;
	sword status;
	dvoid *tmp;
	MY_TABLE tableElem;
	int converted = 0;


/* initialize with SUCCESS; in case of errors this will be replaced
*/ strcpy(error_msg,SUCCESS); error_msgInd = OCI_IND_NOTNULL;
/* parameters needed to get the elements from the holiday table */

  boolean exists;

/* initializes the environment */

	status=OCIEnvCreate(&env, OCI_OBJECT , 0, 0, 0, 0, 0, 0);
	if (status != OCI_SUCCESS) {
    checkerr(error_msg, err, status);
	}


/* allocates memory for the error handle */
status=OCIHandleAlloc( (dvoid *) env, (dvoid **) &err, (ub4) OCI_HTYPE_ERROR, 52, (dvoid **) &tmp); if (status != OCI_SUCCESS) {

    strcpy(error_msg,"ERROR - OCIHandleAlloc");     return;

        }

	if(table_obj_in == OCI_IND_NOTNULL) {

/* gets the table size */
status = OCITableSize (env,err,table_obj,&table_size); if (status != OCI_SUCCESS) { checkerr(error_msg, err, status); } /* gets the index of the first element in the table */ status = OCITableFirst (env,err,table_obj,&first_index); if (status != OCI_SUCCESS) { checkerr(error_msg, err, status); } status= OCICollGetElem (env,err,table_obj,first_index, &exists, (dvoid*)&tableElem,0); if (status != OCI_SUCCESS) { checkerr(error_msg, err, status); } /* converts OCINumber to int */ status = OCINumberToInt(err, tableElem.feld2,sizeof(converted),OCI_NUMBER_UNSIGNED,&converted); if (status != OCI_SUCCESS) { checkerr(error_msg, err, status); } } return converted;

}

When we call it from oracle we get the following error: OCI-21560: 2 argument string is null, invalid, or out of range

What do we have to do to access the data of the second column?

Thanks for your help!
Sebastian Received on Sun Jun 03 2007 - 11:32:17 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US