gpt4 book ai didi

PostgreSQL:通过 ZeosLib/Lazarus 从客户端连接捕获 RAISE NOTICE

转载 作者:行者123 更新时间:2023-11-29 11:36:01 27 4
gpt4 key购买 nike

我开发了一个使用 PostgreSQL 8.4 RDBMS 的客户端应用程序。

我的应用程序是用 Lazarus 和 ZeosLib 7.2 编写的,用于数据库访问。

我使用了很多存储过程,在特定点上我使用 raise notice 来获取过程状态的信息,Es:

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

当我在 PgAdmin3 中执行程序时,它会在“消息”选项卡中显示通知。有一种方法可以在我的客户端应用程序中捕获引发的通知吗?

最佳答案

好吧,虽然我对这个话题也很感兴趣,但这里有一些在快速调查后创建的工作示例:

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

关于PostgreSQL:通过 ZeosLib/Lazarus 从客户端连接捕获 RAISE NOTICE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33526809/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com