aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2007-05-02 23:53:46 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2007-05-02 23:53:46 +0000
commitd5a3ee3e914d2b2648a00d5e9bafea306f54b9b5 (patch)
tree399336d08f8e5e545f6f403d83339fad83a6a6c5 /res
parent2faf048c3dc1ec4fefe65cb9046402f8c546e884 (diff)
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
Diffstat (limited to 'res')
-rw-r--r--res/res_config_odbc.c26
1 files changed, 13 insertions, 13 deletions
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);