Recent

Author Topic: Database change  (Read 1407 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Database change
« 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.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Database change
« Reply #1 on: January 20, 2021, 08:04:39 am »
sqlite itself has a notification callback
https://sqlite.org/c3ref/update_hook.html
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Database change
« Reply #2 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;
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

cdbc

  • Hero Member
  • *****
  • Posts: 1026
    • http://www.cdbc.dk
Re: Database change
« Reply #3 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
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Database change
« Reply #4 on: January 20, 2021, 11:33:55 am »
@zvoni - any idea how to implement this in laz / fpc?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Database change
« Reply #5 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......
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018