Page 1 of 1

Warning during console application

Posted: 29.09.2008, 09:32
by andrea.lai
I have this problem. I have do a simple console application that use TZReadOnlyQuery to insert or update fields in some tables.
During the computing are displayed on video several lines containing the words "policy". You can disable this display ?

Thank You.

Posted: 29.09.2008, 11:55
by mdaems
You mean : during compile or when executing your program?
During compile : I think suppression of warnings is some compiler setting.
During runtime : I'll need some more information to know what might be happening. I can't find the string policy in our code, so I doubt it's really zeoslib bound. If you can provide a demonstration case I might look into it.

Mark

Posted: 03.10.2008, 10:20
by andrea.lai
the message appear in runtime.
For example i create this query in my console application :

DB := TZConnection.Create(nil);
DB.HostName := 'localhost';
DB.User := 'postgres';
DB.Password := 'mypwd';
DB.Protocol := 'postgresql';
DB.Database := 'testdb';

ZQRY := TZQuery.Create(nil);
ZQRY.Connection := DB;

ZQRY.SQL.Clear;
ZQRY.SQL.Add('CREATE TABLE TEST (CMP CHAR(10))');
ZQRY.ExecSQL;

Compile the program.
Then open the shell and run "test.exe" and in the console appear the message "NOTICE : CREATE TABLE ...." .

I not want this message ... It possible not have this ?

Thank you

Posted: 06.10.2008, 12:24
by btrewern
It looks like it's libpq.dll working as designed. See here:
http://www.postgresql.org/docs/8.3/stat ... ssing.html.

Note where is says "The default notice handling function prints the message on stderr, ...." It also looks like the only way to stop this is to set the PQnoticeProcessor. Not worked out how to do that yet but will have another look at it when I have time.

Regards,

Ben

Posted: 08.10.2008, 10:22
by mdaems
@Ben,
@andrea.slai,

I just managed to get Postgres installed and running (proud of myself ;) ).

So my first step was to run the test suite against this new database. And indeed, I ran into this problem immediately. The test log was full of warnings... A mess.

Ben, you're right. This is indeed the default notice handling function.

I made a quick patch (against Testing branch, but you can just copy/paste it in any version)

Code: Select all

Index: ZDbcPostgreSql.pas
===================================================================
--- ZDbcPostgreSql.pas	(revision 482)
+++ ZDbcPostgreSql.pas	(working copy)
@@ -153,6 +154,7 @@
     FCharactersetCode: TZPgCharactersetType;
     FServerMajorVersion: Integer;
     FServerMinorVersion: Integer;
+    FNoticeProcessor: TZPostgreSQLNoticeProcessor;
   protected
     function BuildConnectStr: string;
     procedure StartTransactionSupport;
@@ -214,6 +216,10 @@
   ZDbcPostgreSqlUtils, ZDbcPostgreSqlMetadata, ZPostgreSqlToken,
   ZPostgreSqlAnalyser;
 
