From: Timo Sirainen Date: Thu, 15 Sep 2011 10:46:45 +0000 (+0300) Subject: lib-sql: When escaping a string, use the first ready connection (if any). X-Git-Tag: 2.0.15~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d20d46069fa0d4b98790779552dd778d1749d1c;p=thirdparty%2Fdovecot%2Fcore.git lib-sql: When escaping a string, use the first ready connection (if any). This avoids unnecessarily trying to reconnect to a failing connection. --- diff --git a/src/lib-sql/driver-sqlpool.c b/src/lib-sql/driver-sqlpool.c index 5cbbb33350..c92a281b23 100644 --- a/src/lib-sql/driver-sqlpool.c +++ b/src/lib-sql/driver-sqlpool.c @@ -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)