diff options
-rwxr-xr-x | go | 4 | ||||
-rw-r--r-- | include/db.h | 2 | ||||
-rw-r--r-- | src/libs/zbxdbhigh/db.c | 13 | ||||
-rw-r--r-- | src/zabbix_server/server.c | 18 |
4 files changed, 33 insertions, 4 deletions
@@ -28,8 +28,8 @@ automake echo Configuring... export CFLAGS="-Wall" #export CFLAGS="-Wall -pedantic" -#./configure --enable-agent --enable-server --with-mysql --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null -./configure --enable-agent --enable-server --with-oracle --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null +./configure --enable-agent --enable-server --with-mysql --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null +#./configure --enable-agent --enable-server --with-oracle --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null echo Cleaning... make clean 2>>WARNINGS >/dev/null echo Making... diff --git a/include/db.h b/include/db.h index 189c8fb3..02a2be16 100644 --- a/include/db.h +++ b/include/db.h @@ -66,6 +66,7 @@ extern int CONFIG_DBPORT; #ifdef HAVE_MYSQL #define DB_RESULT MYSQL_RES * #define DBfree_result mysql_free_result + #define DB_ROW MYSQL_ROW #endif #ifdef HAVE_PGSQL @@ -336,6 +337,7 @@ int DBexecute( char *query ); long DBaffected_rows(); DB_RESULT DBselect(char *query); +DB_ROW DBfetch(DB_RESULT result); char *DBget_field(DB_RESULT result, int rownum, int fieldnum); int DBnum_rows(DB_RESULT result); int DBinsert_id(); diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c index 17d36e1d..3bcbb62e 100644 --- a/src/libs/zbxdbhigh/db.c +++ b/src/libs/zbxdbhigh/db.c @@ -180,6 +180,19 @@ int DBexecute(char *query) return SUCCEED; } +DB_ROW DBfetch(DB_RESULT result) +{ +#ifdef HAVE_MYSQL + return mysql_fetch_row(result); +#endif +#ifdef HAVE_ORACLE + if(SQLO_SUCCESS == sqlo_fetch(result, 1)) + return sqlo_values(result, NULL, 1); + else + return 0; +#endif +} + /* * Execute SQL statement. For select statements only. * If fails, program terminates. diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index e891c4a8..90a195fa 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -502,15 +502,29 @@ int main(int argc, char **argv) char sql[MAX_STRING_LEN]; DB_RESULT result; - const char ** v; +#ifdef HAVE_MYSQL + DB_ROW row; + init_config(); + + DBconnect(); + result = DBselect("select itemid,key_,description from items where 1=0"); + while((row=DBfetch(result))) + { + printf("%s %s %s\n",row[0],row[1],row[2]); + } + DBfree_result(result); + DBclose(); + return 0; +#endif #ifdef HAVE_ORACLE /* */ + const char ** v; DBconnect(); /* DBexecute("update history set value=value-10 where itemid=20272");*/ - result = DBselect("select * from history"); + result = DBselect("select itemid,key_,description from items"); while ( SQLO_SUCCESS == sqlo_fetch(result, 1)) { v = sqlo_values(result, NULL, 1); |