+procedure DefaultNoticeProcessor(arg: Pointer; message: PChar); cdecl;
+begin
+DriverManager.LogMessage(lcOther,'Postgres NOTICE',message);
+end;
 { TZPostgreSQLDriver }
 
 {**
@@ -377,6 +383,7 @@
   FClientCodePage := Trim(Info.Values['codepage']);
   FCharactersetCode := pg_CS_code(FClientCodePage);
 //  DriverManager.LogError(lcOther,'','Create',Integer(FCharactersetCode),'');
+  FNoticeProcessor := DefaultNoticeProcessor;
 end;
 
 {**
@@ -496,6 +503,10 @@
   else
     DriverManager.LogMessage(lcConnect, FPlainDriver.GetProtocol, LogMessage);
 
+  { Set the notice processor (default = nil)}
+
+  FPlainDriver.SetNoticeProcessor(FHandle,FNoticeProcessor,nil);
+
   { Sets a client codepage. }
   if FClientCodePage <> '' then
   begin
Now I need a smart person to tell me how we can allow a programmer to use this postgres-only feature by setting his own event handler, but without adding a database specific event or property to the connection component. Maybe using the connection.dbcconnection interface?

Mark

Posted: 13.10.2008, 18:42
by alai
Hi Mark,
sorry but i have a very bad english.
I don't have understand one thing ... how is possible apply your patch ?

Thank you

Andrea

Posted: 14.10.2008, 09:43
by mdaems
Hi Andrea,

You just have to add the lines with '+' in front of them in the right places in the files mentioned in the patch and rebuild/reinstall the zeoslib components. That's just 10 lines of code. Shouldn't be that difficult.

Can you please try and test this? I plan to put it in next 6.6.4 release, but I want a positive confirmation from somebody else first.

If you can not get it patched yourself, send me your version of ZDbcPostgreSql.pas in a private message and I'll return you the modified version.

Mark

Posted: 27.11.2008, 20:39
by andrea.lai
Hi Mark,

Sorry for the delay in my response.

Today I have seen that has been released version 6.6.4 and I soon only to prove the amendement made.

I can confirm that the application works correctly and no longer appears the unpleasant message.

Thank you very much.

Andrea

Posted: 29.01.2009, 22:24
by snorkel
Hi,
is it possible to get the default notices in my application now(with the latest version)?
The default notice processor I believe receives notices for things like VACUUM and Raise Notice from a stored proc.

Thanks,

Snorkel

Posted: 29.01.2009, 23:28
by mdaems
Actually, you can. It's not ideal, but by adding a TZSQLMonitor to your application and filtering the log category lcOther and 'Protocol' 'Postgres NOTICE' (what an ugly hack) you get the notices in your app.

Is there some smart PG + Delphi/Lazarus programmer who knows how we can add a possibility to connect a custom notice processor to a postgres connection? There may be two path's we can follow :
- Add a method to the ZConnection.dbcconnection interface for postgres only. Not sure if it's possible to handle this interface as a IZPostgreSQLConnection through the TZConnection component.
- Fetch the value of a Connection.properties line. Convert that value to a pointer address of a handler procedure. This one should work for sure, but it involves the ugly passing of a pointer in a string field.

Mark

Posted: 30.01.2009, 00:24
by snorkel
I think a event would just have to be added to the postgresql connection and then instead of sending to the log you would call that event.

Doesn't look like it would be to big a deal. Just having the ability to receive these notifications would be a big plus for anyone that wanted to make a admin tool for postgresql. Being able to receive these messages should be a higher priority than being able to use NOTIFY/LISTEN.

Can the latest version be installed on Delphi 2009? I could take a crack at it, but I am totally moved over to
Delphi 2009 right now.

Posted: 30.01.2009, 08:19
by mdaems
Give the trunk or testing snapshots a try. BLOB handling isn't very good yet, but normal operations seem to be alright.

Adding an event to the dbc postgres connection would be no problem. I'm not sure adding an event to the TZComponent is a good idea when it's only supported by one db server.

Mark

Posted: 04.02.2009, 15:33
by seawolf
Differently from Firebird, Postgres does not return an event in response a notification, so it is necessary ask every x seconds if there are new notifications. So you can change

function TZPostgreSQLConnection.PingServer: Integer;
const
PING_ERROR_ZEOSCONNCLOSED = -1;
var
Closing: boolean;
Notify : PZPostgreSQLNotify;
begin
Closing := FHandle = nil;
if Closed or Closing then
Result := PING_ERROR_ZEOSCONNCLOSED
else
begin
FPlainDriver.Clear(FPlainDriver.ConsumeInput(FHandle));
if FPlainDriver.GetStatus(FHandle) = CONNECTION_OK then
begin
Result := 0;
Notify := FPlainDriver.Notifies(FHandle);
------ Do a notification parser -------
FPlainDriver.FreeNotify(Notify);

end
else
try
FPlainDriver.Reset(FHandle);
FPlainDriver.Clear(FPlainDriver.ConsumeInput(FHandle));
if FPlainDriver.GetStatus(FHandle) = CONNECTION_OK then
begin
Result := 0;
Notify := FPlainDriver.Notifies(FHandle);
------ Do a notification parser -------
FPlainDriver.FreeNotify(Notify);

end
except
Result := 1;
end;
end;
end;

as stated on the Postgres 8.3 PDF manual, page 506

Posted: 04.02.2009, 16:34
by mdaems
Hi Seawolf,

I'm afraid that's not the intended use of the pingserver call.

And, BTW, now you're talking about something different as mentioned in the original post. The original past was about Postgres Notices, you're talking about the LISTEN and NOTIFY Asynchronous Notification feature, which I believe should be implemented similar to the TZIBEventmonitor (which should really become simply TZEventMonitor).

Mark