Re: Some encoding trouble via libpq - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Some encoding trouble via libpq
Date
Msg-id 20070402144501.GB9547@svana.org
Whole thread Raw
In response to Re: Some encoding trouble via libpq  ("William Gray" <billy.zophar@gmail.com>)
List 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@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: PlPg/SQL
Next
From: "Sorin N. Ciolofan"
Date:
Subject: Re: [ADMIN] Increasing the shared memory