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 -> Re: SQL-Pro*C++ : Copying char* into VARCHAR

Re: SQL-Pro*C++ : Copying char* into VARCHAR

From: Ed Prochak <prochak_at_my-dejanews.com>
Date: Thu, 11 Feb 1999 04:44:37 GMT
Message-ID: <79tn7i$cg$1@nnrp1.dejanews.com>


In article <36C08209.A18B7590_at_eurocontrol.fr>,   Serge LUCAS <Serge.Lucas_at_eurocontrol.fr> wrote:
> I have a littele problem, which must have already be solved by many
> people:
>
> void MyClass::f(char* str)
> {
> EXEC SQL BEGIN DECLARE SECTION;
> VARCHAR dest[20];
> EXEC SQL END DECLARE SECTION;
>
> strcpy(dest,str);
>
> //EXEC SQL INSERT etc...
> }
>
> Since the precompiler transform the VARCHAR as an unsigned char[20], the


this assumption of yours is wrong----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> c++ compiler tells me:
>
> Argument type 'unsigned char[20]' does not match expected parameter type
> 'const char *'.
> strcpy(dest,str);
> ^^^^

The compiler is right. The types do not match! VARCHAR is a counted string, and as such is transformed by the precompiler into a structure:

struct {
  unsigned short len;
  unsigned char arr[20];
} dest;

>
> Does anybody has a solution to this very simple problem ?
>
> Thanks!
> --
> Serge LUCAS
> STERIA ATM/Eurocontrol

I hope you can figure it out from there. Note that Oracle DOES NOT put the nul terminator at the end of the string. You must use counted string handling, ie, use strncpy() instead of strcpy().

Ed Prochak
Magic Interface, Ltd.
ORACLE services for LINUX and other platforms 440-498-3702

-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Wed Feb 10 1999 - 22:44:37 CST

Original text of this message

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