Loggin SQL warnings in JDBC driver

From: Edson Richter <edsonrichter(at)hotmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Loggin SQL warnings in JDBC driver
Date: 2013-01-17 22:25:12
Message-ID: BLU0-SMTP1153C57A744EA6503D03CE3CF130@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I've applyied both paths below to be able to print SQL Warnings when
loglevel=1 when working with JDBC 9.2.2 driver.
I did create this as separate driver compilation, because I don't want
the slowdown introduced in the addWarnings (that would affect
significantly my production servers).
Using this patch it is possible to get logged the RAISE NOTICE warnings
from triggers, among other warnings.

First patch:
---------------------------------------------------------------------------------------------------------------------------

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>AbstractJdbc2Statement.java (<b>Nov 14, 2012 9:08:49
AM</b>)</html>
+++ <html><b>Current File</b></html>
@@ -745,6 +745,10 @@
*/
public void addWarning(SQLWarning warn)
{
+ if(connection.getLogger()!=null) {
+ connection.getLogger().log("Warning", warn);
+ }
+
if (warnings == null) {
warnings = warn;
lastWarning = warn;

---------------------------------------------------------------------------------------------------------------------------

Second patch:
---------------------------------------------------------------------------------------------------------------------------

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>AbstractJdbc2Connection.java (<b>Nov 14, 2012 9:08:49
AM</b>)</html>
+++ <html><b>Current File</b></html>
@@ -327,6 +327,9 @@
*/
public void addWarning(SQLWarning warn)
{
+ if(getLogger()!=null) {
+ getLogger().log("Warning", warn);
+ }
// Add the warning to the chain
if (firstWarning != null)
firstWarning.setNextWarning(warn);

---------------------------------------------------------------------------------------------------------------------------

Regards,

Edson

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2013-01-18 00:06:52 Re: SELECT DISTINCT
Previous Message Kirk Wythers 2013-01-17 22:05:25 Re: speeding up a join query that utilizes a view