Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: How to use array of struct in pro*C

Re: How to use array of struct in pro*C

From: Frank Langelage <frank_at_lafr.de>
Date: Mon, 12 Mar 2001 23:02:30 +0100
Message-ID: <3AAD4776.A5F4753E@lafr.de>

comments embedded.

kevin Gao wrote:
>
> 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;

I think pointers don't work. You must use static areas. int _id[2] would work.
Additionally Type should be long, not int for datatype number.

> 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) */

To get the size of the array proc will probably do something like sizeof(_id) / sizeof(_id[0]) = sizeof(int*) / sizeof(int) = 4 / 4 = 1

>
> 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 */

I dont't know fore sure but I would try struct TT t1[2] above.

>
> /* 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?
>
> Thanks in advance!
>
> Kevin Gao
Received on Mon Mar 12 2001 - 16:02:30 CST

Original text of this message

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