From 0bdca6cf66d708313da3434474bc92cd109ef1f2 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Sat, 17 Sep 2005 22:27:24 +0000 Subject: [PATCH] This patch fill fix the notice handler so that the odbc driver doesn't output notices from the backend to stderr. [Scot Loach] --- connection.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/connection.c b/connection.c index 6b8703d..38a4e28 100644 --- a/connection.c +++ b/connection.c @@ -2349,6 +2349,29 @@ CC_send_cancel_request(const ConnectionClass *conn) } #else + +static void +CC_handle_notice(void *arg, const char *msg) +{ + QResultClass *qres; + + qres = (QResultClass*)(arg); + + if (qres == NULL) + { + // No query in progress, so just drop the notice + return; + } + + if (QR_command_successful(qres)) + { + QR_set_status(qres, PGRES_NONFATAL_ERROR); + QR_set_notice(qres, msg); /* will dup this string */ + mylog("~~~ NOTICE: '%s'\n", msg); + qlog("NOTICE from backend during send_query: '%s'\n", msg); + } +} + /* * Connection class implementation using libpq. * Memory Allocation for PGconn is handled by libpq. @@ -3161,6 +3184,9 @@ LIBPQ_connect(ConnectionClass *self) } /* free the conninfo structure */ free(conninfo); + + /* setup the notice handler */ + PQsetNoticeProcessor(self->pgconn, CC_handle_notice, NULL); mylog("connection to the database succeeded.\n"); return 1; } @@ -3173,8 +3199,6 @@ LIBPQ_execute_query(ConnectionClass *self,char *query) PGresult *pgres; char errbuffer[ERROR_MSG_LENGTH + 1]; int pos=0; - - pgres = PQexec(self->pgconn,query); qres=QR_Constructor(); if(!qres) @@ -3183,6 +3207,11 @@ LIBPQ_execute_query(ConnectionClass *self,char *query) QR_Destructor(qres); return NULL; } + + PQsetNoticeProcessor(self->pgconn, CC_handle_notice, qres); + pgres = PQexec(self->pgconn,query); + PQsetNoticeProcessor(self->pgconn, CC_handle_notice, NULL); + qres->status = PQresultStatus(pgres); /* Check the connection status */ @@ -3383,7 +3412,6 @@ CC_is_server_alive(ConnectionClass *conn) } - #endif /* USE_LIBPQ */ -- 2.39.5