#1 2016-11-17 07:09:10

bagusprasojo
Member
Registered: 2016-07-26
Posts: 18

How to rollback transaction using batch processing in server side?

How to rollback transaction when it fails to execute BatchSend menthod in server side. Here is my code :

  Batch := TSQLRestBatch.Create(RestServer, TMorAssetSplit);
  try
	AAssetSplit.IDValue := 10000; // I do it on purpose to get Error
	Batch.Add(AAssetSplit, True, True);
	Batch.Add(AAssetSplit, True, True); // I do it on purpose to get Error
    
    RestServer.BatchSend(Batch);    
  finally    
    Batch.Free;
  end;

I execute the above code on server. It generates error when trying to save the 2nd AAssetSplit because it has same ID (10000). But when i check in database, the frist AAssetSplit is Saved. How to rollback transaction in batch processing ?

Offline

#2 2016-11-17 17:45:00

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

Re: How to rollback transaction using batch processing in server side?

Enable a transaction during the batch.

Offline

#3 2016-11-18 00:22:13

bagusprasojo
Member
Registered: 2016-07-26
Posts: 18

Re: How to rollback transaction using batch processing in server side?

ab wrote:

Enable a transaction during the batch.

How to do it AB ?

Should I change my code to :

  Batch := TSQLRestBatch.Create(RestServer, TMorAssetSplit, 5);
  try
	AAssetSplit.IDValue := 10000; // I do it on purpose to get Error
	Batch.Add(AAssetSplit, True, True);
	Batch.Add(AAssetSplit, True, True); // I do it on purpose to get Error
    
    RestServer.BatchSend(Batch);    
  finally    
    Batch.Free;
  end;

Offline

#4 2016-11-18 09:27:49

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

Re: How to rollback transaction using batch processing in server side?

Yes

Offline

#5 2016-11-18 10:33:54

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: How to rollback transaction using batch processing in server side?

@ab,

I thought even if the AutomaticTransactionPerRow parameter is leaved to 0, a transaction will still be created for the rows being inserted/updated?!
Looks I was wrong...


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#6 2016-11-23 01:11:51

bagusprasojo
Member
Registered: 2016-07-26
Posts: 18

Re: How to rollback transaction using batch processing in server side?

ab wrote:

Enable a transaction during the batch.

Hi DB I did what you suggested, but I got another trouble. When i enable a transcation during the bact for every 5 rows the application stop / hang when it tries to save the 2nd object, the table may be locked confilict. My Database is MS SQL Server. I can not execute query for this table until i shutdown my application.

I Think mormot fail to rollback transaction.

Offline

#7 2016-11-23 08:02:25

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

Re: How to rollback transaction using batch processing in server side?

@bagusprasojo
Ensure you get the latest version of mORMot trunk.

Offline

Board footer

Powered by FluxBB