[dovecot-cvs] dovecot/src/auth db-pgsql.c,1.7,1.8

cras at dovecot.org cras at dovecot.org
Fri Jul 30 09:53:38 EEST 2004


Update of /home/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv30387

Modified Files:
	db-pgsql.c 
Log Message:
Reconnection fix, thanks to Zsolt Varga.



Index: db-pgsql.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/db-pgsql.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- db-pgsql.c	18 Jul 2004 12:43:05 -0000	1.7
+++ db-pgsql.c	30 Jul 2004 06:53:35 -0000	1.8
@@ -50,7 +50,7 @@
 		    struct pgsql_request *request)
 {
 	PGresult *res;
-	int i, failed;
+	int failed;
 
 	if (!conn->connected) {
 		if (!pgsql_conn_open(conn)) {
@@ -61,16 +61,22 @@
 
 	if (verbose_debug)
 		i_info("PGSQL: Performing query: %s", query);
+	
+	res = PQexec(conn->pg, query);
+	switch (PQresultStatus(res)) {
+	case PGRES_EMPTY_QUERY:
+	case PGRES_COMMAND_OK:
+	case PGRES_TUPLES_OK:
+		break;
 
-	for (i = 0; i < 2; i++) {
-		res = PQexec(conn->pg, query);
-
-		if (PQresultStatus(res) != PGRES_FATAL_ERROR)
-			break;
-
+	default:
 		/* probably lost connection */
-		i_info("PGSQL: Fatal error, reconnecting");
+		i_info("PGSQL: Query failed, reconnecting");
+		PQclear(res);
 		PQreset(conn->pg);
+
+		res = PQexec(conn->pg, query);
+		break;
 	}
 
 	if (PQresultStatus(res) == PGRES_TUPLES_OK)



More information about the dovecot-cvs mailing list