Warning during console application
Moderators: gto, cipto_kh, EgonHugeist, olehs
-
- Fresh Boarder
- Posts: 21
- Joined: 26.11.2005, 12:23
Warning during console application
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.
During the computing are displayed on video several lines containing the words "policy". You can disable this display ?
Thank You.
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
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
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
-
- Fresh Boarder
- Posts: 21
- Joined: 26.11.2005, 12:23
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
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
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
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
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
@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)
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
@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
Mark
Last edited by mdaems on 14.10.2008, 09:44, edited 4 times in total.
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
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
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
-
- Fresh Boarder
- Posts: 21
- Joined: 26.11.2005, 12:23
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
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
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
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.
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.
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
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
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
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
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