#1 2018-08-30 13:36:24

isa
Member
Registered: 2018-01-09
Posts: 22

How to see changes since... for ORM Objects?

Hi,

I have developed an agenda using Delphi with a server and client, where I use ORM objects (TSQLRecords) as each appointment.
There is an automatic refresh system that refreshes the agenda every minute. But that is a full refresh, where the complete date range is re-retrieved that is currently visible on the client side.
That is rather overkill I want to refresh only if there are any changes done on the specific table where these appointment records are stored.

The only thing that I was able to find that came close to it was the audit system, which isn't very practical for this application, very resource heavy and is overkill. I only have to see IF ANY changes took place on said records table since Time X.
So is there any built in system in the ORM to check/track this easily through client side so that it knows it has to do a refresh / retrieve the changes on that table?
Or if not, how can I best implement this?

Thanks upfront

Last edited by isa (2018-08-30 13:36:59)

Offline

#2 2018-08-30 16:14:44

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

Re: How to see changes since... for ORM Objects?

Do you mean Master/Slave replication?
It is indeed global to the whole table.

There is no built-in mechanism in the ORM to track the changes of only a sub-part of the table.

But it could be very easy to add it in your business code:
1. add a "version" field which is incremented at every change (a global counter via InterlockedIncrement() is enough)
2. query for all records in a given range which have the "version"> latest version you got.

Offline

#3 2018-08-31 07:05:46

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

Re: How to see changes since... for ORM Objects?

Not at the ORM level but at the sqlite db engine level, few days ago I read an article on tracking sqlite table changes into JSON string, using triggers, not sure if it helps in your case: https://blog.budgetwithbuckets.com/2018 … gelog.html


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

Offline

#4 2018-08-31 07:15:04

isa
Member
Registered: 2018-01-09
Posts: 22

Re: How to see changes since... for ORM Objects?

ab wrote:

Do you mean Master/Slave replication?
It is indeed global to the whole table.

There is no built-in mechanism in the ORM to track the changes of only a sub-part of the table.

But it could be very easy to add it in your business code:
1. add a "version" field which is incremented at every change (a global counter via InterlockedIncrement() is enough)
2. query for all records in a given range which have the "version"> latest version you got.

Thanks for a quick reply.
I see, that's kinda like what I initially had in mind using the TModTime, but that still meant going to the server and doing a query on the table.
Now retrieving ONLY the "objects changed since ..." is one thing, which I can indeed handle with the version numbering like you said.

But more importantly I'm currently looking for something to see client side IF there is ANY change on the table, before I have to go and do a full query on the table.
Now I notice that there is a property called InternalState, is that something that can be used for what I described?

Offline

#5 2018-08-31 08:53:19

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

Re: How to see changes since... for ORM Objects?

Or you can use the OnUpdateEvent on the server side, this even is triggered when there is a update/insert/delete event happens on a specific table. Can you store a list of <tableName, LastUpdateTime> pairs in the memory, and expose an API to the clients.


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

Offline

#6 2018-08-31 12:33:07

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

Re: How to see changes since... for ORM Objects?

InternalState is for the whole table too.

Offline

Board footer

Powered by FluxBB