[Asterisk-cvs] asterisk-addons res_config_mysql.c,1.7,1.8

kpfleming at lists.digium.com kpfleming at lists.digium.com
Thu Apr 21 22:39:06 CDT 2005


Update of /usr/cvsroot/asterisk-addons
In directory mongoose.digium.com:/tmp/cvs-serv13183

Modified Files:
	res_config_mysql.c 
Log Message:
report number of rows affected when using RealTime update method (bug #4066)


Index: res_config_mysql.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_config_mysql.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- res_config_mysql.c	28 Jan 2005 22:42:36 -0000	1.7
+++ res_config_mysql.c	22 Apr 2005 03:29:41 -0000	1.8
@@ -8,6 +8,9 @@
  *
  * res_config_mysql.c <mysql plugin for RealTime configuration engine >
  *
+ * v1.8   - (04-21-05) - Modified return values of update_mysql to better indicate
+ *                       what really happened.
+ *
  * v1.7   - (01-28-05) - Fixed non-initialization of ast_category struct
  *                       in realtime_multi_mysql function which caused segfault. 
  *
@@ -285,7 +288,7 @@
 
 	if(!table) {
 		ast_log(LOG_WARNING, "MySQL RealTime: No table specified.\n");
-		return 0;
+               return -1;
 	}
 
 	/* Get the first parameter and first value in our list of passed paramater/value pairs */
@@ -294,7 +297,7 @@
 	if(!newparam || !newval)  {
 		ast_log(LOG_WARNING, "MySQL RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
 		mysql_close(&mysql);
-		return 0;
+               return -1;
 	}
 
 	/* Create the first part of the query using the first parameter/value pairs we just extracted
@@ -312,7 +315,7 @@
 
 	/* We now have our complete statement; Lets connect to the server and execute it. */
 	if(!mysql_reconnect()) {
-		return 0;
+               return -1;
 	}
 
 	ast_mutex_lock(&mysql_lock);
@@ -321,7 +324,7 @@
 		ast_log(LOG_DEBUG, "MySQL RealTime: Query: %s\n", sql);
 		ast_log(LOG_DEBUG, "MySQL RealTime: Query Failed because: %s\n", mysql_error(&mysql));
 		ast_mutex_unlock(&mysql_lock);
-		return 0;
+               return -1;
 	}
 
 	numrows = mysql_affected_rows(&mysql);
@@ -329,9 +332,14 @@
 
 	ast_log(LOG_DEBUG,"MySQL RealTime: Updated %llu rows on table: %s\n", numrows, table);
 
-	if(numrows) {
-		return 0;
-	}
+       /* From http://dev.mysql.com/doc/mysql/en/mysql-affected-rows.html
+        * An integer greater than zero indicates the number of rows affected
+        * Zero indicates that no records were updated
+        * -1 indicates that the query returned an error (although, if the query failed, it should have been caught above.)
+       */
+
+       if(numrows >= 0)
+               return (int)numrows;
 
 	return -1;
 }




More information about the svn-commits mailing list