[dovecot-cvs] dovecot/src/auth db-pgsql.c,1.3,1.4

cras at procontrol.fi cras at procontrol.fi
Thu Jun 19 05:59:13 EEST 2003


Update of /home/cvs/dovecot/src/auth
In directory danu:/tmp/cvs-serv12981

Modified Files:
	db-pgsql.c 
Log Message:
If query fails with fatal failure, reconnect.



Index: db-pgsql.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/db-pgsql.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- db-pgsql.c	27 Apr 2003 00:12:43 -0000	1.3
+++ db-pgsql.c	19 Jun 2003 01:59:11 -0000	1.4
@@ -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_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);



More information about the dovecot-cvs mailing list