Re: Pro*C and VARCHAR pointer arrays

From: Ian A. MacGregor <ian_at_unixhub.SLAC.Stanford.EDU>
Date: 23 Jan 92 19:56:57 GMT
Message-ID: <3149_at_unixhub.SLAC.Stanford.EDU>


In article <1198.297d8a98_at_hermes.dlogics.com>, dlm_at_hermes.dlogics.com writes:
|>ppe_at_niksula.hut.fi (Petri Pellinen) writes:
|>> My Pro*C compiler for MS-DOS makes an interesting error when compiling
|>> VARCHAR pointer arrays. If I say in a Pro*C program:
|>>
|>> VARCHAR *foo[7];
|>> [... it didn't work the way he expected!]
|>
|>Pro*C 1.3 does not support pointers-to-VARCHAR; your choices are:
|>o char[]
|>o char*
|>o VARCHAR[]
|>when the array notation is used, it means that you are specifying the maximum
|>string length. when the pointer notation is used, it means that you
 must ensure
|>that the pointed-to array is large enough.
|>
|>in general you CANNOT precompile pointers-to-arrays nor arrays-of-pointers
|>DIRECTLY with the precompiled SQL.
|>
|>Of course, if you must have arrays of varchars you can simulate this
 in various
|>ways, but the additional work is up to you, using the basic types above.
|>--
|>Dave Mausner, Senior Consultant / Datalogics Inc / Chicago IL / 312-266-4450
|>dlm_at_dlogics.com Motto: Just show me the code

On VMS one can however, do this:
EXEC SQL BEGIN DECLARE SECTION;
short int foonum;
VARCHAR *foobar
EXEC SQL END DECLARE SECTION; ... main()
{ foonum =10;

    foobar = malloc(sizeof(short) + foonum);     if (!foobar) handle error;
     foobar->len = foonum;




This code is not necessarily transportable to other operating systems. I have never tried

    foobar = malloc((sizeof(short) +foonum) * 100) or something similar, and do not know if it works as well.

                       Ian MacGregor
                     [Stanford Linear Accelerator Center]

             

 
     
   
                       
Received on Thu Jan 23 1992 - 20:56:57 CET

Original text of this message