[asterisk-addons-commits] tilghman: branch 1.6.1 r692 - /branches/1.6.1/res/res_config_mysql.c

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Wed Nov 12 13:35:48 CST 2008


Author: tilghman
Date: Wed Nov 12 13:35:47 2008
New Revision: 692

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=692
Log:
Remove portions of API that aren't in Asterisk-1.6.1

Modified:
    branches/1.6.1/res/res_config_mysql.c

Modified: branches/1.6.1/res/res_config_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/branches/1.6.1/res/res_config_mysql.c?view=diff&rev=692&r1=691&r2=692
==============================================================================
--- branches/1.6.1/res/res_config_mysql.c (original)
+++ branches/1.6.1/res/res_config_mysql.c Wed Nov 12 13:35:47 2008
@@ -652,133 +652,6 @@
 	return (int)numrows;
 }
 
-#define ESCAPE_STRING(buf, var) \
-	do { \
-		size_t size; \
-		if ((size = strlen(var)) * 2 + 1 > (buf)->len) { \
-			ast_str_make_space(&(buf), size * 2 + 1); \
-		} \
-		mysql_real_escape_string(&dbh->handle, (buf)->str, var, size); \
-	} while (0)
-
-static int update2_mysql(const char *database, const char *tablename, va_list ap)
-{
-	struct mysql_conn *dbh;
-	my_ulonglong numrows;
-	int first = 1;
-	const char *newparam, *newval;
-	struct ast_str *sql = ast_str_thread_get(&sql_buf, 100), *buf = ast_str_thread_get(&scratch_buf, 100);
-	struct ast_str *where = ast_str_thread_get(&sql2_buf, 100);
-	struct tables *table;
-	struct columns *column = NULL;
-
-	if (!tablename) {
-		ast_log(LOG_WARNING, "MySQL RealTime: No table specified.\n");
-		return -1;
-	}
-
-	if (!(dbh = find_database(database, 1))) {
-		ast_log(LOG_ERROR, "Invalid database specified: %s\n", database);
-		return -1;
-	}
-
-	if (!(table = find_table(database, tablename))) {
-		ast_log(LOG_ERROR, "Table '%s' does not exist!!\n", tablename);
-		release_database(dbh);
-		return -1;
-	}
-
-	if (!sql || !buf || !where) {
-		release_database(dbh);
-		release_table(table);
-		return -1;
-	}
-
-	ast_str_set(&sql, 0, "UPDATE %s SET", tablename);
-	ast_str_set(&where, 0, "WHERE");
-
-	/* Must connect to the server before anything else, as the escape function requires the mysql handle. */
-	if (!mysql_reconnect(dbh)) {
-		release_table(table);
-		release_database(dbh);
-		return -1;
-	}
-
-	while ((newparam = va_arg(ap, const char *))) {
-		if (!(column = find_column(table, newparam))) {
-			ast_log(LOG_ERROR, "Updating on column '%s', but that column does not exist within the table '%s'!\n", newparam, tablename);
-			release_table(table);
-			release_database(dbh);
-			return -1;
-		}
-		if (!(newval = va_arg(ap, const char *))) {
-			ast_log(LOG_ERROR, "Invalid arguments: no value specified for column '%s' on '%s@%s'\n", newparam, tablename, database);
-			release_table(table);
-			release_database(dbh);
-			return -1;
-		}
-		ESCAPE_STRING(buf, newval);
-		ast_str_append(&where, 0, "%s %s='%s'", first ? "" : " AND", newparam, buf->str);
-		first = 0;
-
-		/* If the column length isn't long enough, give a chance to lengthen it. */
-		if (strncmp(column->type, "char", 4) == 0 || strncmp(column->type, "varchar", 7) == 0) {
-			internal_require(database, tablename, newparam, RQ_CHAR, buf->used, SENTINEL);
-		}
-	}
-
-	first = 1;
-	while ((newparam = va_arg(ap, const char *))) {
-		if (!(newval = va_arg(ap, const char *))) {
-			ast_log(LOG_ERROR, "Invalid arguments: no value specified for column '%s' on '%s@%s'\n", newparam, tablename, database);
-			release_table(table);
-			release_database(dbh);
-			return -1;
-		}
-
-		/* If the column is not within the table, then skip it */
-		if (!(column = find_column(table, newparam))) {
-			ast_log(LOG_WARNING, "Attempted to update column '%s' in table '%s', but column does not exist!\n", newparam, tablename);
-			continue;
-		}
-
-		ESCAPE_STRING(buf, newval);
-		ast_str_append(&sql, 0, "%s %s = '%s'", first ? "" : ",", newparam, buf->str);
-
-		/* If the column length isn't long enough, give a chance to lengthen it. */
-		if (strncmp(column->type, "char", 4) == 0 || strncmp(column->type, "varchar", 7) == 0) {
-			internal_require(database, tablename, newparam, RQ_CHAR, strlen(newval), SENTINEL);
-		}
-	}
-	va_end(ap);
-	release_table(table);
-
-	ast_str_append(&sql, 0, " %s", where->str);
-
-	ast_debug(1, "MySQL RealTime: Update SQL: %s\n", sql->str);
-
-	/* Execution. */
-	if (mysql_real_query(&dbh->handle, sql->str, sql->used)) {
-		ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database: %s\n", mysql_error(&dbh->handle));
-		release_table(table);
-		release_database(dbh);
-		return -1;
-	}
-
-	numrows = mysql_affected_rows(&dbh->handle);
-	release_database(dbh);
-
-	ast_debug(1, "MySQL RealTime: Updated %llu rows on table: %s\n", numrows, tablename);
-
-	/* 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.)
-	*/
-
-	return (int)numrows;
-}
- 
 static int store_mysql(const char *database, const char *table, va_list ap)
 {
 	struct mysql_conn *dbh;
@@ -1376,7 +1249,6 @@
 	.store_func = store_mysql,
 	.destroy_func = destroy_mysql,
 	.update_func = update_mysql,
-	.update2_func = update2_mysql,
 	.require_func = require_mysql,
 	.unload_func = unload_mysql,
 };
@@ -1440,12 +1312,10 @@
 	const char *catg;
 	struct mysql_conn *cur;
 
-	if ((config = ast_config_load(RES_CONFIG_MYSQL_CONF, config_flags)) == CONFIG_STATUS_FILEMISSING) {
+	if (!(config = ast_config_load(RES_CONFIG_MYSQL_CONF, config_flags))) {
 		return 0;
 	} else if (config == CONFIG_STATUS_FILEUNCHANGED) {
 		return 0;
-	} else if (config == CONFIG_STATUS_FILEINVALID) {
-		ast_log(LOG_ERROR, "Not %sloading " RES_CONFIG_MYSQL_CONF "\n", reload ? "re" : "");
 	}
 
 	AST_LIST_LOCK(&databases);




More information about the asterisk-addons-commits mailing list