[svn-commits] kpfleming: branch 1.4 r62797 -
/branches/1.4/res/res_config_pgsql.c
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Wed May 2 16:57:24 MST 2007
Author: kpfleming
Date: Wed May 2 18:57:23 2007
New Revision: 62797
URL: http://svn.digium.com/view/asterisk?view=rev&rev=62797
Log:
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)
Modified:
branches/1.4/res/res_config_pgsql.c
Modified: branches/1.4/res/res_config_pgsql.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/res/res_config_pgsql.c?view=diff&rev=62797&r1=62796&r2=62797
==============================================================================
--- branches/1.4/res/res_config_pgsql.c (original)
+++ branches/1.4/res/res_config_pgsql.c Wed May 2 18:57:23 2007
@@ -444,7 +444,9 @@
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;
@@ -455,11 +457,11 @@
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_log(LOG_DEBUG, "Postgresql RealTime: Static SQL: %s\n", sql);
+ 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 ");
+
+ 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);
@@ -468,7 +470,7 @@
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");
ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
@@ -492,20 +494,9 @@
}
if ((num_rows = PQntuples(result)) > 0) {
- int numFields = PQnfields(result);
- int i = 0;
int rowIndex = 0;
- char **fieldnames = NULL;
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);
More information about the svn-commits
mailing list