Recent

Author Topic: Database change  (Read 666 times)

pcurtis

  • Sr. Member
  • ****
  • Posts: 491
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 / Linux Mint 20
Laz 2.0.12
FPC 3.2.0

Zvoni

  • Hero Member
  • *****
  • Posts: 518
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 IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

madref

  • Hero Member
  • *****
  • Posts: 832
  • ..... 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 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

cdbc

  • Sr. Member
  • ****
  • Posts: 353
    • 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 ;)

pcurtis

  • Sr. Member
  • ****
  • Posts: 491
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 / Linux Mint 20
Laz 2.0.12
FPC 3.2.0

Zvoni

  • Hero Member
  • *****
  • Posts: 518
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 IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

 

TinyPortal © 2005-2018