English (en) │
русский (ru) │
TFBEventMonitor in the FBEventMonitor unit is used to monitor named events sent from the Firebird database server. Events are typically generated by triggers on certain database operations.
Using events means you can avoid regularly polling the database for status changes and can be useful in cases of high load.
Updating a memo with events received. Monitoring events E1 through E7.
procedure TForm1.StartMonitor; begin EventsM:=TFBEventMonitor.create(Self); EventsM.Connection:=IBConnection1; EventsM.Events.CommaText:='"E1",E2,E3,E4,"E5","E6","E7"'; //quotes are ignored EventsM.OnEventAlert:=OnFBEvent; EventsM.RegisterEvents; // will activate IBConnection1 if not connected end; procedure TForm1.StopMonitor; begin EventsM.UnRegisterEvents; EventsM.Free; end; procedure TForm1.OnFBEvent(Sender: TObject; EventName: string; EventCount: longint; var CancelAlerts: boolean); begin Memo1.Lines.Add(EventName+' occurred '+IntToStr(EventCount)+' times.'); end;
The event monitor stops monitoring when the linked TIBConnection is disconnected and will not restart automatically. Use the TIBConnection.AfterConnect and TIBConnection.BeforeDisconnect event handlers to start and stop the monitoring automatically.
The database server sends events to all connections registered for these events except for those created by the connection itself. Events are sent after a transaction is committed. Rolling back a transaction will cancel all events created in that transaction. fbeventstest.pp in the fcl packages/fcl-db/examples/ directory is a test/demo program that creates a stored procedure to send an event with an arbitrary name and uses a second connection to monitor the events sent.
Warning: TFBEventMonitor creates a thread to monitor incoming events. On Unix include cthreads or any other thread manager.
- Using Firebird with FPC/Lazarus sqldb.
- Firebird documentation/readme files on events
- Presentation on Firebird events