Re: New COPY commands in libpq - Mailing list pgsql-hackers

From Jeroen T. Vermeulen
Subject Re: New COPY commands in libpq
Date
Msg-id 20040430145855.GD6945@xs4all.nl
Whole thread Raw
In response to New COPY commands in libpq  (reina_ga@hotmail.com (Tony Reina))
List pgsql-hackers
On Fri, Apr 30, 2004 at 06:12:35AM -0700, Tony Reina wrote:

>         CString cmd, msg;
>         cmd.Format("1\t\2\t{3,4,5}\n");
> *    PQputCopyData(conn, cmd, sizeof(cmd));
>         cmd.Format("\\.\n");
> *       PQputCopyData(conn, cmd, sizeof(cmd));
> *       PQputCopyEnd(conn, msg);
> Old C++ code works, new stuff doesn't. Only line that have changed are
> *'d.
I'm not surprised.  CString is clearly a class, and cmd is an object of
that class.  Apparently that class has an implicit conversion operator to
char * (which is a striking example of a Bad Idea--kids, don't try this
at home!) but nonetheless, sizeof() should still give you the size of the
object, *not* the size of the string it represents!

You might try porting your code to libpqxx, which is C++-native and should
make large swathes of this sort of code unnecessary.


Jeroen



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Call for 7.5 feature completion
Next
From: Alvaro Herrera
Date:
Subject: Re: Current CVS tip segfaulting