Victor Granados
2008-06-04 20:50:05 UTC
I have a problem. This is the porcedure involving a IBScript:
function TFTraspaso.Anade_SQL_Traspaso(FUE1, DES1, CAN1, SIPER1, COD1, NOM1,
VFUE1, VDES1, PINI1, PFIN1 : String) : String;
Var
Apoyo1: String;
begin
Apoyo1:='insert into TRASPASO (FUE, DES, CAN, SIPER, COD, NOM, VFUE, VDES,
PINI, PFIN) values ('+FUE1+', '+DES1+', '+CAN1+', ';
Apoyo1:=Apoyo1+SIPER1+',
'+''''+COD1+''','+''''+NOM1+''','+''''+VFUE1+''','+''''+VDES1+''','+''''+PINI1+''','+''''+PFIN1+''');'+#13#10;
Anade_SQL_Traspaso:=Apoyo1;
end;
procedure TFTraspaso.BtnGuardarClick(Sender: TObject);
Var
STemp, Ap01, Ap02, Ap03, Ap04, Ap05, Ap06, Ap07, Ap08, Ap09, Ap10: String;
AnchoIBS: Integer;
begin
If DatosPrinc.CDSQTemp2.RecordCount>0 then
begin
STemp:='BATCH START;'+#13#10;
DatosPrinc.CDSQTemp2.First;
While not(DatosPrinc.CDSQTemp2.Eof) do
begin
Ap01:=EdAlmacen1.Text;
Ap02:=EdAlmacen2.Text;
Ap03:=DatosPrinc.CDSQTemp2.FieldByName('COD').AsString;
Ap04:=DatosPrinc.CDSQTemp2.FieldByName('NOM').AsString;
Ap05:=FloatToStrF(DatosPrinc.CDSQTemp2.FieldByName('CAN').AsFloat,ffFixed,10,2);
Ap06:=ExiMod1;
Ap07:=ExiMod2;
If CheckBox1.Checked then
begin
Ap08:=FechaPunto(LabFecIni.Caption);
Ap09:=FechaPunto(LabFecFin.Caption);
Ap10:='True';
end
else
begin
Ap08:=FechaPunto(DateToStr(now));
Ap09:=FechaPunto(DateToStr(now));
Ap10:='False';
end;
STemp:=STemp+Anade_SQL_Traspaso(Ap01,Ap02,Ap05,Ap10,Ap03,Ap04,Ap06,Ap07,Ap08,Ap09);
AnchoIBS:=Length(STemp);
If AnchoIBS>64000 then
begin
STemp:=STemp+'BATCH EXECUTE;'; {** EJECUCION BATCH
UPDATE **}
ModuloModif.IBTransScript1.StartTransaction;
ModuloModif.IBScript1.Script.Text:=STemp;
ModuloModif.IBScript1.ExecuteScript;
If ModuloModif.IBTransScript1.InTransaction then
ModuloModif.IBTransScript1.Commit; {** EJECUCION BATCH
UPDATE **}
ModuloModif.IBScript1.Script.Clear;
STemp:='BATCH START;'+#13#10;
end;
DatosPrinc.CDSQTemp2.Next;
end;
STemp:=STemp+'BATCH EXECUTE;'; {** EJECUCION BATCH
UPDATE **}
ModuloModif.IBTransScript1.StartTransaction;
ModuloModif.IBScript1.Script.Text:=STemp;
ModuloModif.IBScript1.ExecuteScript;
If ModuloModif.IBTransScript1.InTransaction then
ModuloModif.IBTransScript1.Commit; {** EJECUCION BATCH
UPDATE **}
ModuloModif.IBScript1.Script.Clear;
DatosPrinc.CDSQTemp2.EmptyDataSet;
DatosPrinc.CDSQTemp2.Close;
DatosPrinc.CDSQTemp2.Open;
BtnArriba.Click;
LabNomCod.Caption:='';
end
else
MessageDlg('¡No hay movimientos a guardar!', mtError, [mbOk], 0);
end;
I receive some data in a Client Data Set and I want data be written in a
table with an IBScript. The problem is that this procedure checks if the
script length is > 64000 (because if it is, a too long string error would be
sent). So it executes the script and begins another one. But the result of
this is that It writes in the table only the last part of the script. Why?.
Am I missing something?
function TFTraspaso.Anade_SQL_Traspaso(FUE1, DES1, CAN1, SIPER1, COD1, NOM1,
VFUE1, VDES1, PINI1, PFIN1 : String) : String;
Var
Apoyo1: String;
begin
Apoyo1:='insert into TRASPASO (FUE, DES, CAN, SIPER, COD, NOM, VFUE, VDES,
PINI, PFIN) values ('+FUE1+', '+DES1+', '+CAN1+', ';
Apoyo1:=Apoyo1+SIPER1+',
'+''''+COD1+''','+''''+NOM1+''','+''''+VFUE1+''','+''''+VDES1+''','+''''+PINI1+''','+''''+PFIN1+''');'+#13#10;
Anade_SQL_Traspaso:=Apoyo1;
end;
procedure TFTraspaso.BtnGuardarClick(Sender: TObject);
Var
STemp, Ap01, Ap02, Ap03, Ap04, Ap05, Ap06, Ap07, Ap08, Ap09, Ap10: String;
AnchoIBS: Integer;
begin
If DatosPrinc.CDSQTemp2.RecordCount>0 then
begin
STemp:='BATCH START;'+#13#10;
DatosPrinc.CDSQTemp2.First;
While not(DatosPrinc.CDSQTemp2.Eof) do
begin
Ap01:=EdAlmacen1.Text;
Ap02:=EdAlmacen2.Text;
Ap03:=DatosPrinc.CDSQTemp2.FieldByName('COD').AsString;
Ap04:=DatosPrinc.CDSQTemp2.FieldByName('NOM').AsString;
Ap05:=FloatToStrF(DatosPrinc.CDSQTemp2.FieldByName('CAN').AsFloat,ffFixed,10,2);
Ap06:=ExiMod1;
Ap07:=ExiMod2;
If CheckBox1.Checked then
begin
Ap08:=FechaPunto(LabFecIni.Caption);
Ap09:=FechaPunto(LabFecFin.Caption);
Ap10:='True';
end
else
begin
Ap08:=FechaPunto(DateToStr(now));
Ap09:=FechaPunto(DateToStr(now));
Ap10:='False';
end;
STemp:=STemp+Anade_SQL_Traspaso(Ap01,Ap02,Ap05,Ap10,Ap03,Ap04,Ap06,Ap07,Ap08,Ap09);
AnchoIBS:=Length(STemp);
If AnchoIBS>64000 then
begin
STemp:=STemp+'BATCH EXECUTE;'; {** EJECUCION BATCH
UPDATE **}
ModuloModif.IBTransScript1.StartTransaction;
ModuloModif.IBScript1.Script.Text:=STemp;
ModuloModif.IBScript1.ExecuteScript;
If ModuloModif.IBTransScript1.InTransaction then
ModuloModif.IBTransScript1.Commit; {** EJECUCION BATCH
UPDATE **}
ModuloModif.IBScript1.Script.Clear;
STemp:='BATCH START;'+#13#10;
end;
DatosPrinc.CDSQTemp2.Next;
end;
STemp:=STemp+'BATCH EXECUTE;'; {** EJECUCION BATCH
UPDATE **}
ModuloModif.IBTransScript1.StartTransaction;
ModuloModif.IBScript1.Script.Text:=STemp;
ModuloModif.IBScript1.ExecuteScript;
If ModuloModif.IBTransScript1.InTransaction then
ModuloModif.IBTransScript1.Commit; {** EJECUCION BATCH
UPDATE **}
ModuloModif.IBScript1.Script.Clear;
DatosPrinc.CDSQTemp2.EmptyDataSet;
DatosPrinc.CDSQTemp2.Close;
DatosPrinc.CDSQTemp2.Open;
BtnArriba.Click;
LabNomCod.Caption:='';
end
else
MessageDlg('¡No hay movimientos a guardar!', mtError, [mbOk], 0);
end;
I receive some data in a Client Data Set and I want data be written in a
table with an IBScript. The problem is that this procedure checks if the
script length is > 64000 (because if it is, a too long string error would be
sent). So it executes the script and begins another one. But the result of
this is that It writes in the table only the last part of the script. Why?.
Am I missing something?