summaryrefslogtreecommitdiffstats
path: root/src/zabbix_server/functions.c
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-06 23:31:27 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-06 23:31:27 +0000
commitdf815285d27dc77733398d14db0bfbc27a7a3c3e (patch)
tree1171521dc5dfb3c96283338647b67a7b154663be /src/zabbix_server/functions.c
parent7a294da6a5b3190270d635824592dc6b4c5b8ac5 (diff)
downloadzabbix-df815285d27dc77733398d14db0bfbc27a7a3c3e.tar.gz
zabbix-df815285d27dc77733398d14db0bfbc27a7a3c3e.tar.xz
zabbix-df815285d27dc77733398d14db0bfbc27a7a3c3e.zip
- improved performance of MySQL calls (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@2812 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_server/functions.c')
-rw-r--r--src/zabbix_server/functions.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c
index f3c5af5a..70dc7444 100644
--- a/src/zabbix_server/functions.c
+++ b/src/zabbix_server/functions.c
@@ -71,12 +71,12 @@ void update_functions(DB_ITEM *item)
{
DB_FUNCTION function;
DB_RESULT result;
+ DB_ROW row;
char sql[MAX_STRING_LEN];
char value[MAX_STRING_LEN];
char value_esc[MAX_STRING_LEN];
char *lastvalue;
int ret=SUCCEED;
- int i;
zabbix_log( LOG_LEVEL_DEBUG, "In update_functions(%d)",item->itemid);
@@ -84,12 +84,12 @@ void update_functions(DB_ITEM *item)
result = DBselect(sql);
- for(i=0;i<DBnum_rows(result);i++)
+ while((row=DBfetch(result)))
{
- function.function=DBget_field(result,i,0);
- function.parameter=DBget_field(result,i,1);
- function.itemid=atoi(DBget_field(result,i,2));
- lastvalue=DBget_field(result,i,3);
+ function.function=row[0];
+ function.parameter=row[1];
+ function.itemid=atoi(row[2]);
+ lastvalue=row[3];
zabbix_log( LOG_LEVEL_DEBUG, "ItemId:%d Evaluating %s(%d)\n",function.itemid,function.function,function.parameter);
@@ -230,20 +230,19 @@ void update_services_rec(int serviceid)
void update_services(int triggerid, int status)
{
char sql[MAX_STRING_LEN];
- int i;
+ DB_ROW row;
DB_RESULT result;
snprintf(sql,sizeof(sql)-1,"update services set status=%d where triggerid=%d",status,triggerid);
DBexecute(sql);
-
snprintf(sql,sizeof(sql)-1,"select serviceid from services where triggerid=%d", triggerid);
result = DBselect(sql);
- for(i=0;i<DBnum_rows(result);i++)
+ while((row=DBfetch(result)))
{
- update_services_rec(atoi(DBget_field(result,i,0)));
+ update_services_rec(atoi(row[0]));
}
DBfree_result(result);
@@ -274,8 +273,7 @@ void update_triggers(int itemid)
time_t now;
DB_TRIGGER trigger;
DB_RESULT result;
-
- int i;
+ DB_ROW row;
zabbix_log( LOG_LEVEL_DEBUG, "In update_triggers [%d]", itemid);
@@ -286,14 +284,14 @@ void update_triggers(int itemid)
result = DBselect(sql);
- for(i=0;i<DBnum_rows(result);i++)
+ while((row==DBfetch(result)))
{
- trigger.triggerid=atoi(DBget_field(result,i,0));
- strscpy(trigger.expression,DBget_field(result,i,1));
- trigger.status=atoi(DBget_field(result,i,2));
- trigger.priority=atoi(DBget_field(result,i,4));
- trigger.value=atoi(DBget_field(result,i,5));
- strscpy(trigger.description,DBget_field(result,i,6));
+ trigger.triggerid=atoi(row[0]);
+ strscpy(trigger.expression,row[1]);
+ trigger.status=atoi(row[2]);
+ trigger.priority=atoi(row[4]);
+ trigger.value=atoi(row[5]);
+ strscpy(trigger.description,row[6]);
strscpy(exp, trigger.expression);
if( evaluate_expression(&exp_value, exp, error, sizeof(error)) != 0 )