New COPY commands in libpq

From: reina_ga(at)hotmail(dot)com (Tony Reina)
To: pgsql-hackers(at)postgresql(dot)org
Subject: New COPY commands in libpq
Date: 2004-04-30 13:12:35
Message-ID: 272e4be7.0404300512.49592ecb@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2004-04-30 13:27:22 Re: FW: Timezone library
Previous Message Dave Page 2004-04-30 12:21:57 Re: Small OS ports & Handheld devices