Re: Some encoding trouble via libpq

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: William Gray <billy(dot)zophar(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: Some encoding trouble via libpq
Date: 2007-04-02 14:45:01
Message-ID: 20070402144501.GB9547@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Mar 30, 2007 at 11:43:08AM -0400, William Gray wrote:
> The solution was to not clear result until later, or to copy the data in
> allocated memory, then clear the result, which we did thusly:
>
> tmp_str = PQgetvalue(result, 0, 0);
> tmp_str_len = strlen(tmp_str);
> event_id = xmalloc(tmp_str_len + 1);
> strncpy(event_id, tmp_str, tmp_str_len);

Glad you got your problem solved. What you've done here is so common
there's even a standard function for it: strdup(). So what you did is
equivalent to:

event_id = strdup( PQgetvalue(result, 0, 0) );

You obviously need to free it later, but this gives you the right
idea...

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sorin N. Ciolofan 2007-04-02 14:52:15 Re: Increasing the shared memory
Previous Message A. Kretschmer 2007-04-02 14:41:29 Re: PlPg/SQL