From d5a3ee3e914d2b2648a00d5e9bafea306f54b9b5 Mon Sep 17 00:00:00 2001 From: kpfleming Date: Wed, 2 May 2007 23:53:46 +0000 Subject: 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) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2@62796 f38db490-d61c-443f-a65b-d21fe96a405b --- res/res_config_odbc.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'res') diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c index 5a71ee561..fb3120757 100644 --- a/res/res_config_odbc.c +++ b/res/res_config_odbc.c @@ -421,9 +421,11 @@ static struct ast_config *config_odbc(const char *database, const char *table, c 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 @@ static struct ast_config *config_odbc(const char *database, const char *table, c 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); + 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); - 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); + 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, sql); + 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); -- cgit v1.2.3