#1 2022-08-08 10:40:28

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

REPLACE sql statement in REST

when using Batches we can set the 'boInsertOrReplace' to have replaced a row if its primary key is the same with the inserted new row.

How can we have it in ORM/REST add or addorupdate functions of mormot2?

If I understand it correctly, addorupdate is based on IDvalue to issue an add or an update.

How can we have an 'INSERT OR REPLACE' sql statement for ORM/REST in order not to have to check if a record with the same primary key value exists in the table ?

Thank you in advance

Last edited by dcoun (2022-08-08 10:41:26)

Offline

#2 2022-08-08 17:43:56

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

Re: REPLACE sql statement in REST

This is not yet supported - the idea is to make a manual Update then Add if the first failed...

Offline

#3 2022-08-08 17:44:54

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: REPLACE sql statement in REST

Thanks a lot @ab

Offline

#4 2022-08-08 17:45:48

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

Re: REPLACE sql statement in REST

Or to make a Retrieve() - which should be very fast if there is a cache enabled for the table - then Update or Add...

Offline

#5 2022-08-12 09:11:05

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: REPLACE sql statement in REST

ab wrote:

This is not yet supported - the idea is to make a manual Update then Add if the first failed...

I tried the above and it does not work
If record is missing, update returns true

Offline

#6 2022-08-12 09:23:25

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: REPLACE sql statement in REST

Trying to debug it, I noticed that in the update sql query no data are expected to be returned back. That is ok
But an update is not returning an error if the updated record does not exist
I am using ZEOS 8.0-patches branch from GitHub

I switched to your second suggestion that it is better I believe too
I issue an OneField requesting the RowID

function OneFieldValue(Table: TOrmClass; const FieldName: RawUtf8; WhereID: TID): RawUtf8;

Last edited by dcoun (2022-08-12 09:36:33)

Offline

#7 2022-08-12 12:57:06

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

Re: REPLACE sql statement in REST

You have IRestOrm.MemberExists() for checking if a ID does exist.

Offline

Board footer

Powered by FluxBB