[asterisk-commits] twilson: branch twilson/res_config_sqlite3 r334430 - /team/twilson/res_config...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Sep 3 12:21:09 CDT 2011


Author: twilson
Date: Sat Sep  3 12:20:58 2011
New Revision: 334430

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=334430
Log:
Use two variables where one would suffice for sake of clarity

Make the compiler earn its keep. :-)

Modified:
    team/twilson/res_config_sqlite3/res/res_config_sqlite3.c

Modified: team/twilson/res_config_sqlite3/res/res_config_sqlite3.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/res_config_sqlite3/res/res_config_sqlite3.c?view=diff&rev=334430&r1=334429&r2=334430
==============================================================================
--- team/twilson/res_config_sqlite3/res/res_config_sqlite3.c (original)
+++ team/twilson/res_config_sqlite3/res/res_config_sqlite3.c Sat Sep  3 12:20:58 2011
@@ -627,7 +627,7 @@
 {
 	struct ast_str *sql;
 	const char *key, *value;
-	int tmp = 1;
+	int first = 1, res;
 
 	if (ast_strlen_zero(table)) {
 		ast_log(LOG_WARNING, "Must have a table to query!\n");
@@ -639,9 +639,9 @@
 	}
 
 	while ((key = va_arg(ap, const char *)) && (value = va_arg(ap, const char *))) {
-		if (tmp) {
+		if (first) {
 			ast_str_set(&sql, 0, "UPDATE %s SET `%s` = '%s'", table, key, value);
-			tmp = 0;
+			first = 0;
 		} else {
 			ast_str_append(&sql, 0, ", `%s` = '%s'", key, value);
 		}
@@ -649,10 +649,10 @@
 
 	ast_str_append(&sql, 0, " WHERE %s%s '%s'", keyfield, strchr(keyfield, ' ') ? "" : " =", entity);
 
-	tmp = realtime_sqlite3_execute(database, ast_str_buffer(sql), NULL, NULL, 1);
+	res = realtime_sqlite3_execute(database, ast_str_buffer(sql), NULL, NULL, 1);
 	ast_free(sql);
 
-	return tmp;
+	return res;
 }
 
 /*! \brief Realtime callback for updating a row based on multiple criteria
@@ -663,7 +663,7 @@
 	struct ast_str *sql;
 	struct ast_str *where_clause;
 	const char *key, *value;
-	int tmp = 1;
+	int first = 1, res;
 
 	if (ast_strlen_zero(table)) {
 		ast_log(LOG_WARNING, "Must have a table to query!\n");
@@ -680,19 +680,19 @@
 	}
 
 	while ((key = va_arg(ap, const char *)) && (value = va_arg(ap, const char *))) {
-		if (tmp) {
+		if (first) {
 			ast_str_append(&where_clause, 0, " WHERE %s%s '%s'", key, strchr(key, ' ') ? "" : " =", value);
-			tmp = 0;
+			first = 0;
 		} else {
 			ast_str_append(&where_clause, 0, " AND %s%s '%s'", key, strchr(key, ' ') ? "" : " =", value);
 		}
 	}
 
-	tmp = 1;
+	first = 1;
 	while ((key = va_arg(ap, const char *)) && (value = va_arg(ap, const char *))) {
-		if (tmp) {
+		if (first) {
 			ast_str_set(&sql, 0, "UPDATE %s SET `%s` = '%s'", table, key, value);
-			tmp = 0;
+			first = 0;
 		} else {
 			ast_str_append(&sql, 0, ", `%s` = '%s'", key, value);
 		}
@@ -700,12 +700,12 @@
 
 	ast_str_append(&sql, 0, "%s", ast_str_buffer(where_clause));
 
-	tmp = realtime_sqlite3_execute(database, ast_str_buffer(sql), NULL, NULL, 1);
+	res = realtime_sqlite3_execute(database, ast_str_buffer(sql), NULL, NULL, 1);
 
 	ast_free(sql);
 	ast_free(where_clause);
 
-	return tmp;
+	return res;
 }
 
 /*! \brief Realtime callback for inserting a row
@@ -715,7 +715,7 @@
 {
 	struct ast_str *sql, *values;
 	const char *column, *value;
-	int tmp = 1;
+	int first = 1, res;
 
 	if (ast_strlen_zero(table)) {
 		ast_log(LOG_WARNING, "Must have a table to query!\n");
@@ -732,10 +732,10 @@
 	}
 
 	while ((column = va_arg(ap, const char *)) && (value = va_arg(ap, const char *))) {
-		if (tmp) {
+		if (first) {
 			ast_str_set(&sql, 0, "INSERT INTO %s (`%s`", table, column);
 			ast_str_set(&values, 0, ") VALUES ('%s'", value);
-			tmp = 0;
+			first = 0;
 		} else {
 			ast_str_append(&sql, 0, ", `%s`", column);
 			ast_str_append(&values, 0, ", '%s'", value);
@@ -744,12 +744,12 @@
 
 	ast_str_append(&sql, 0, "%s)", ast_str_buffer(values));
 
-	tmp = realtime_sqlite3_execute(database, ast_str_buffer(sql), NULL, NULL, 1);
+	res = realtime_sqlite3_execute(database, ast_str_buffer(sql), NULL, NULL, 1);
 
 	ast_free(sql);
 	ast_free(values);
 
-	return tmp;
+	return res;
 }
 
 /*! \brief Realtime callback for deleting a row
@@ -759,7 +759,7 @@
 {
 	struct ast_str *sql;
 	const char *param, *value;
-	int tmp = 1;
+	int first = 1, res;
 
 	if (ast_strlen_zero(table)) {
 		ast_log(LOG_WARNING, "Must have a table to query!\n");
@@ -771,19 +771,19 @@
 	}
 
 	while ((param = va_arg(ap, const char *)) && (value = va_arg(ap, const char *))) {
-		if (tmp) {
+		if (first) {
 			ast_str_set(&sql, 0, "DELETE FROM %s WHERE %s%s '%s'", table, param, strchr(param, ' ') ? "" : " =", value);
-			tmp = 0;
+			first = 0;
 		} else {
 			ast_str_append(&sql, 0, " AND %s%s '%s'", param, strchr(param, ' ') ? "" : " =", value);
 		}
 	}
 
-	tmp = realtime_sqlite3_execute(database, ast_str_buffer(sql), NULL, NULL, 1);
+	res = realtime_sqlite3_execute(database, ast_str_buffer(sql), NULL, NULL, 1);
 
 	ast_free(sql);
 
-	return tmp;
+	return res;
 }
 
 /*! \brief Convert Asterisk realtime types to SQLite 3 types
@@ -824,7 +824,7 @@
 static int handle_missing_table(struct realtime_sqlite3_db *db, const char *table, va_list ap)
 {
 	const char *column;
-	int type, tmp = 1;
+	int type, first = 1, res;
 	size_t sz;
 	struct ast_str *sql;
 
@@ -833,9 +833,9 @@
 	}
 
 	while ((column = va_arg(ap, typeof(column))) && (type = va_arg(ap, typeof(type))) && (sz = va_arg(ap, typeof(sz)))) {
-		if (tmp) {
+		if (first) {
 			ast_str_set(&sql, 0, "CREATE TABLE IF NOT EXISTS %s (%s %s", table, column, get_sqlite_column_type(type));
-			tmp = 0;
+			first = 0;
 		} else {
 			ast_str_append(&sql, 0, ", %s %s", column, get_sqlite_column_type(type));
 		}
@@ -843,10 +843,10 @@
 
 	ast_str_append(&sql, 0, ")");
 
-	tmp = realtime_sqlite3_execute_handle(db, ast_str_buffer(sql), NULL, NULL, 1) < 0 ? -1 : 0;
+	res = realtime_sqlite3_execute_handle(db, ast_str_buffer(sql), NULL, NULL, 1) < 0 ? -1 : 0;
 	ast_free(sql);
 
-	return tmp;
+	return res;
 }
 
 /*! \brief If ast_realtime_require sends info about a column we don't have, create it




More information about the asterisk-commits mailing list