#1 2017-01-23 06:03:50

htits
Member
Registered: 2014-12-27
Posts: 10

Are there have an easy way to update one record ?

Are there have an easy way to update one record ?
select * from tablename where keyfield=?keyValue
if found
    update
else
    insert JSON

Offline

#2 2017-01-23 08:31:36

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

Re: Are there have an easy way to update one record ?

See TSQLRest.AddOrUpdate if keyfield is ID.
https://synopse.info/files/html/api-1.1 … DDORUPDATE
But it will depend on the supplied ID value (0 or not 0).

Otherwise, there is no such a direct method, since a command like REPLACE is not supported directly by all SQL dialects.
You should rather use an aggregate record, and update internal fields depending on your business logic.

Offline

#3 2017-01-23 12:25:17

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

Re: Are there have an easy way to update one record ?

@ab, is there a way for us to extend the TSQLRestBatch class to support the real "INSERT OR REPLACE" operation supported by SQLITE? Thanks.


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

Offline

#4 2017-01-23 13:00:52

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

Re: Are there have an easy way to update one record ?

Isn't it already there as a batch option?

Offline

#5 2017-01-23 22:52:58

htits
Member
Registered: 2014-12-27
Posts: 10

Re: Are there have an easy way to update one record ?

In my old project, I got tableName and delta (in TFDMemTable & TClientDataset, What Log changs), It can easy save to Datasnap's Server.
If I serializate tableName and delta  to Json,
How I save the Json to mORMot's server?

Offline

Board footer

Powered by FluxBB