Mercurial > dovecot > core-2.2
changeset 1562:95e2fea24d06 HEAD
If query fails with fatal failure, reconnect.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 19 Jun 2003 04:59:11 +0300 |
parents | 24dad210417f |
children | 1ffb486b0ca6 |
files | src/auth/db-pgsql.c |
diffstat | 1 files changed, 14 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/auth/db-pgsql.c Thu Jun 19 04:49:48 2003 +0300 +++ b/src/auth/db-pgsql.c Thu Jun 19 04:59:11 2003 +0300 @@ -38,7 +38,7 @@ struct pgsql_request *request) { PGresult *res; - int failed; + int i, failed; if (!conn->connected) { if (!pgsql_conn_open(conn)) { @@ -50,14 +50,23 @@ 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_FATAL_ERROR) + break; - if (PQresultStatus(res) != PGRES_TUPLES_OK) { + /* 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);