浏览代码

db_mysql: explicitely set the reconenct flag via mysql cloent api

- old mode setting connection fied directly still in place, but now
  should be safer if that changes
Daniel-Constantin Mierla 9 年之前
父节点
当前提交
e89c77f641
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      modules/db_mysql/km_my_con.c

+ 10 - 0
modules/db_mysql/km_my_con.c

@@ -43,6 +43,9 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
 	struct my_con* ptr;
 	char *host, *grp, *egrp;
 	unsigned int connection_flag = 0;
+#if MYSQL_VERSION_ID > 50012
+	my_bool rec;
+#endif
 
 	if (!id) {
 		LM_ERR("invalid parameter value\n");
@@ -99,6 +102,13 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
 	mysql_options(ptr->con, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&db_mysql_timeout_interval);
 	mysql_options(ptr->con, MYSQL_OPT_READ_TIMEOUT, (const char *)&db_mysql_timeout_interval);
 	mysql_options(ptr->con, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&db_mysql_timeout_interval);
+#if MYSQL_VERSION_ID > 50012
+	/* set reconnect flag if enabled */
+	if (db_mysql_auto_reconnect) {
+		rec = 1;
+		mysql_options(ptr->con, MYSQL_OPT_RECONNECT, &rec);
+	}
+#endif
 
 	if (db_mysql_update_affected_found) { 
 	    connection_flag |= CLIENT_FOUND_ROWS;