libpq question...

Поиск
Список
Период
Сортировка
От wy2lam@yahoo.com (Michael Lam)
Тема libpq question...
Дата
Msg-id 23f69a9b.0209040740.37f2e07a@posting.google.com
обсуждение исходный текст
Список 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!!

В списке pgsql-general по дате отправления:

Предыдущее
От: "Linn Kubler"
Дата:
Сообщение: Re: parameterized views?
Следующее
От: "Linn Kubler"
Дата:
Сообщение: Re: show ?