]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-sql: When escaping a string, use the first ready connection (if any).
authorTimo Sirainen <tss@iki.fi>
Thu, 15 Sep 2011 10:46:45 +0000 (13:46 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 15 Sep 2011 10:46:45 +0000 (13:46 +0300)
This avoids unnecessarily trying to reconnect to a failing connection.

src/lib-sql/driver-sqlpool.c

index 5cbbb3335064b6d51cb1795754f3e4d4b2ac9df9..c92a281b2379f3c3d4262c10378fb9df176e135e 100644 (file)
@@ -533,11 +533,18 @@ static const char *
 driver_sqlpool_escape_string(struct sql_db *_db, const char *string)
 {
        struct sqlpool_db *db = (struct sqlpool_db *)_db;
-       const struct sqlpool_connection *conn;
+       const struct sqlpool_connection *conns;
+       unsigned int i, count;
 
-       /* we always have at least one connection */
-       conn = array_idx(&db->all_connections, 0);
-       return sql_escape_string(conn->db, string);
+       /* use the first ready connection */
+       conns = array_get(&db->all_connections, &count);
+       for (i = 0; i < count; i++) {
+               if (SQL_DB_IS_READY(conns[i].db))
+                       return sql_escape_string(conns[i].db, string);
+       }
+       /* no ready connections. just use the first one (we're guaranteed
+          to always have one) */
+       return sql_escape_string(conns[0].db, string);
 }
 
 static void driver_sqlpool_timeout(struct sqlpool_db *db)