[asterisk-commits] kpfleming: branch 1.2 r62796 - /branches/1.2/res/res_config_odbc.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed May 2 16:53:46 MST 2007


Author: kpfleming
Date: Wed May  2 18:53:46 2007
New Revision: 62796

URL: http://svn.digium.com/view/asterisk?view=rev&rev=62796
Log:
increase reliability and efficiency of static Realtime config loading via ODBC:
	don't request fields we aren't going to use
	don't request sorting on fields that are pointless to sort on
	explicitly request the fields we want, because we can't expect the database to always return them in the order they were created
	
(reported by blitzrage in person (!), patch by me)

Modified:
    branches/1.2/res/res_config_odbc.c

Modified: branches/1.2/res/res_config_odbc.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/res/res_config_odbc.c?view=diff&rev=62796&r1=62795&r2=62796
==============================================================================
--- branches/1.2/res/res_config_odbc.c (original)
+++ branches/1.2/res/res_config_odbc.c Wed May  2 18:53:46 2007
@@ -421,9 +421,11 @@
 	struct ast_category *cur_cat;
 	int res = 0;
 	odbc_obj *obj;
-	SQLINTEGER err=0, commented=0, cat_metric=0, var_metric=0, last_cat_metric=0;
-	SQLBIGINT id;
-	char sql[255] = "", filename[128], category[128], var_name[128], var_val[1024];
+	SQLINTEGER err=0, cat_metric=0, last_cat_metric=0;
+	char category[128], var_name[128], var_val[1024];
+	char sqlbuf[1024];
+	char *sql;
+	size_t sqlleft = sizeof(sqlbuf);
 	SQLSMALLINT rowcount=0;
 	SQLHSTMT stmt;
 	char last[128] = "";
@@ -437,18 +439,16 @@
 
 	res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
 
-	SQLBindCol (stmt, 1, SQL_C_ULONG, &id, sizeof (id), &err);
-	SQLBindCol (stmt, 2, SQL_C_ULONG, &cat_metric, sizeof (cat_metric), &err);
-	SQLBindCol (stmt, 3, SQL_C_ULONG, &var_metric, sizeof (var_metric), &err);
-	SQLBindCol (stmt, 4, SQL_C_ULONG, &commented, sizeof (commented), &err);
-	SQLBindCol (stmt, 5, SQL_C_CHAR, &filename, sizeof (filename), &err);
-	SQLBindCol (stmt, 6, SQL_C_CHAR, &category, sizeof (category), &err);
-	SQLBindCol (stmt, 7, SQL_C_CHAR, &var_name, sizeof (var_name), &err);
-	SQLBindCol (stmt, 8, SQL_C_CHAR, &var_val, sizeof (var_val), &err);
-	
-	snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE filename='%s' and commented=0 ORDER BY filename,cat_metric desc,var_metric asc,category,var_name,var_val,id", table, file);
-
-	res = odbc_smart_direct_execute(obj, stmt, sql);
+	SQLBindCol(stmt, 1, SQL_C_ULONG, &cat_metric, sizeof(cat_metric), &err);
+	SQLBindCol(stmt, 2, SQL_C_CHAR, &category, sizeof(category), &err);
+	SQLBindCol(stmt, 3, SQL_C_CHAR, &var_name, sizeof(var_name), &err);
+	SQLBindCol(stmt, 4, SQL_C_CHAR, &var_val, sizeof(var_val), &err);
+	
+	ast_build_string(&sql, &sqlleft, "SELECT cat_metric, category, var_name, var_val FROM %s ", table);
+	ast_build_string(&sql, &sqlleft, "WHERE filename='%s' AND commented=0 ", file);
+	ast_build_string(&sql, &sqlleft, "ORDER BY cat_metric DESC, var_metric ASC, category, var_name ");
+
+	res = odbc_smart_direct_execute(obj, stmt, sqlbuf);
 	
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 		ast_log (LOG_WARNING, "SQL select error!\n[%s]\n\n", sql);



More information about the asterisk-commits mailing list