From c46e391fe627d386be82d3644427ab10deb690be Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 19 Jun 2003 04:59:11 +0300 Subject: [PATCH] If query fails with fatal failure, reconnect. --HG-- branch : HEAD --- src/auth/db-pgsql.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/auth/db-pgsql.c b/src/auth/db-pgsql.c index 5efe6fee03..821b289967 100644 --- a/src/auth/db-pgsql.c +++ b/src/auth/db-pgsql.c @@ -38,7 +38,7 @@ void db_pgsql_query(struct pgsql_connection *conn, const char *query, struct pgsql_request *request) { PGresult *res; - int failed; + int i, failed; if (!conn->connected) { if (!pgsql_conn_open(conn)) { @@ -50,14 +50,23 @@ void db_pgsql_query(struct pgsql_connection *conn, const char *query, if (verbose_debug) i_info("PGSQL: Performing query: %s", query); - res = PQexec(conn->pg, query); + for (i = 0; i < 2; i++) { + res = PQexec(conn->pg, query); - if (PQresultStatus(res) != PGRES_TUPLES_OK) { + if (PQresultStatus(res) != PGRES_FATAL_ERROR) + break; + + /* probably lost connection */ + i_info("PGSQL: Fatal error, reconnecting"); + PQreset(conn->pg); + } + + if (PQresultStatus(res) == PGRES_TUPLES_OK) + failed = FALSE; + else { i_error("PGSQL: Query \"%s\" failed: %s", query, PQresultErrorMessage(res)); failed = TRUE; - } else { - failed = FALSE; } request->callback(conn, request, failed ? NULL : res); -- 2.47.3