Search Postgresql Archives

Re: code example for PQgetCopyData

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux