NOTIFY/LISTEN in Postgresql

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

NOTIFY/LISTEN in Postgresql

Post by binfch » Thu 31 May 2012 09:05

Hi there

How can I use the NOTIFY/LISTEN interprocess communication mechanism in postgresql?

See http://www.postgresql.org/docs/9.1/stat ... otify.html

Thanks & cheers,
Peter

ROD
Devart Team
Posts: 23
Joined: Mon 07 May 2012 09:09

Re: NOTIFY/LISTEN in Postgresql

Post by ROD » Thu 31 May 2012 13:08

Hi

It is very easy. There is a special component for this - TPgAlerter.
With the help of its methods/properties/events the PostgreSQL NOTIFY/LISTEN gear is realized.
So, for example, a notification is sent by the procedure SendEvent(const MessageName: string; MessageText: string);
You can find more details in the context help of the TPgAlerter component.

Also, if you have bought PgDAC, you must have demo projects:
...\Demos\Win32\PgDacDemo\PgDacDemo.dpr
where you can see Alerter in action, watching the sources in parallel

binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

Re: NOTIFY/LISTEN in Postgresql

Post by binfch » Mon 04 Jun 2012 09:39

Thanks for the info!

Just for your Information.

-> In my Lazarus/Ubuntu IDE the component "TPgAlerter" is not shown on the component bar/panel (all the other components are well there!).

Thanks & cheers,
P.

binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

Re: NOTIFY/LISTEN in Postgresql

Post by binfch » Mon 04 Jun 2012 13:29

Hi there

I am unable to manually free the PgAlerter component in Lazarus/Ubuntu. The same code works fine under Delphi7. Here's my code:

Code: Select all

unit AlerterEventsLib; 

interface

uses
  Classes, SysUtils, DAAlerter, PgAlerter, DB, DBAccess, PgAccess;

type
  TAlerterEvents = class
  private
    PgConnection: TPgConnection;
    PgAlerter: TPgAlerter;
    procedure AlerterEvent(Sender: TObject; const EventName: AnsiString; PID: LongInt; const EventMessage: AnsiString);
  public
    constructor Create(const Channel: AnsiString);
    destructor Destroy;
  end;

implementation

uses
  Globals;

procedure TAlerterEvents.AlerterEvent(Sender: TObject; const EventName: AnsiString; PID: LongInt; const EventMessage: AnsiString);
begin
  WriteLn('Received Event:' + EventName);
end;

constructor TAlerterEvents.Create(const Channel: AnsiString);
begin
  PgConnection := TPgConnection.Create(nil);
  with PgConnection do begin
    Server := ConfigRecord.DatabaseServerIp;
    Port := ConfigRecord.DatabaseServerPort;
    Database := ConfigRecord.DatabaseName;
    Schema := ConfigRecord.DatabaseShema;
    Username := ConfigRecord.DatabaseUser;
    Password := ConfigRecord.DatabasePassword;
  end;

  try
    PgConnection.Connected := True;
    PgAlerter := TPgAlerter.Create(nil);
    PgAlerter.OnEvent := @AlerterEvent;
    with PgAlerter do begin
      AutoRegister := False;
      Connection := PgConnection;
      Events := Channel;
      Active := True;
    end;
  except
    WriteLn('Error Creating PgAlerter');
  end;
end;

destructor TAlerterEvents.Destroy;
begin
WriteLn('Start Destroy PgAlerter');
  PgAlerter.Active := False;
  PgAlerter.Free;
WriteLn('Done');       //<<<<< NEVER COMES UNTIL HERE

WriteLn('Start Destroy PgConnection');
  PgConnection.Connected := False;
  PgConnection.Free;
WriteLn('Done');
end;

end.
Thanks & cheers,
Peter

ROD
Devart Team
Posts: 23
Joined: Mon 07 May 2012 09:09

Re: NOTIFY/LISTEN in Postgresql

Post by ROD » Tue 05 Jun 2012 16:05

Hi

That's right, there is no such component for Linux.
We will check the workability of your code.

binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

Re: NOTIFY/LISTEN in Postgresql

Post by binfch » Tue 19 Jun 2012 11:30

Hi there

Any news on this?

Thanks & cheers,
P.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: NOTIFY/LISTEN in Postgresql

Post by AlexP » Wed 20 Jun 2012 11:51

hello,

Presently, TPgAlerter works only on Windows platform, we will try to support PgAlerter in Unix platforms in the next versions

binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

Re: NOTIFY/LISTEN in Postgresql

Post by binfch » Wed 20 Jun 2012 12:42

Hi there

Thx for the answer.

I am actually already using TPgAlerter quiet extensively in my Linux/FPC application (development stage). It seems to work just fine so far except that I can not free it correctly.

It would be a shame if I had to change my code again -> Can you give me a approximate date for the next release? If this is not too far I might be able to wait...

Thanks & cheers,
Peter

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: NOTIFY/LISTEN in Postgresql

Post by AlexP » Fri 22 Jun 2012 14:50

hello,

The new release of our products with support of the new two features, Data Encryption and Data Type Mapping, has just come out. Therefore the next release is expected not earlier then in a month

binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

Re: NOTIFY/LISTEN in Postgresql

Post by binfch » Fri 27 Jul 2012 08:45

Hi there

Is there any news on this resp. availability of the PgAlerter component for Lazarus/Ubuntu?

Thanks & cheers,
P.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: NOTIFY/LISTEN in Postgresql

Post by AlexP » Mon 30 Jul 2012 06:47

hello,

We are still working on this problem.
We will notify you as soon as we have any results.

binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

Re: NOTIFY/LISTEN in Postgresql

Post by binfch » Wed 29 Aug 2012 13:37

Hi there

Is there any workaround available yet?
I am stuck with this issue for 3 months now! I need a working TPgAlerter for Linux.

Thanks & cheers,
P.

binfch
Posts: 33
Joined: Sat 22 Jan 2011 09:26

Re: NOTIFY/LISTEN in Postgresql

Post by binfch » Thu 13 Sep 2012 06:44

Hi there

Can I assume that no answer = Good answer?

Comon guys you must be able to give some kind of timeline here! I am a paying customer and I am not requesting a new feature. All I expect is that an existing feature gets fixed (Since 4th of June actually)!

Thx & cheers,
Peter

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: NOTIFY/LISTEN in Postgresql

Post by ZEuS » Mon 17 Sep 2012 10:45

The working TPgAlerter component for Linux is the new feature of PgDAC, not just a fix of an existing feature.
TPgAlerter was never supported on Linux, because it widely uses such specific Windows mechanisms as messages and critical sections, the implementation of which in FPC is not good enough.
At the moment we are trying to adapt the TPgAleter component for Linux, and we will notify you when we have any results.

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: NOTIFY/LISTEN in Postgresql

Post by ZEuS » Wed 19 Sep 2012 14:12

We have adapted TPgAlerter for Linux. This component will be included in the next PgDAC build.

Post Reply