Jump to content

MrSpock1

Members
  • Content Count

    2
  • Joined

  • Last visited

Posts posted by MrSpock1


  1. Delphi, SQlite and dbExpress
    I open two copies of the app. I have one SQLConnection and two SQLQuery.
    SQLQuery1.SQL:=insert into topics(da,topic) values(1,'1')
    SQLQuery2.SQL:=insert into topics(da,topic) values(2,'2')

    there is a suspicious
    var
      Form1: TForm1; in the interface part, which I do not know how to remove

    In form.oncreate
    SQLConnection1.Connected:=true

    The first copy runs the first code


    Code:
     

    procedure TForm1.Button2Click(Sender: TObject);
    var
       tr: TTransactionDesc;
       finished: boolean;
    begin
      try
        SQLQuery2.SQLConnection:=SQLConnection1;
        SQLConnection1.StartTransaction(tr);
        SQLQuery2.ExecSQL;
        sleep(4000);
        SQLConnection1.Commit(tr);
        finished:= true;
        SQLQuery2.SQLConnection:=nil
      except
        SQLConnection1.Rollback(tr);
        finished:= false;
      end;
      if finished
      then
        showmessage('OK')
      else
        ShowMessage('NOT OK');
    end;


    and the second copy runs the second code

    Code:
     

    procedure TForm1.Button3Click(Sender: TObject);
    var
      tr: TTransactionDesc;
      finished: boolean;
    begin
      repeat
        try
          SQLQuery3.SQLConnection:=SQLConnection1;
          SQLConnection1.StartTransaction(tr);
          SQLQuery3.ExecSQL;
          SQLConnection1.Commit(tr);
          finished:= true;
          SQLQuery3.SQLConnection:=nil;
          memo1.Lines.Add('OK')
        except
          sleep(400);
          SQLConnection1.Rollback(tr);
          finished:= false;
          memo1.Lines.Add('NOT OK')
        end;
      until finished;
      memo1.Lines.Add('END')
    end;

    When I run the codes one after another I get all right two records inserted into the database, but when I start the second code  before the first transaction finishes, I get both OK messages but there appears only one record inserted in the database. The second transaction waits normally until the first finishes.

×