diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-05-03 00:02:57 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-05-03 00:02:57 +0000 |
commit | e732d7145b867525ec86a6fb4a01438f849ffce4 (patch) | |
tree | 385955c367ad164e6a02c143fe6d4018fbbd9a46 /res | |
parent | f9d75a502ad378393ce5edee0d779b52364b3d0e (diff) |
Merged revisions 62796 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r62796 | kpfleming | 2007-05-02 19:53:46 -0400 (Wed, 02 May 2007) | 7 lines
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.4@62807 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r-- | res/res_config_odbc.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c index a2cfa7cf5..e0600d9a6 100644 --- a/res/res_config_odbc.c +++ b/res/res_config_odbc.c @@ -442,11 +442,7 @@ static int update_odbc(const char *database, const char *table, const char *keyf struct config_odbc_obj { char *sql; - unsigned long id; unsigned long cat_metric; - unsigned long var_metric; - unsigned long commented; - char filename[128]; char category[128]; char var_name[128]; char var_val[1024]; /* changed from 128 to 1024 via bug 8251 */ @@ -474,14 +470,10 @@ static SQLHSTMT config_odbc_prepare(struct odbc_obj *obj, void *data) return NULL; } - SQLBindCol(sth, 1, SQL_C_ULONG, &q->id, sizeof(q->id), &q->err); - SQLBindCol(sth, 2, SQL_C_ULONG, &q->cat_metric, sizeof(q->cat_metric), &q->err); - SQLBindCol(sth, 3, SQL_C_ULONG, &q->var_metric, sizeof(q->var_metric), &q->err); - SQLBindCol(sth, 4, SQL_C_ULONG, &q->commented, sizeof(q->commented), &q->err); - SQLBindCol(sth, 5, SQL_C_CHAR, q->filename, sizeof(q->filename), &q->err); - SQLBindCol(sth, 6, SQL_C_CHAR, q->category, sizeof(q->category), &q->err); - SQLBindCol(sth, 7, SQL_C_CHAR, q->var_name, sizeof(q->var_name), &q->err); - SQLBindCol(sth, 8, SQL_C_CHAR, q->var_val, sizeof(q->var_val), &q->err); + SQLBindCol(sth, 1, SQL_C_ULONG, &q->cat_metric, sizeof(q->cat_metric), &q->err); + SQLBindCol(sth, 2, SQL_C_CHAR, q->category, sizeof(q->category), &q->err); + SQLBindCol(sth, 3, SQL_C_CHAR, q->var_name, sizeof(q->var_name), &q->err); + SQLBindCol(sth, 4, SQL_C_CHAR, q->var_val, sizeof(q->var_val), &q->err); return sth; } @@ -492,9 +484,11 @@ static struct ast_config *config_odbc(const char *database, const char *table, c struct ast_category *cur_cat; int res = 0; struct odbc_obj *obj; - char sql[255] = ""; + char sqlbuf[1024] = ""; + char *sql; + size_t sqlleft = sizeof(sqlbuf); unsigned int last_cat_metric = 0; - SQLSMALLINT rowcount=0; + SQLSMALLINT rowcount = 0; SQLHSTMT stmt; char last[128] = ""; struct config_odbc_obj q; @@ -508,8 +502,10 @@ static struct ast_config *config_odbc(const char *database, const char *table, c if (!obj) return NULL; - 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); - q.sql = sql; + 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 "); + q.sql = sqlbuf; stmt = ast_odbc_prepare_and_execute(obj, config_odbc_prepare, &q); |