看看zabbix 数据库操作结构体
一、数据库操作结果数据结构struct zbx_db_result{#if defined(HAVE_IBM_DB2) SQLHANDLE hstmt; SQLSMALLINT nalloc; SQLSMALLINT ncolumn; DB_ROW values; DB_ROW values_cli; SQLINTEGER *values_len;#elif defined(HAVE_MYSQL) MYSQL_RES *result;#elif defined(HAVE_ORACLE) OCIStmt *stmthp; /* the statement handle for select operations */ int ncolumn; DB_ROW values; ub4 *values_alloc; OCILobLocator **clobs;#elif defined(HAVE_POSTGRESQL) PGresult *pg_result; int row_num; int fld_num; int cursor; DB_ROW values;#elif defined(HAVE_SQLITE3) int curow; char **data; int nrow; int ncolumn; DB_ROW values;#endif};
二、数据库根据sql查询/****************************************************************************** * * * Function: DBselect * * * * Purpose: execute a select statement * * * * Comments: retry until DB is up * * * ******************************************************************************/DB_RESULT __zbx_DBselect(const char *fmt, ...){ va_list args;//参数列表 DB_RESULT rc;
va_start(args, fmt);
rc = zbx_db_vselect(fmt, args);
while ((DB_RESULT)ZBX_DB_DOWN == rc) { DBclose(); DBconnect(ZBX_DB_CONNECT_NORMAL);
if ((DB_RESULT)ZBX_DB_DOWN == (rc = zbx_db_vselect(fmt, args))) { zabbix_log(LOG_LEVEL_ERR, "database is down: retrying in %d seconds", ZBX_DB_WAIT_DOWN); connection_failure = 1; sleep(ZBX_DB_WAIT_DOWN); } }
va_end(args);
return rc;}
三、MySQL操作结果数据结构
typedef struct st_mysql_res {my_ulonglongrow_count;MYSQL_FIELD *fields;MYSQL_DATA *data;MYSQL_ROWS *data_cursor;unsigned long *lengths; /* column lengths of current row */MYSQL *handle; /* for unbuffered reads */const struct st_mysql_methods *methods;MYSQL_ROW row; /* If unbuffered read */MYSQL_ROW current_row; /* buffer to current row */MEM_ROOT field_alloc;unsigned int field_count, current_field;my_bool eof; /* Used by mysql_fetch_row *//* mysql_stmt_close() had to cancel this result */my_bool unbuffered_fetch_cancelled;void *extension;} MYSQL_RES;
原创:黑洞
页:
[1]