New COPY commands in libpq - Mailing list pgsql-hackers

From reina_ga@hotmail.com (Tony Reina)
Subject New COPY commands in libpq
Date
Msg-id 272e4be7.0404300512.49592ecb@posting.google.com
Whole thread Raw
Responses Re: New COPY commands in libpq
Re: New COPY commands in libpq
List pgsql-hackers
I read in the manual that the libpq functions PQputline(conn, cmd) and
PQendcopy(conn) have been deprecated and that PQputCopyData(conn, cmd,
sizeof(cmd)) and PQputCopyEnd(conn, msg) are the replacements.

I'm trying to convert a program that works just fine with the old
functions. I assume I'm missing a step here:

old C++ code:
       CString cmd;              res = PQexec(conn,  "COPY segmentvalues FROM STDIN;");if (PQresultStatus (res) !=
PGRES_COPY_IN){   PQclear (res);    return ns_DATABASEERROR;}else    PQclear(res);
 
       cmd.Format("1\t\2\t{3,4,5}\n");PQputline(conn, cmd);cmd.Format("\\.\n");PQputline(conn, cmd);
       PQendcopy(conn);


New C++ code:
       CString cmd, msg;              res = PQexec(conn,  "COPY segmentvalues FROM STDIN;");if (PQresultStatus (res) !=
PGRES_COPY_IN){   PQclear (res);    return ns_DATABASEERROR;}else    PQclear(res);
 
       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.

The serverlog gives me the error: "ERROR: Copy from STDIN failed:
CONTEXT: COPY segmentvalues, line 1: "1        " ERROR: current
transaction is aborted, commands ignored until the end of transaction
block."

Can anyone point me in the right direction? There aren't any examples
of how to use the new code in the manual. I thought I was following
the written instructions correctly (but apparently am not).

Thanks.
-Tony

p.s. Running PostgreSQL 7.4.2 server on Fedora Linux. Client is a
Windows XP MS Visual C++ .NET using libpq.


pgsql-hackers by date:

Previous
From: "Dave Page"
Date:
Subject: Re: Small OS ports & Handheld devices
Next
From: "Marc G. Fournier"
Date:
Subject: Re: Call for 7.5 feature completion