Re: missing row in a table

From: David R. Barstis <david_r_barstis_at_med.umich.edu>
Date: 9 Mar 1993 19:59:34 GMT
Message-ID: <david_r_barstis-090393144915_at_no-name-medadmin.med.umich.edu>


In article <0ezv03tBccTT00_at_amdahl.uts.amdahl.com>, rtan_at_polaris.uts.amdahl.com (Rick Tan) wrote:
>
> I wrote the following C program with embedded SQL
>
> cnt=10;
> .
> .
> for (i=1; i<=10; i++) {
> .
> .
> EXEC SQL INSERT INTO mytable (xyz, abc) VALUES (:xyz, :abc);
> }
> EXEC SQL COMMIT WORK;
>
>
> This works fine except that only 9 rows are inserted into my table. Any ideas what's happening here?
> If I change the loop count to 3, all three rows are inserted.
>
> Thanks for any help.
>
> Rick

Since I don't know what your array size is, and I'm assuming you are not using the 0 occurance of the array, I can only suggest the following:

Load your array - including the 0 occurance - and use a subscript declared in your host variable section. Then you only need to execute the following statement once - not in a loop.

     EXEC SQL FOR :sub
          INSERT INTO mytable (xyz, abc)
          VALUES (:xyz, :abc);

Where :xyz and :abc are declared in the host variable section as char xyz[99][10];
int abc[10];
Don't forget int sub; sub will contain the actual number of rows to be inserted. Add 1 to it after you load the array variable i.e load 0 then add 1 to sub.

I hope this helps.
Dave Barstis.
E-mail: david_r_barstis_at_med.umich.edu

"I'm so broke I can't even pay attention!" Received on Tue Mar 09 1993 - 20:59:34 CET

Original text of this message