Re: OCI calls

From: Chris Hafey <chafey_at_ecst.csuchico.edu>
Date: 1996/02/01
Message-ID: <4eraj5$65p_at_charnel.ecst.csuchico.edu>#1/1


In article <4eovhd$t08_at_news.missouri.edu>, Ravi Kodali <kodali_at_cclabs.missouri.edu> wrote:
>I was trying to update some records with C and OCI and could someone
>tell me if I need to bind the variable before calling 'oexec' or
>can I directly call 'oexec' after 'oparse'.

You can directly call oexec after an oparse if you have no variables to bind.

>say variable 'Load' is pointer to some data.
>
>now I tried this way.
>
> strcpy(array,"UPDATE USER_INFO SET DESCRIPTION = '");
> strcat(array,Load);
> strcat(array,"' WHERE USER_ID = 'dale'");
>
> oparse(&cda, array, -1, 0, 2);
>
> obndra(&cda,(text *) "dale",-1,(text *) Load,sizeof(sword),\
> VARCHAR2_TYPE,-1,(sb2 *) 1,alen,arcode,len,&max ,(text
> 0,-1,-1));
>
> oexec(&cda);

I assume that Load is a pointer to a string. If this is the case, then you should remove the obndra statement. Your are not building your SQL string correctly to use bind variables. If you really want to use variable binding, you should do something like:

sb2	indp;
ub2	alen;
ub2	arcode;

strcpy(array,"UPDATE USER_INFO SET DESCRIPTION = :var WHERE USER_ID='dale'");
oparse(&cda, array, -1, 0, 2);
obndra(&cda, (text *)":var", -1, 	/* tell oci which variable to bind */
	(ub1 *) Load, strlen(Load), 	/* here is the data to bind it to */
	VARCHAR2_TYPE, -1, 		/* your TYPE and scale(unused) */
	&indp, &alen, &arcode, 0,	
	(ub4 *)0, (text *)0, -1, -1);

oexec(&cda);

The :var in the SQL statement tells oci that it is a bind variable. obndra() tells oci where to find the value for that bind variable. In your example, you were concatenating the value into the SQL string. This works great but requires no variables to be bound. I am not sure if binding your string to the SQL statement will make it execute much faster.

Chris Hafey

-- 
chafey_at_ecst.csuchico.edu    	http://www.ecst.csuchico.edu/~chafey
"One two buckle my shoe take care of me because I might be you"
Received on Thu Feb 01 1996 - 00:00:00 CET

Original text of this message