Re: code example for PQgetCopyData

From: Dave Huber <DHuber(at)letourneautechnologies(dot)com>
To: 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: code example for PQgetCopyData
Date: 2009-12-03 20:54:07
Message-ID: 7CDADB576E07AC4FA71E1B12566C9126546D556F12@lti-mb-1.LTI.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom,

Thanks for the help. Setting buffer to a char * fixed the crashing problem.

Now, I have a different issue. The result from PQgetCopyData is always 1 for every row of data returned. Does this not work for return data "WITH BINARY"? If I issue the same copy command to a file instead of STDOUT and examine the file contents, there is most definitely data for each row. The command going to the PQexec function is:

COPY (SELECT * FROM event_log_table) TO STDOUT WITH BINARY
Or
COPY (SELECT * FROM event_log_table) TO E'C:\\testfile' WITH BINARY

To reiterate, nLen in the following code always == 1:

pResult = PQexec(pConn, szCopyStr);
delete [] szCopyStr;

// make sure we are in the copy out state before reading if (PGRES_COPY_OUT == PQresultStatus(pResult))
{
// get the data
int i = 0;
while (nLen = PQgetCopyData(pConn, &buffer, false) > 0)
{
...

Thanks again.

Dave

Tom wrote:

One thing you're missing is that you should check that the result from
the PQexec actually shows successful entry into COPY_OUT state.
But I think the crash is because you're confused about the indirection
level. buffer should be char *, not char **, and the argument ought to
be &buffer so that the function can assign to buffer.

regards, tom lane

This electronic mail message is intended exclusively for the individual(s) or entity to which it is addressed. This message, together with any attachment, is confidential and may contain privileged information. Any unauthorized review, use, printing, retaining, copying, disclosure or distribution is strictly prohibited. If you have received this message in error, please immediately advise the sender by reply email message to the sender and delete all copies of this message.
THIS E-MAIL IS NOT AN OFFER OR ACCEPTANCE: Notwithstanding the Uniform Electronic Transactions Act or any other law of similar import, absent an express statement to the contrary contained in this e-mail, neither this e-mail nor any attachments are an offer or acceptance to enter into a contract, and are not intended to bind the sender, LeTourneau Technologies, Inc., or any of its subsidiaries, affiliates, or any other person or entity.
WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-12-03 21:00:03 Re: [Bacula-users] Catastrophic changes to PostgreSQL 8.4
Previous Message Israel Brewster 2009-12-03 20:39:32 Re: Build universal binary on Mac OS X 10.6?