#1 2016-10-05 02:50:52

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

How To Save 2 TSQLRecord in the same time ?

Hi, I have 2 objects of TSQLRecord (TFahter and TChildren). I Want to save both in the same time. How should I do it ? How to define Transcation and commit ?

Thank You

Last edited by bagusprasojo (2016-10-05 03:02:45)

Offline

#2 2016-10-05 04:03:54

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

Re: How To Save 2 TSQLRecord in the same time ?

It's recommended to use "batch mode":

http://synopse.info/files/html/Synopse% … l#NDX_1604

When creating the TSQLRestBatch instance, supply 'nil' for the 'aTable' param.

Caveat: When calling Add/Delete/Update methods of it, don't forget to pass the correct 'TSQLRecord' subclass, otherwise it won't work **siliently** ( suggested @ab to raise exception in this case, but he don't agree smile.


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

Offline

#3 2016-10-06 02:21:36

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

Re: How To Save 2 TSQLRecord in the same time ?

Hi edwinsn thank you for your quick response.

I did it using "batch mode" also. But I got trouble when TFahter has property refers to TChildren. Everytime I save those objects, field Children in table TFather is always "0". I don't know how to use "batch mode" in this case.

Thanks

Offline

#4 2016-10-10 17:53:32

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: How To Save 2 TSQLRecord in the same time ?

You need to do two transactions to achieve this. Because TSQLRecord.Add() needs to be commited to get the ID.

Offline

#5 2016-10-10 18:07:22

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

Re: How To Save 2 TSQLRecord in the same time ?

You can force the ID, using an incremental integer on the server side, or TSynUniqueIdentifier if you want something unique over a network.

Offline

#6 2016-10-10 18:12:48

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: How To Save 2 TSQLRecord in the same time ?

Nice idea AB!

Offline

#7 2016-11-10 04:58:59

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

Re: How To Save 2 TSQLRecord in the same time ?

ab wrote:

You can force the ID, using an incremental integer on the server side, or TSynUniqueIdentifier if you want something unique over a network.


Hi AB, how to Force ID if ID is readonly property ?

Thanks

Last edited by bagusprasojo (2016-11-10 04:59:25)

Offline

#8 2016-11-10 05:16:12

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

Re: How To Save 2 TSQLRecord in the same time ?

Try IdValue.


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

Offline

#9 2016-11-17 07:22:17

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

Re: How To Save 2 TSQLRecord in the same time ?

OK, Solved ! Thank you all

Offline

Board footer

Powered by FluxBB