Recent

Author Topic: SQLQUERY dont update table  (Read 3062 times)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 446
SQLQUERY dont update table
« on: March 15, 2015, 12:30:57 am »
I have this code all looks good also i dont received any message error but dont insert nothing on my table, SQLQTT "formaqc"table is temporal has 3 records but i need pass to SQLQCF "detaqcrep" , what  I doing wron pls help me.

 
Code: [Select]
Var STream:TStream;
begin
//   SQLQCF.UpdateMode := upWhereAll;
   SQLQTT.First;
   while not SQLQTT.EOF do begin

    if(SQLQTT.FieldByName('NewRec').AsBoolean = True) then begin
     with SQLQTT do begin
            Stream:=CreateBlobStream(SQLQTT.FieldByName('mesurements'),bmRead);
           with SQLQCF do begin
                 Insert;
                 FieldByname('NumPart').AsString := FormCtrlPart.SQLQPartes.FieldByName('NumPart').AsString;
                 FieldByname('ViewGpo').AsString := SQLQTT.FieldByName('ViewGpo').AsString;
                 FieldByname('ViewDesc').AsString := SQLQTT.FieldByName('ViewDesc').AsString;
                 FieldByname('FoliosGpo').AsInteger := SQLQTT.FieldByName('FoliosGpo').AsInteger;
                 FieldByname('ProcCode').AsString :='0';
                 if( Stream <> nil) then
                     TBlobField(SQLQCF.FieldByName('mesurements')).LoadFromStream(Stream);
                 Post;
                 Stream.Free;
           end;
           SQLQCF.ApplyUpdates;
       end;
    end;
    SQLQTT.Next;
  end;
//  FormPrinc.SQLTMSC.CommitRetaining;
  FormPrinc.SQLTMSC.Commit;
  SQLQTT.Close;
  SQLQCF.Close;
  FormQC.Close;
  FormCtrlPart.DBGrid1.Refresh;

thanks for all.

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: SQLQUERY dont update table
« Reply #1 on: March 15, 2015, 04:31:25 am »
One thing that catches my eye is the nested WITH statements. Can it be that when Post is called, it is called for SQLQTT instead SQLQCF and that causes the problem. Post exists in both SQLQCF and SQLQTT so which one gets the call?:

Code: [Select]
with SQLQTT do begin
  with SQLQCF do begin
    Post;

Something else that often causes this is that Commit is not called, but that doesn't seem to be the case here.

You could also show us the Insert SQL code.
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: SQLQUERY dont update table
« Reply #2 on: March 15, 2015, 05:49:23 am »
One thing that catches my eye is the nested WITH statements. Can it be that when Post is called, it is called for SQLQTT instead SQLQCF and that causes the problem. Post exists in both SQLQCF and SQLQTT so which one gets the call?:
The rule is that identifiers are searched from the innermost scope outward, so in this case, SQLQCF.Post is called.

The use of nested with like this is dangerous though, according to my experience, since the silent identifier shadowing could happen anytime (either from you or any libraries you use). When doing assignments between two variables of the same type, either use just one with or don't use it at all.

eldonfsr

  • Sr. Member
  • ****
  • Posts: 446
Re: SQLQUERY dont update table
« Reply #3 on: April 01, 2015, 05:19:07 am »
OK I understand, i going to change my program and thanks for your help.


 

TinyPortal © 2005-2018