Re: Dynamic SQL - proC - Method 4

From: John Strange <jstrange_at_imtn.dsccc.com>
Date: Wed, 25 Jul 2001 12:00:29 +0000 (UTC)
Message-ID: <9jmcct$98v$1_at_auds955.usa.alcatel.com>


Here is just some code pieces to show how to get string data in c vars.

The target string must be 1 character longer to store a string terminator.

EXEC SQL BEGIN DECLARE SECTION ;
static varchar app_name [41] ; /* storage + n */ EXEC SQL END DECLARE SECTION ; static char app [41] ;/* application name */

EXEC SQL FETCH find_app INTO :app_name ; /* oracle loads app_name struct */

app_name.arr[app_name.len] = '\0'; /* set end of string for sprintf */

sprintf (app, "%s", (char *)app_name.arr) ; /* copy app_name into app */

Sylvain Benoist (sylvainb_at_whitepj.com) wrote:
: "Erwin Dondorp" <erwindon_at_wxs.nl> wrote in message
: news:3B5D2932.615C0D6C_at_wxs.nl...
: > Sylvain Benoist wrote:
: > > When we want to get some data from the database by using this
 application,
: > > everything works fine except with the "string" fields. Indeed, if the
 type
: > > of one field is varchar(10) and this field contains 4 characters, the
: > > Dynamic SQL method 4 will return a string containing 10 characters with
 the
: > > 4 corresponding characters + 6 spaces.
: >
: > You need to set s->T[i] to 5 ("C"-string) of the varchar2 columns.
: > You probably used 1 ("char") or 9 ("varchar").
: >
: > Erwin
: >
 

: Hi,
: I see what you mean and I tried it. What I did is I tried to coerce the
: varchar datatype to STRING, by using the following statement:
 

: /* Coerce select-list value to STRING */
 

: select_des->T[i] = 5;
 

: But the length returned is still the maximum length of the varchar field.
 

: I also tried to set the T array of datatype codes to tell Oracle the
: external datatype of each bind variable ( Oracle is supposed to do any
: necessary conversion between external and internal datatypes at OPEN time,
: by using the following statement :
 

: bind_des->T[i] = 5;
 

: But it doesn't work.
 

: Thank you for your help.
 

: Sylvain.

--
While Alcatel may claim ownership of all my ideas (on or off the job),
Alcatel does not claim any responsibility for them. Warranty expired when u
opened this article and I will not be responsible for its contents or use.
Received on Wed Jul 25 2001 - 14:00:29 CEST

Original text of this message