Board index » delphi » how to writing sql sentence when sentence'count is large

how to writing sql sentence when sentence'count is large

hello,everyone!
  I use Delphi5.0 and SQLserver7.0. In my application I need to add sql sentences that it count to 1000. when I run the application, there are always errors.

here is the application:
var
   i:integer;
begin
     i:=0;
       while i<=1000 do begin
         WITH querypub do begin
         sql.add('insert into ptree_tmp1
            (n_id,zyh,mx_no,zyh_parent,userid,n_level,tmp_nid,tmp_parent,quantity)
            values("1","1",0,"1","1",1,"1","1",1)');
         end;
         i:=i+1;
       end;
         try
           querypub.execsql;
         except
           abort;
         end;
end;

 I open the profiler window and find out the error:

when I run the application,the SQL server locked. when I open the
insert into ptree_tmp1 (n_id,zyh,mx_no,zyh_parent,userid,n_level,t:p_nid,tmp_parent,quantity) values("1","1",0,"1","1",1,"1","1",1)
insert into ptree_tmp1 (n_id,zyh,:x_no,zyh_parent,userid,n_level,tmp_nid,tmp_parent,quantity) values("1","1",0,"1","1",1,"1","1",1)

I don't know why there is a ":" in the sentence.I don't know how to overcome the problem.

sorry for my poor English, thanks for any help.

 

Re:how to writing sql sentence when sentence'count is large


TQuery handles one query at a time, so try the following :

 var
    i:integer;
 begin
      i:=0;
      while i<=1000 do begin
          querypub.sql.Text:='insert into ptree_tmp1 [...]';
          querypub.execsql;
          i:=i+1;
      end;
 end;

I'm not too convinced by the content of your original query though...

Eric Grange

Other Threads