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 -> this could be a solution...

this could be a solution...

From: AGNELLO Fabrice <fagnello_at_micropole.com>
Date: Mon, 22 Feb 1999 12:54:00 +0100
Message-ID: <9D3B96D19579D211B33300A0C9B3F22909B663@communication.micropole.com>


if you want to copy a varchar into a char* through a function, you could do
as follow...

void recopy( char *dest, varchar *src ) // oracle won't precompile this line, since we have a pointer onto { // a
varchar..

	memcpy( dest, src +sizeof( src->len ), src->len );
	*( dest +src->len ) = 0;

}

this way, you copy all the characters in src ( the copy begins at offset SRC adress + size of the LEN field which is two bytes long )...

You should have any precompilation error with this, and it works pretty fine.

just one thing : don't forget to allocate dest to the right length ( which should be src->len +1 )....

C U...
Fab. :-)

-----Original Message-----
From: Serge LUCAS [mailto:Serge.Lucas_at_eurocontrol.fr] Posted At: Monday, February 22, 1999 10:27 AM Posted To: misc
Conversation: Pro*C: copying VARCHAR into char* Subject: Pro*C: copying VARCHAR into char*

I have declared in SQL-Pro*C a VARCHAR variable:

        VARCHAR SRC[30];
developped by the precompiler as:

        struct {unsigned short int len;unsigned char* arr;} SRC;

and want to copy it in a char*:

        strncpy(dest,SRC.arr,SRC.len);

Strncpy copies 'len' characters of SRC in dest, but does not copy a '\0' at the end.
So I must add :

        dest[SRC.len]='\0';

but Is there a better way to do it, in one line for exemple:

        recopy(dest, SRC) ???

If I try to define :

        struct OracleVARCHARtype {unsigned short int len;unsigned char* arr;};
and:

	void recopy(char* dest, OracleVARCHARtype src)
	{
	 strncpy(dest, src.arr,src.len);
	 dest[src.len]='\0';
	}

I have many syntax errors of the C++ compiler. (parameter not defined const, unsigned char* instead of char*, etc...)

Does somebody has a solution ?
--
Serge LUCAS
STERIA ATM/Eurocontrol
BS-012
Tel 01 69 88 74 15
Fax 01 69 88 73 33
Mel lua_at_eurocontrol.fr Received on Mon Feb 22 1999 - 05:54:00 CST

Original text of this message

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