get error message of COPY command after using PQputCopyEnd

From: bronstein87 <bumatov(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: get error message of COPY command after using PQputCopyEnd
Date: 2017-01-24 21:34:39
Message-ID: 1485293679459-5940767.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I'm trying to get an error after sending wrong buffer by PQputCopyData.
I do everything according to the documentation:
PGconn* conn=PQconnectdb(qPrintable(conninfo));

if (PQstatus(conn) != CONNECTION_OK)
{
...
}
PQsetClientEncoding(conn,"WIN1251");
PGresult* res=PQexec(conn,"COPY ksv FROM STDIN);
ExecStatusType status= PQresultStatus(res);
PQclear(res);
if(status!=PGRES_COPY_IN)
{
...
}
int
copyStatus=PQputCopyData(conn,bufferToWrite,strlen(bufferToWrite));//
bufferToWrite is wrong
cout()<<copyStatus; // returns 1
const char* error=NULL;
int copyStatusEnd=PQputCopyEnd(conn,error);

cout()<<copyStatusEnd;// returns 1
if(error!=NULL) // error is NULL
{
...
}
PGresult* result=PQgetResult(conn); // so, here im calling pqgetresult
to get error
ExecStatusType status2= PQresultStatus(result);
if(status2==PGRES_COMMAND_OK) // and status2 is really PGRES_COMMAND_OK
{
...
}
char * error1= PQresultErrorMessage(result);
cout()<<error1; // here null
char* error2 =PQerrorMessage(conn);
cout()<<error2; // here null

so, pqgetresult do not return any error. what im doing wrong?

--
View this message in context: http://postgresql.nabble.com/get-error-message-of-COPY-command-after-using-PQputCopyEnd-tp5940767.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.

Browse pgsql-novice by date

  From Date Subject
Next Message bronstein87 2017-01-24 21:40:47 get error message of COPY command after using PQputCopyEnd
Previous Message valeriof 2017-01-23 15:49:09 Deployment of an output plugin in Unix-like environment