浏览代码

modules/db_mysql: Don't call mysql_next_results if there aren't any results left

Calling mysql_next_results looses connection state for the previous result,
making it impossible to use mysql_last_insert_id and mysql_affected_rows
afterwards.
Alex Hermann 14 年之前
父节点
当前提交
dfc2834223
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2 2
      modules/db_mysql/km_dbase.c

+ 2 - 2
modules/db_mysql/km_dbase.c

@@ -197,7 +197,7 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
 		 * to free the mem from the mysql lib side */
 		mysql_free_result(CON_RESULT(_h));
 #if (MYSQL_VERSION_ID >= 40100)
-		while( mysql_next_result( CON_CONNECTION(_h) ) > 0 ) {
+		while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) > 0 ) {
 			MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
 			mysql_free_result(res);
 		}
@@ -208,7 +208,7 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
 
 done:
 #if (MYSQL_VERSION_ID >= 40100)
-	while( mysql_next_result( CON_CONNECTION(_h) ) > 0 ) {
+	while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) > 0 ) {
 		MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
 		mysql_free_result(res);
 	}