aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2007-05-03 00:10:38 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2007-05-03 00:10:38 +0000
commit0fab3b4de2572b9ee5ed5050163a63ee8c5f8f60 (patch)
treeae262c358861b14a8a74882a4b375e185534cd10 /res
parent4dd1f3a0c48e3240daca0c7ea3beed398e0dd81f (diff)
Merged revisions 62797,62807 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ................ r62797 | kpfleming | 2007-05-02 19:57:23 -0400 (Wed, 02 May 2007) | 7 lines improve static Realtime config loading from PostgreSQL: don't request sorting on fields that are pointless to sort on use ast_build_string() instead of snprintf() don't request the list of fieldnames that resulted from the query when we both knew what they were before we ran the query _AND_ we aren't going to do anything with them anyway (patch by me, inspired by blitzrage's bug report about res_config_odbc) ................ r62807 | kpfleming | 2007-05-02 20:02:57 -0400 (Wed, 02 May 2007) | 15 lines 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/trunk@62824 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r--res/res_config_odbc.c28
-rw-r--r--res/res_config_pgsql.c25
2 files changed, 20 insertions, 33 deletions
diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c
index 0e317640f..bb73521c9 100644
--- a/res/res_config_odbc.c
+++ b/res/res_config_odbc.c
@@ -444,11 +444,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 */
@@ -476,14 +472,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;
}
@@ -494,9 +486,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;
@@ -510,8 +504,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);
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index ed9b65e3e..624522744 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -462,7 +462,9 @@ static struct ast_config *config_pgsql(const char *database, const char *table,
long num_rows;
struct ast_variable *new_v;
struct ast_category *cur_cat = NULL;
- char sql[250] = "";
+ char sqlbuf[1024] = "";
+ char *sql;
+ size_t sqlleft = sizeof(sqlbuf);
char last[80] = "";
int last_cat_metric = 0;
@@ -473,12 +475,12 @@ static struct ast_config *config_pgsql(const char *database, const char *table,
return NULL;
}
- snprintf(sql, sizeof(sql),
- "SELECT category, var_name, var_val, cat_metric 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 category, var_name, var_val, cat_metric 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 ");
if (option_debug)
- ast_log(LOG_DEBUG, "Postgresql RealTime: Static SQL: %s\n", sql);
+ ast_log(LOG_DEBUG, "Postgresql RealTime: Static SQL: %s\n", sqlbuf);
/* We now have our complete statement; Lets connect to the server and execute it. */
ast_mutex_lock(&pgsql_lock);
@@ -487,7 +489,7 @@ static struct ast_config *config_pgsql(const char *database, const char *table,
return NULL;
}
- if (!(result = PQexec(pgsqlConn, sql))) {
+ if (!(result = PQexec(pgsqlConn, sqlbuf))) {
ast_log(LOG_WARNING,
"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
if (option_debug) {
@@ -515,22 +517,11 @@ static struct ast_config *config_pgsql(const char *database, const char *table,
}
if ((num_rows = PQntuples(result)) > 0) {
- int numFields = PQnfields(result);
- int i = 0;
int rowIndex = 0;
- char **fieldnames = NULL;
if (option_debug)
ast_log(LOG_DEBUG, "Postgresql RealTime: Found %ld rows.\n", num_rows);
- if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
- ast_mutex_unlock(&pgsql_lock);
- PQclear(result);
- return NULL;
- }
- for (i = 0; i < numFields; i++)
- fieldnames[i] = PQfname(result, i);
-
for (rowIndex = 0; rowIndex < num_rows; rowIndex++) {
char *field_category = PQgetvalue(result, rowIndex, 0);
char *field_var_name = PQgetvalue(result, rowIndex, 1);