[sr-dev] git:master: modules/db_mysql: Don't call mysql_next_results if there aren' t any results left

Alex Hermann alex at speakup.nl
Thu Aug 18 09:50:52 CEST 2011


Module: sip-router
Branch: master
Commit: dfc2834223b7c6b2e799da5a0876b8096cfdae5e
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dfc2834223b7c6b2e799da5a0876b8096cfdae5e

Author: Alex Hermann <alex at speakup.nl>
Committer: Alex Hermann <alex at speakup.nl>
Date:   Tue Aug  9 11:54:05 2011 +0200

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.

---

 modules/db_mysql/km_dbase.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/db_mysql/km_dbase.c b/modules/db_mysql/km_dbase.c
index 6f344f2..68481f7 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/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);
 	}




More information about the sr-dev mailing list