Page 1 of 1

Insert multiple times gets optimized away.

Posted: 01.04.2011, 09:56
by marcov
I've a TZQuery with the an insert into statement.

I run this 5 times with the same parameters in a for loop, which should result in 5 rows with different autonumbered ids.

However only one or two rows are inserted (and only those commands are visible in sql monitor).

The for loop is a bit braindead

for i:=0 to number-1 do
begin
qry.execsql;
qry.active:=true;
end;

Even if I add some parameter that forces the tuples to be different (I put the loopcounter in some memo) this still happen.

What is the proper way of doing this?

Posted: 04.04.2011, 07:06
by Wild_Pointer
marcov,

Code: Select all

for i:=0 to number-1 do 
begin 
  qry.execsql; 
end;

should be enough. If you still experience problems try replacing qry.execsql with qry.close; qry.open; commands. It you do only qry.active:=true - only the first time it gets executed as after that qry is active already and no work is done.

Good luck!