PostgreSQL: Capturing NOTIFICATIONS FROM USER CONNECTION from a client connection through ZeosLib / Lazarus

I developed a client application using RDBMS PostgreSQL 8.4.

My application is written in Lazarus and ZeosLib 7.2 to access the database.

I use a lot of stored procedures, and at a certain point I use a raise notification to get information about the status of the procedure, Es:

RAISE NOTICE 'Step 1: Import Items from CSV file';
....
....
RAISE NOTICE 'Step 2: Check Items data';

When I execute the procedures in PgAdmin3, it shows a notification on the Messages tab. Is there a way to capture elevated notifications in my client application?

+4
source share
1 answer

, , , :

uses
    Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    ZConnection, ZDbcPostgreSql;

type

    { TForm1 }

    TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        pgConn: TZConnection;
        procedure Button1Click(Sender: TObject);
        procedure pgConnAfterConnect(Sender: TObject);
    private
        { private declarations }
    public
        { public declarations }
    end;

var
    Form1: TForm1;

implementation

{$R *.lfm}

procedure PGNotifyProcessor(arg: Pointer; message: PAnsiChar); cdecl;
begin
    Form1.Memo1.Lines.Add(message);
end;

{ TForm1 }

procedure TForm1.pgConnAfterConnect(Sender: TObject);
var
    pg: IZPostgreSQLConnection;
    args: Pointer;
begin
    pg := pgConn.DbcConnection as IZPostgreSQLConnection;
    pg.GetPlainDriver.SetNoticeProcessor(pg.GetConnectionHandle, @PGNotifyProcessor, args);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    pgConn.ExecuteDirect('select foo(''bar'')');
end;

end. 

.

, . , LCL , . , , .

: FPC 2.6.4, Lazarus 1.5, Postgres 9.3, Linux Mint

+2

Source: https://habr.com/ru/post/1614479/