Answer for rtan_at_polaris.utswrk about ProC
Date: Wed, 10 Feb 1993 15:49:55 GMT
Message-ID: <C28pB7.AnH_at_vtm.be>
>I have a problem that is close to driving me nuts. I've coded a C program with
>Embedded SQL that
>goes like this:
>
> EXEC SQL BEGIN DECLARE SECTION;
> char name[20];
> EXEC SQL END DECLARE SECTION;
> .
> .
> strcpy(name,"Any Valid Name");
>
>
> EXEC SQL INSERT INTO mytable (name) VALUES (:name);
> EXEC SQL COMMIT WORK REPLACE;
>
>
>The row is inserted with no problem. However, the field in the row only shows "
>ny Valid Name". The
>field is defined as "NAME CHAR(20)". Does anyone know what is happening
>here?
>Thanks.
>
>Rick
Tried to reach you by email but polaris.utswrk was unknown...
If you define a hostvariable for ESQL as a string of characters, your
hostvariable is NOT a string in C !
Instead it becomes a struct like this
struct
{ int len; char arr[20]; } name; So to insert your value don't do this strcpy(name,"A valid Name"); But do this strcpy(name.arr,"A Valid Name"); name.len = strlen("A Valid Name");
I have run into the same kine of problem you have and I've created a
little define which is quite helpfull :
#define sql_strcpy(hostvar, string) \
{strcpy(hostvar.arr,string);hostvar.len=strlen(string);}
And then you can use
sql_strcpy(name,"A Valid Name");
Hope this one helps...
-- Gerrit Cap {gerrit_at_vtm.be} Vlaamse Televisie Maatschappij N.V. Luchthavenlaan 22 B-1800 Vilvoorde BelgiumReceived on Wed Feb 10 1993 - 16:49:55 CET