Re: using Array of struct in Pro*C++

From: Pierre Charpenay <pcharpenay_at_unilog.fr>
Date: Mon, 12 Mar 2001 13:06:12 +0100
Message-ID: <3AACBBB4.6FDABDA1_at_unilog.fr>


kevin Gao a écrit :
>
> Hi, all:
> I read Oracle white paper and some paper on the internet. They said
> Oracle V8.0.4 supports struct array for insert/query and pointer but I have
> some problem to implement it (I am using V8.0.4).
>
> E.g.
>
> EXEC SQL BEGIN DECLARE SECTION;
> typedef struct TT {
> char name[10];
> int id } T;
> T t1[2];
> int *_id;
> EXEC SQL END DECLARE SECTION;
>
> void main()
> {
> _id = malloc(sizeof(int )*2);
> int ii;
>
> EXEC SQL SELECT id INTO :_id FROM test; /* suppose test table just has two
> rows for id */
> /* it doesn't work. error msg: select too many rows. I believe Pro*c still
> think *_id = _id (one row) */

That's right ! So, just declare : "int _id[2];" and it will work.

>
> strcpy(t1[0].name,"Jordan");
> t1[0].id = 12;
>
> strcpy(t1[1].name, "Mason");
> t1[1].id = 14;
>
> EXEC SQL INSERT test(name, id) VALUES (:t1);
> /* it doesn't compile. Error msg: using array of structs require that the
> structs be named */

Not sure, but I think you can only use full structure of arrays, but not full array of structures ... So, "struct { char name[2][10]; int id[2]; } t1;" will work like you want.  

>
> /* it works following but it is NOT really I want it.*/
> for(ii = 0;ii<2;ii++)
> {
> EXEC SQL INSERT test(name, id) values(:t1[ii]);
> }
>
> EXEC SQL SELECT * INTO :t1 FROM TEST;
> /* it doesn't compile. Error msg:using array of structs require that the
> structs be named */
> }
>
> Could I declare point of struct and dynamically allocate this struct and
> then use it for insert and query?

May be it's possible with the "FOR n" clause (never used with struct, but it works with arrays).

>
> Thanks in advance!
>
> Kevin Gao
 

-- 
 Pierre CHARPENAY
Received on Mon Mar 12 2001 - 13:06:12 CET

Original text of this message