static MYSQL_RES *plmysql_query(PLMYSQL *PLDB, const char *query, char *dbname, char *username, char *password) { HOST *host; MYSQL_RES *res = 0; while ((host = dict_mysql_get_active(PLDB, dbname, username, password)) != NULL) { if (!(mysql_query(host->db, query))) { if ((res = mysql_store_result(host->db)) == 0) { msg_warn("mysql query failed: %s", mysql_error(host->db)); plmysql_down_host(host); } else { if (msg_verbose) msg_info("dict_mysql: successful query from host %s", host->hostname); event_request_timer(dict_mysql_event, (char *) host, IDLE_CONN_INTV); break; } } else { msg_warn("mysql query failed: %s", mysql_error(host->db)); plmysql_down_host(host); } } return res; }
static MYSQL_RES *plmysql_query(DICT_MYSQL *dict_mysql, const char *name, VSTRING *query) { HOST *host; MYSQL_RES *res = 0; while ((host = dict_mysql_get_active(dict_mysql)) != NULL) { #if defined(MYSQL_VERSION_ID) && MYSQL_VERSION_ID >= 40000 /* * The active host is used to escape strings in the context of the * active connection's character encoding. */ dict_mysql->active_host = host; VSTRING_RESET(query); VSTRING_TERMINATE(query); db_common_expand(dict_mysql->ctx, dict_mysql->query, name, 0, query, dict_mysql_quote); dict_mysql->active_host = 0; #endif if (!(mysql_query(host->db, vstring_str(query)))) { if ((res = mysql_store_result(host->db)) == 0) { msg_warn("mysql query failed: %s", mysql_error(host->db)); plmysql_down_host(host); } else { if (msg_verbose) msg_info("dict_mysql: successful query from host %s", host->hostname); event_request_timer(dict_mysql_event, (char *) host, IDLE_CONN_INTV); break; } } else { msg_warn("mysql query failed: %s", mysql_error(host->db)); plmysql_down_host(host); } } return res; }