Browse code

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 authored on 09/08/2011 09:54:05
Showing 1 changed files
... ...
@@ -197,7 +197,7 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
197 197
 		 * to free the mem from the mysql lib side */
198 198
 		mysql_free_result(CON_RESULT(_h));
199 199
 #if (MYSQL_VERSION_ID >= 40100)
200
-		while( mysql_next_result( CON_CONNECTION(_h) ) > 0 ) {
200
+		while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) > 0 ) {
201 201
 			MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
202 202
 			mysql_free_result(res);
203 203
 		}
... ...
@@ -208,7 +208,7 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
208 208
 
209 209
 done:
210 210
 #if (MYSQL_VERSION_ID >= 40100)
211
-	while( mysql_next_result( CON_CONNECTION(_h) ) > 0 ) {
211
+	while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) > 0 ) {
212 212
 		MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
213 213
 		mysql_free_result(res);
214 214
 	}