The data structure of the operation result of MySQL database
This article mainly explains the "data structure of MySQL database operation results". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the data structure of MySQL database operation results.
I. data structure of database operation results
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
}
The database is queried according to sql
/ *
* *
* Function: DBselect *
* *
* Purpose: execute a select statement *
* *
* Comments: retry until DB is up *
* *
* * /
DB_RESULT _ _ zbx_DBselect (const char * fmt,...)
{
Va_list args; / / Parameter list
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
}
3. Data structure of MySQL operation result
Typedef struct st_mysql_res {
My_ulonglong row_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
Thank you for your reading, the above is the content of "data structure of MySQL database operation results". After the study of this article, I believe you have a deeper understanding of the data structure of MySQL database operation results, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!