Patch for NOTICE messages to PQfn() from backend - Mailing list pgsql-hackers

From Oliver Elphick
Subject Patch for NOTICE messages to PQfn() from backend
Date
Msg-id 199804281110.MAA23122@linda.lfix.co.uk
Whole thread Raw
List pgsql-hackers
If PQfn() receives NOTICEs from the backend, it fails because there is no
provision to deal with them.

This patch (supplied by Anders Hammarquist <iko@netg.se> to me as Debian
maintainer of postgresql) cures the problem:

diff -cr postgresql-6.3.2.orig/src/interfaces/libpq/fe-exec.c
postgresql-6.3.2/src/interfaces/libpq/fe-exec.c
*** postgresql-6.3.2.orig/src/interfaces/libpq/fe-exec.c    Mon Mar 16 08:0
0:26
1998
- --- postgresql-6.3.2/src/interfaces/libpq/fe-exec.c    Tue Apr 28 06:47:22 199
8
***************
*** 1545,1556 ****
      }
      pqFlush(pfout, pfdebug);

!     id = pqGetc(pfin, pfdebug);
!     if (id != 'V')
      {
          if (id == 'E')
          {
              pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, pfde
bug);
          }
          else
              sprintf(conn->errorMessage,
- --- 1545,1570 ----
      }
      pqFlush(pfout, pfdebug);

!     while ((id = pqGetc(pfin, pfdebug)) != 'V')
      {
          if (id == 'E')
          {
              pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, pfde
bug);
+         }
+         else if (id == 'N')
+             {
+                    /* print notice and go back to processing return
+                values */
+                    if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH,
+                 pfin, pfdebug) == 1)
+             {
+                 sprintf(conn->errorMessage,
+                 "Notice return detected from backend, but "
+                 "message cannot be read");
+             }
+             else
+                 fprintf(stderr, "%s\n", conn->errorMessage);
+             continue;
          }
          else
              sprintf(conn->errorMessage,


--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver

PGP key from public servers; key ID 32B8FAA1

                 ========================================
    Come to me, all you who labour and are heavily laden, and I will
    give you rest. Take my yoke upon you, and learn from me; for I am
    meek and lowly in heart, and you shall find rest for your souls.
    For my yoke is easy and my burden is light.    (Matthew 11: 28-30)



pgsql-hackers by date:

Previous
From: "Oliver Elphick"
Date:
Subject: Patch for createuser to make it consistent with CREATE USER
Next
From: Robert Hiltibidal
Date:
Subject: Re: [QUESTIONS] Postgres still dying on insert