Lazarus

Programming => Databases => Topic started by: pcurtis on January 19, 2021, 08:59:16 pm

Title: Database change
Post by: pcurtis on January 19, 2021, 08:59:16 pm
Hi All,

whats the best / correct way to be informed of changes to a DB / dataset?

I use Zeos and Sqlite

Thanks in advance.
Title: Re: Database change
Post by: Zvoni on January 20, 2021, 08:04:39 am
sqlite itself has a notification callback
https://sqlite.org/c3ref/update_hook.html
Title: Re: Database change
Post by: madref on January 20, 2021, 09:03:50 am
When ever I use a form that has data from my database I use a query to get the specific data I need from that database.
When that query has changed I update it.


To check if the query is changed I use
Code: Pascal  [Select][+][-]
  1.   if TQ_Evaluatie.State in [dsEdit, dsInsert] then
  2.   begin
  3.     TQ_Evaluatie.Post;
  4.     TQ_Evaluatie.ApplyUpdates;
  5.     if Form_Lint.Trans_RefereeDB.Active then
  6.       Form_Lint.Trans_RefereeDB.CommitRetaining;
  7.   end;
Title: Re: Database change
Post by: cdbc on January 20, 2021, 10:09:05 am
Hi
Implement the Observer pattern...
It is built in, in the LCL (TObserved) in TPersistent
You only need to build an Observer, with one method
If need be, "steal" the implementation of TObserved in TPersistent and put it in your db-code  ;)
Two small classes with enormous effect.
HTH
Regards Benny
Title: Re: Database change
Post by: pcurtis on January 20, 2021, 11:33:55 am
@zvoni - any idea how to implement this in laz / fpc?
Title: Re: Database change
Post by: Zvoni on January 20, 2021, 01:31:26 pm
@zvoni - any idea how to implement this in laz / fpc?
Probably as a class-helper for sqlite3conn (never worked with Zeos).
You should check first if the external function is already declared available in sqlite3conn (at least that's the place i would look in)
The link describes the prototype of the Function which acts as a "Event"-Handler. From there......
TinyPortal © 2005-2018