[svn-commits] russell: trunk r347 - /trunk/app_addon_sql_mysql.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Mar 6 15:36:23 MST 2007


Author: russell
Date: Tue Mar  6 16:36:23 2007
New Revision: 347

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=347
Log:
Update the MySQL application so that it supports stored procedures
(issue #9217, tgledhill)

Modified:
    trunk/app_addon_sql_mysql.c

Modified: trunk/app_addon_sql_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/app_addon_sql_mysql.c?view=diff&rev=347&r1=346&r2=347
==============================================================================
--- trunk/app_addon_sql_mysql.c (original)
+++ trunk/app_addon_sql_mysql.c Tue Mar  6 16:36:23 2007
@@ -226,7 +226,8 @@
 	if( connid_var && dbhost && dbuser && dbpass && dbname ) {
 		mysql = mysql_init(NULL);
 		if (mysql) {
-			if (mysql_real_connect(mysql,dbhost,dbuser,dbpass,dbname,0,NULL,0)) {
+			if (mysql_real_connect(mysql, dbhost, dbuser, dbpass, dbname, 0 ,NULL,
+				CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS)) {
 				add_identifier_and_set_asterisk_int(chan,connid_var,AST_MYSQL_ID_CONNID,mysql);
 				return 0;
 			}
@@ -255,39 +256,31 @@
 	char *querystring;
 	int mysql_query_res;
 
-	strsep(&data," "); // eat the first token, we already know it :P 
+	strsep(&data, " ");
 
 	resultid_var = strsep(&data," ");
 	connid       = safe_scan_int(&data," ",-1);
 	querystring  = strsep(&data,"\n");
 
-	if (resultid_var && (connid>=0) && querystring) {
-		if ((mysql=find_identifier(connid,AST_MYSQL_ID_CONNID))!=NULL) {
-			mysql_query_res = mysql_query(mysql,querystring);
-			if (mysql_query_res != 0) {
-				ast_log(LOG_WARNING, "aMYSQL_query: mysql_query failed. Error: %s\n", mysql_error(mysql));
-			}
-			else {
-				if ((mysqlres=mysql_use_result(mysql))!=NULL) {
-					add_identifier_and_set_asterisk_int(chan,resultid_var,AST_MYSQL_ID_RESID,mysqlres);
-					return 0;
-				}
-				else if (mysql_field_count(mysql)==0) {
-					return 0;  // See http://dev.mysql.com/doc/mysql/en/mysql_field_count.html
-				}
-				else {
-					ast_log(LOG_WARNING,"aMYSQL_query: mysql_store_result() failed on query %s\n",querystring);
-				}
-			}
-		}
-		else {
-			ast_log(LOG_WARNING,"aMYSQL_query: Invalid connection identifier %d passed in aMYSQL_query\n",connid);
-		}
-	}
-	else {
-		ast_log(LOG_WARNING,"aMYSQL_query: missing some arguments\n");
-	}
-	
+	if (resultid_var && (connid >= 0) && querystring) {
+		if ((mysql=find_identifier(connid, AST_MYSQL_ID_CONNID))) {
+			mysql_query(mysql,querystring);
+			if ((mysqlres=mysql_store_result(mysql))) {
+				add_identifier_and_set_asterisk_int(chan,resultid_var,AST_MYSQL_ID_RESID,mysqlres);
+				if (mysql_more_results(mysql))
+					mysql_next_result(mysql);
+				return 0;
+			} else if (!mysql_field_count(mysql)) {
+				return 0;
+			} else
+				ast_log(LOG_WARNING,"mysql_store_result() failed on query %s\n",querystring);
+		} else
+			ast_log(LOG_WARNING,"Invalid connection identifier %d passed in aMYSQL_query\n",connid);
+	} else
+		ast_log(LOG_WARNING,"missing some arguments\n");
+
+	mysql_free_result(mysqlres);
+
 	return -1;
 }
 
@@ -320,12 +313,12 @@
 					pbx_builtin_setvar_helper(chan,s5, s6 ? s6 : "NULL");
 				}
 #if EXTRA_LOG
-				ast_log(LOG_WARNING,"ast_MYSQL_fetch: numFields=%d\n",numFields);
+				ast_log(LOG_DEBUG,"ast_MYSQL_fetch: numFields=%d\n",numFields);
 #endif
 				set_asterisk_int(chan,fetchid_var,1); // try more rows
 			} else {
 #if EXTRA_LOG
-				ast_log(LOG_WARNING,"ast_MYSQL_fetch : EOF\n");
+				ast_log(LOG_DEBUG,"ast_MYSQL_fetch : EOF\n");
 #endif
 				set_asterisk_int(chan,fetchid_var,0); // no more rows
 			}



More information about the svn-commits mailing list