Source
void zbx_db_insert_prepare_dyn(zbx_db_insert_t *self, const zbx_db_table_t *table, const zbx_db_field_t **fields,
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
static zbx_dbconn_t *dbconn;
static int db_autoincrement;
void zbx_db_init_autoincrement_options(void)
{
db_autoincrement = 1;
}
/******************************************************************************
* *
* Purpose: connect to the database *
* *
* Parameters: flag - ZBX_DB_CONNECT_ONCE (try once and return the result), *
* ZBX_DB_CONNECT_EXIT (exit on failure) or *
* ZBX_DB_CONNECT_NORMAL (retry until connected) *
* *
* Return value: ZBX_DB_OK - successfully connected *
* ZBX_DB_DOWN - database is down *
* ZBX_DB_FAIL - failed to connect *
* *
******************************************************************************/
int zbx_db_connect(int flag)
{
int ret;
zbx_dbconn_t *db;
if (NULL != dbconn)
THIS_SHOULD_NEVER_HAPPEN;
db = zbx_dbconn_create();
(void)zbx_dbconn_set_connect_options(db, flag);
zbx_dbconn_set_autoincrement(db, db_autoincrement);
ret = zbx_dbconn_open(db);
dbconn = db;
return ret;
}
/******************************************************************************
* *
* Purpose: close database connection *