Re: PQerrorMessage: suppress trailing new line?

From: Felix Kater <fkater(at)googlemail(dot)com>
To: "Andrej Ricnik-Bay" <andrej(dot)groups(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PQerrorMessage: suppress trailing new line?
Date: 2007-04-24 09:13:45
Message-ID: 20070424111345.494f7d43.fkater@googlemail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 24 Apr 2007 11:14:43 +1200
"Andrej Ricnik-Bay" <andrej(dot)groups(at)gmail(dot)com> wrote:

> On 4/24/07, Felix Kater <fkater(at)googlemail(dot)com> wrote:
> > Hi,
> >
> > the messages returned by PQerrorMessage() contain a trailing new
> > line. So, they doesn't nicely integrate into strings formatted by
> > printf.
> >
> > Is there a way to suppress the trailing new line (except for
> > alloc/copy to a new string)?
> The alloc kind of suggests that you're using C ... is that
> correct? Either way - please be a bit more specific as to what you're
> trying to achieve by which means.

Sorry (was deep in thoughs while coding...). A bit more detailed:

I am using libpq, the C language pg library. There is a useful function
to return the last error message as human readable text: PQerrorMessage.

While the returned text message is static memory which is good (you
simply print it and don't have to free the memory) there is a trailing
new line character at each text message like this:
<message text><newline><0-byte-terminator>

I find this newline a lot uncommon--since it is easy to add manually if
you really want it, and, however, it is not so easy to get rid of it.

Getting rid of it means: Copying the whole string without the newline,
pass it to the user, who has to free the copied memory after printing
it...

I wanted to know if there is a switch or similar somewhere to get the
messages without newline character.

Thank You
Felix

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Staubo 2007-04-24 09:31:11 Re: [GENERAL] Regarding WAL
Previous Message Teodor Sigaev 2007-04-24 08:21:29 Re: tsearch2 dictionary that indexes substrings?