libpq question...

From: wy2lam(at)yahoo(dot)com (Michael Lam)
To: pgsql-general(at)postgresql(dot)org
Subject: libpq question...
Date: 2002-09-04 15:40:06
Message-ID: 23f69a9b.0209040740.37f2e07a@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I have a question about insertions with duplicate primary keys...

I was trying to detect duplicated rows while inserting rows with libpq
making calls to stored procedures.

Suppose I have the following snipplet:

PGresult *res;
res = PQexec(conn, "SELECT AddRow(1);"
if (!res) {
// connection bad
return CONNECTION_BAD;
}
if (PGRES_TUPLES_OK != PQresultStatus(res)) {
string errMsg = PQerrorMessage(conn);
if (string::npos != errMsg.find("dupl")) {
return DUPLICATED_ROWS;
} else {
return CONNECTION_BAD;
}
}

Question is: is there a better way of detecting duplicated rows than
checking for "duplicate" in the error message? I fear the error
string may get changed and break the code...

I have tried looking at the PQresultStatus(res), but unfortunately it
is PGRES_FATAL_ERROR - which is the same as when I shut down the
backend or a disconnection - and I want to do different things for
duplications and disconnections.

Can anyone shed some light on this? Thanks!!

Browse pgsql-general by date

  From Date Subject
Next Message Patrick Bakker 2002-09-04 16:09:30 split(...) style functions
Previous Message scott.marlowe 2002-09-04 15:09:06 Re: Remote connection via psql