pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeroen T. Vermeulen <jtv@xs4all.nl>
To: pgsql-interfaces@postgresql.org
Subject: libpq notice processors
Date: Thu, 29 Jan 2004 19:37:31 +0100
Message-ID: <20040129183731.GI43961@xs4all.nl> (raw)

Is it actually required that a message passed to the notice processor
end in a newline?  For libpqxx it would be highly convenient if this were
optional from the caller's point of view.

The library itself calls the same handler sometimes.  Adding the newline to
an error or warning message is not only inefficient, it also introduces
certain risks of failure.  That's just what you don't want to have when
handling an error in the first place--error handling clauses are usually the
worst-tested corners of the program.

Simply making the newline optional may be inconvenient for the notice
processor, e.g. if it's something like fprintf(stderr,"%s",msg); (and we
want to give the user maximum convenience to reduce bugs) so here's
one relatively easy way to solve the problem:

 * The message passed to the handler "ought to" end in newline, but it
   doesn't always.

 * If the trailing newline is missing, it will be written by the next
   call to the notice processor.

 * If the original message missed its trailing newline, the next message
   will contain only the missing newline.

Now, whenever it is inconvenient to tack a trailing newline to a message,
libpqxx could call the notice processor twice--once with the message text
and once with the newline.  A printf-style notice processor would continue
simply to print out what it's given, as before.  A typical GUI notice
processor, which might want to pop up a dialog for each message, can display
the message regardless of trailing newline, provided it ignores messages
consisting only of "\n".
                                                                                
                                                                                
Jeroen 



view thread (3+ messages)  latest in thread

Message-ID: <20040129183731.GI43961@xs4all.nl>
Permalink:  ../20040129183731.GI43961@xs4all.nl/
Also on:    postgresql.org/message-id/20040129183731.GI43961@xs4all.nl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: jtv@xs4all.nl
  Subject: Re: libpq notice processors
  In-Reply-To: <20040129183731.GI43961@xs4all.nl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox