Re: code example for PQgetCopyData - Mailing list pgsql-general

From Dave Huber
Subject Re: code example for PQgetCopyData
Date
Msg-id 7CDADB576E07AC4FA71E1B12566C9126546D556F12@lti-mb-1.LTI.com
Whole thread Raw
In response to Re: code example for PQgetCopyData  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: code example for PQgetCopyData
List 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
workfor 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
inerror, 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
similarimport, absent an express statement to the contrary contained in this e-mail, neither this e-mail nor any
attachmentsare 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
companycannot accept responsibility for any loss or damage arising from the use of this email or attachments. 


pgsql-general by date:

Previous
From: Israel Brewster
Date:
Subject: Re: Build universal binary on Mac OS X 10.6?
Next
From: Alvaro Herrera
Date:
Subject: Re: [Bacula-users] Catastrophic changes to PostgreSQL 8.4