#1 2014-04-30 14:06:16

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Problem with TransactionBegin

Hi, i wrote one first Program for Mormot. The Task is easy copying data from one SQLite3 Table to mORMot ORM.
To speed it up i use TransactionBegin and BatchStart ...

examplecode in Client - App (Server is as Project Sample 04):

  procedure AddTestRecord(const AField1, AField2, ... : String);
  var
    test : TSQLTestRecord;
    id : integer;
  begin
    test := TSQLTestRecord.Create;
    try
      test.field1 := AField1;
      test.field2 := AField2;
      id := Database.Add(test, true);
    finally
      test.Free;
    end;
  end;

var
  props: TSQLDBConnectionProperties;
  I : ISQLDBRows;
  G : Variant;
  Results: TIntegerDynArray;
begin
  if FileExists('source.db') then begin
    props := TSQLDBSQLite3ConnectionProperties.Create(StringToUTF8('source.db'),'','','');
    try
      I := props.Execute('select * from sourcetable', [], @G);
      if Database.TransactionBegin(TSQLTestRecord) then try
        Database.BatchStart(TSQLTestRecord);
        while I.Step do
          AddTestRecord(G.field1, G.field2, ...);
        Database.BatchSend(Results);
        Database.Commit;
      except
        Database.RollBack;
      end;
    finally
      props.Free;
    end;
  end;
end;

On normal Processing everything works fine !

But i debugged the Program with the Debugger and if i abort the Program with (STRG+F2) in AddTestRecord, i had to restart the Serverapp before starting the client a second time because TransactionBegin failed.
So my Question: what should a client Program do if there is an unclosed Transaction (from another Session) on the ServerApp ?

In Praxis there could be an interrupt in Transmissiting Data from a client.

Last edited by itSDS (2014-04-30 14:07:08)


Rad Studio 12.1 Santorini

Offline

#2 2014-04-30 23:00:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Problem with TransactionBegin

Are you using latest version from nightly zip?

Online

#3 2014-05-03 09:24:18

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Problem with TransactionBegin

Yes was using zip from 22.4.2014


Rad Studio 12.1 Santorini

Offline

#4 2014-05-05 08:48:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Problem with TransactionBegin

You are mixing:
- SQL statements and ORM statements (not a good practice);
- BATCH commands and non BATCH commands - your add does NOT use BATCH: AFAIK you should use BatchAdd() and not Add() in AddTestRecord.

Online

#5 2014-05-13 14:34:39

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Problem with TransactionBegin

Thanks for the answer, i changed add -> batchadd but my real Problem still persists.

It is not easy to explain for me in english. But i try with an example.

I have 2 Programm

One is the Server as in Example 004.
This Programm i start from Windows.

The Second Programm is the one I'm developing on. Lets call it Client.

I start Client and set Breakpoint in the "BatchAdd" - Loop in AddTestRecord....
As Breakpoint is reached i stop debugging with STRG+F2.
The Server does not get Rollback nor Commit.

I start Debugging again with Server running from prior test.
Now StartTransaction results in false.
Why this - the Client was restartet ?! Session is broken ?!
As Consequence i have to restart the Server. This is not good. In Practice there may be the same Problem if Client loses Connection in the loop.

The Point and my Question is how to debug without restarting the Server ?
Is there a Rollback for prior open Transactions or anything else ?

Or other Question I only use Transaction to speed it up - is this neccessary ?

Last edited by itSDS (2014-05-13 14:36:33)


Rad Studio 12.1 Santorini

Offline

#6 2014-05-13 16:23:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Problem with TransactionBegin

Please try not to use at all TransactionBegin/Commit in Client/Server mode, but BatchStart() and setting the AutomaticTransactionPerRow parameter to some high value.
Ensure you got the latest source code (at least for this morning).

Online

Board footer

Powered by FluxBB