当前位置: 首页>>代码示例>>C++>>正文


C++ DBexecute函数代码示例

本文整理汇总了C++中DBexecute函数的典型用法代码示例。如果您正苦于以下问题:C++ DBexecute函数的具体用法?C++ DBexecute怎么用?C++ DBexecute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DBexecute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: housekeeping_events

static int	housekeeping_events(int now)
{
	const char	*__function_name = "housekeeping_events";
	int		event_history, deleted = 0;
	DB_RESULT	result;
	DB_ROW		row;
	zbx_uint64_t	eventid;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s() now:%d", __function_name, now);

	result = DBselect("select eventid from events where clock<%d",
			now - *(int *)DCconfig_get_config_data(&event_history, CONFIG_EVENT_HISTORY) * SEC_PER_DAY);

	while (NULL != (row = DBfetch(result)))
	{
		ZBX_STR2UINT64(eventid, row[0]);

		DBexecute("delete from acknowledges where eventid=" ZBX_FS_UI64, eventid);
		deleted += DBexecute("delete from events where eventid=" ZBX_FS_UI64, eventid);
	}
	DBfree_result(result);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%d", __function_name, deleted);

	return deleted;
}
开发者ID:nabnut,项目名称:zabbix2.0-cookies,代码行数:26,代码来源:housekeeper.c

示例2: update_checksums

/******************************************************************************
 *                                                                            *
 * Function: update_checksums                                                 *
 *                                                                            *
 * Purpose: overwrite old checksums with new ones                             *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value: SUCCESS - calculated succesfully                             *
 *               FAIL - an error occured                                      *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int update_checksums()
{
    DBexecute("delete from node_cksum where cksumtype=%d",
              NODE_CKSUM_TYPE_OLD);
    DBexecute("update node_cksum set cksumtype=%d where cksumtype=%d",
              NODE_CKSUM_TYPE_OLD,
              NODE_CKSUM_TYPE_NEW);

    return SUCCEED;
}
开发者ID:Shmuma,项目名称:z,代码行数:26,代码来源:nodewatcher.c

示例3: housekeeping_process_log

/******************************************************************************
 *                                                                            *
 * Function: housekeeping_process_log                                         *
 *                                                                            *
 * Purpose: process table 'housekeeper' and remove data if required           *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value: SUCCEED - information removed succesfully                    *
 *               FAIL - otherwise                                             *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int housekeeping_process_log()
{
	DB_HOUSEKEEPER	housekeeper;

	DB_RESULT	result;
	DB_ROW		row;
	int		res = SUCCEED;

	long		deleted;

	zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_process_log()");

	/* order by tablename to effectively use DB cache */
	result = DBselect("select housekeeperid, tablename, field, value from housekeeper order by tablename");

	while((row=DBfetch(result)))
	{
		ZBX_STR2UINT64(housekeeper.housekeeperid,row[0]);
		housekeeper.tablename=row[1];
		housekeeper.field=row[2];
		ZBX_STR2UINT64(housekeeper.value,row[3]);

#ifdef HAVE_ORACLE
		deleted = DBexecute("delete from %s where %s=" ZBX_FS_UI64 " and rownum<500",
			housekeeper.tablename,
			housekeeper.field,
			housekeeper.value);
#elif defined(HAVE_POSTGRESQL)
		deleted = DBexecute("delete from %s where oid in (select oid from %s where %s=" ZBX_FS_UI64 " limit 500)",
				housekeeper.tablename, 
				housekeeper.tablename, 
				housekeeper.field,
				housekeeper.value);
#else
		deleted = DBexecute("delete from %s where %s=" ZBX_FS_UI64 " limit 500",
			housekeeper.tablename,
			housekeeper.field,
			housekeeper.value);
#endif
		if(deleted == 0)
		{
			DBexecute("delete from housekeeper where housekeeperid=" ZBX_FS_UI64,
				housekeeper.housekeeperid);
		}
		else
		{
			zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [%s]",
				deleted,
				housekeeper.tablename);
		}
	}
	DBfree_result(result);

	return res;
}
开发者ID:Shmuma,项目名称:z,代码行数:71,代码来源:housekeeper.c

示例4: process_deleted_records

/******************************************************************************
 *                                                                            *
 * Function: process_deleted_records                                          *
 *                                                                            *
 * Purpose:                                                                   *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static void	process_deleted_records(int nodeid, char *data, int sender_nodetype)
{
	const char	*__function_name = "process_deleted_records";
	char		*r, *lf;
	const ZBX_TABLE	*table = NULL;
	zbx_uint64_t	recid, *ids = NULL;
	int		ids_alloc = 0, ids_num = 0;
	char		*sql = NULL;
	size_t		sql_alloc = 4 * ZBX_KIBIBYTE, sql_offset = 0;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	sql = zbx_malloc(sql, sql_alloc);

	DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset);

	for (r = data; '\0' != *r;)
	{
		if (NULL != (lf = strchr(r, '\n')))
			*lf = '\0';

		zbx_get_next_field((const char **)&r, &buf, &buf_alloc, ZBX_DM_DELIMITER);

		if (NULL == table || 0 != strcmp(table->table, buf))
		{
			make_delete_sql(&sql, &sql_alloc, &sql_offset, table, ids, &ids_num);

			if (NULL == (table = DBget_table(buf)))
			{
				zabbix_log(LOG_LEVEL_DEBUG, "%s(): cannot find table [%s]", __function_name, buf);
				goto next;
			}
		}

		zbx_get_next_field((const char **)&r, &buf, &buf_alloc, ZBX_DM_DELIMITER);
		ZBX_STR2UINT64(recid, buf);

		if ('2' == *r)	/* NODE_CONFIGLOG_OP_DELETE */
			uint64_array_add(&ids, &ids_alloc, &ids_num, recid, 64);
next:
		if (lf != NULL)
		{
			*lf++ = '\n';
			r = lf;
		}
		else
			break;
	}

	make_delete_sql(&sql, &sql_alloc, &sql_offset, table, ids, &ids_num);

	DBend_multiple_update(&sql, &sql_alloc, &sql_offset);

	if (sql_offset > 16)	/* In ORACLE always present begin..end; */
		DBexecute("%s", sql);

	zbx_free(sql);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
}
开发者ID:gheja,项目名称:zabbix-ext,代码行数:75,代码来源:nodesync.c

示例5: ja_host_lock

/******************************************************************************
 *                                                                            *
 * Function:                                                                  *
 *                                                                            *
 * Purpose:                                                                   *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
int ja_host_lock(const char *host, const zbx_uint64_t inner_job_id)
{
    int db_ret;
    char *host_esc;
    const char *__function_name = "ja_host_lock";

    zabbix_log(LOG_LEVEL_DEBUG, "In %s() host: %s", __function_name, host);

    if (ja_host_getip(host, NULL, inner_job_id, NULL, JA_TXN_ON) == 0)
        return FAIL;

    DBfree_result(DBselect
                  ("select lock_host_name from ja_host_lock_table where lock_host_name = 'HOST_LOCK_RECORD' for update"));

    host_esc = DBdyn_escape_string(host);
    db_ret =
        DBexecute
        ("insert into ja_host_lock_table (lock_host_name) values ('%s')",
         host_esc);
    zbx_free(host_esc);

    if (db_ret < ZBX_DB_OK) {
        ja_log("JAHOST200005", 0, NULL, inner_job_id, __function_name, host, inner_job_id);
        return FAIL;
    } else {
        return SUCCEED;
    }
}
开发者ID:hatta0713,项目名称:jobarranger,代码行数:41,代码来源:jahost.c

示例6: DBpatch_2030113

static int	DBpatch_2030113(void)
{
	if (ZBX_DB_OK > DBexecute("delete from profiles where idx in ('web.latest.php.sort', 'web.httpmon.php.sort')"))
		return FAIL;

	return SUCCEED;
}
开发者ID:AdamBalali,项目名称:zabbix-agent-xxl,代码行数:7,代码来源:dbupgrade_2030.c

示例7: DBpatch_2030028

static int	DBpatch_2030028(void)
{
	if (ZBX_DB_OK > DBexecute("update items set formula='' where flags=%d", ZBX_FLAG_DISCOVERY_RULE))
		return FAIL;

	return SUCCEED;
}
开发者ID:AdamBalali,项目名称:zabbix-agent-xxl,代码行数:7,代码来源:dbupgrade_2030.c

示例8: op_host_disable

/******************************************************************************
 *                                                                            *
 * Function: op_host_disable                                                  *
 *                                                                            *
 * Purpose: disable host                                                      *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 ******************************************************************************/
void	op_host_disable(DB_EVENT *event)
{
	const char	*__function_name = "op_host_disable";
	zbx_uint64_t	hostid;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	if (event->source != EVENT_SOURCE_DISCOVERY && event->source != EVENT_SOURCE_AUTO_REGISTRATION)
		return;

	if (event->object != EVENT_OBJECT_DHOST && event->object != EVENT_OBJECT_DSERVICE && event->object != EVENT_OBJECT_ZABBIX_ACTIVE)
		return;

	if (0 == (hostid = add_discovered_host(event)))
		return;

	DBexecute(
			"update hosts"
			" set status=%d"
			" where hostid=" ZBX_FS_UI64,
			HOST_STATUS_NOT_MONITORED,
			hostid);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
}
开发者ID:baniuyao,项目名称:Zabbix_PPTV,代码行数:34,代码来源:operations.c

示例9: zbx_db_init

void	zbx_db_init(char *dbname)
{
#if defined(HAVE_SQLITE3)
	struct stat	buf;

	if (0 != stat(dbname, &buf))
	{
		zabbix_log(LOG_LEVEL_WARNING, "cannot open database file \"%s\": %s", dbname, zbx_strerror(errno));
		zabbix_log(LOG_LEVEL_WARNING, "creating database ...");

		if (SQLITE_OK != sqlite3_open(dbname, &conn))
		{
			zabbix_errlog(ERR_Z3002, dbname, 0, sqlite3_errmsg(conn));
			exit(FAIL);
		}

		zbx_create_sqlite3_mutex(dbname);

		DBexecute("%s", db_schema);
		DBclose();
	}
	else
		zbx_create_sqlite3_mutex(dbname);

#endif	/* HAVE_SQLITE3 */
}
开发者ID:hatta0713,项目名称:jobarranger,代码行数:26,代码来源:db.c

示例10: DBpatch_2010068

static int	DBpatch_2010068(void)
{
	if (ZBX_DB_OK <= DBexecute(
			"update config"
			" set hk_events_mode=0,"
				"hk_services_mode=0,"
				"hk_audit_mode=0,"
				"hk_sessions_mode=0,"
				"hk_history_mode=0,"
				"hk_trends_mode=0,"
				"hk_events_trigger="
					"case when event_history>alert_history"
					" then event_history else alert_history end,"
				"hk_events_discovery="
					"case when event_history>alert_history"
					" then event_history else alert_history end,"
				"hk_events_autoreg="
					"case when event_history>alert_history"
					" then event_history else alert_history end,"
				"hk_events_internal="
					"case when event_history>alert_history"
					" then event_history else alert_history end"))
	{
		return SUCCEED;
	}

	return FAIL;
}
开发者ID:HupuInc,项目名称:zabbix,代码行数:28,代码来源:dbupgrade_2010.c

示例11: register_host

/******************************************************************************
 *                                                                            *
 * Function: register_host                                                    *
 *                                                                            *
 * Purpose: register host if one does not exist                               *
 *                                                                            *
 * Parameters: host ip address                                                *
 *                                                                            *
 * Return value: dhostid or 0 if we didn't add host                           *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static void register_host(DB_DHOST *host,DB_DCHECK *check, zbx_uint64_t druleid, char *ip)
{
	DB_RESULT	result;
	DB_ROW		row;
	char		hostname[MAX_STRING_LEN], hostname_esc[MAX_STRING_LEN];

	assert(host);
	assert(check);
	assert(ip);

	zabbix_log(LOG_LEVEL_DEBUG, "In register_host(ip:%s)",
		ip);

	host->dhostid=0;
	result = DBselect("select dhostid,druleid,ip,status,lastup,lastdown from dhosts where ip='%s'", ip);
	row=DBfetch(result);
	if(!row || DBis_null(row[0])==SUCCEED)
	{
		/* Add host only if service is up */
		if(check->status == DOBJECT_STATUS_UP)
		{
			alarm(CONFIG_TIMEOUT);
			zbx_gethost_by_ip(ip, hostname, sizeof(hostname));
			alarm(0);

			if (hostname[0] != '\0')
				DBescape_string(hostname, hostname_esc, sizeof(hostname_esc));
			else
				hostname_esc[0] = '\0';

			zabbix_log(LOG_LEVEL_DEBUG, "New host discovered at %s (%s)",
				ip, hostname);

			host->dhostid = DBget_maxid("dhosts","dhostid");
			DBexecute("insert into dhosts (dhostid, druleid, dns, ip) values (" ZBX_FS_UI64 "," ZBX_FS_UI64 ", '%s','%s')",
				host->dhostid,
				druleid,
				hostname_esc,
				ip);
			host->druleid	= druleid;
			strscpy(host->ip,ip);
			host->status	= 0;
			host->lastup	= 0;
			host->lastdown  = 0;
		}
	}
	else
	{
		zabbix_log(LOG_LEVEL_DEBUG, "Host is already in database");
		ZBX_STR2UINT64(host->dhostid,row[0]);
		ZBX_STR2UINT64(host->druleid,row[1]);
		strscpy(host->ip,	row[2]);
		host->status		= atoi(row[3]);
		host->lastup		= atoi(row[4]);
		host->lastdown		= atoi(row[5]);
	}
	DBfree_result(result);

	zabbix_log(LOG_LEVEL_DEBUG, "End register_host()");
}
开发者ID:Shmuma,项目名称:z,代码行数:75,代码来源:discoverer.c

示例12: DBpatch_2010037

static int	DBpatch_2010037(void)
{
	if (ZBX_DB_OK <= DBexecute("update config set server_check_interval=10"))
		return SUCCEED;

	return FAIL;
}
开发者ID:HupuInc,项目名称:zabbix,代码行数:7,代码来源:dbupgrade_2010.c

示例13: DBpatch_2010050

static int	DBpatch_2010050(void)
{
	char		*fields[] = {"ts_from", "ts_to", NULL};
	DB_RESULT	result;
	DB_ROW		row;
	int		i;
	time_t		ts;
	struct tm	*tm;

	for (i = 0; NULL != fields[i]; i++)
	{
		result = DBselect(
				"select timeid,%s"
				" from services_times"
				" where type in (%d,%d)"
					" and %s>%d",
				fields[i], 0 /* SERVICE_TIME_TYPE_UPTIME */, 1 /* SERVICE_TIME_TYPE_DOWNTIME */,
				fields[i], SEC_PER_WEEK);

		while (NULL != (row = DBfetch(result)))
		{
			if (SEC_PER_WEEK < (ts = (time_t)atoi(row[1])))
			{
				tm = localtime(&ts);
				ts = tm->tm_wday * SEC_PER_DAY + tm->tm_hour * SEC_PER_HOUR + tm->tm_min * SEC_PER_MIN;
				DBexecute("update services_times set %s=%d where timeid=%s",
						fields[i], (int)ts, row[0]);
			}
		}
		DBfree_result(result);
	}

	return SUCCEED;
}
开发者ID:HupuInc,项目名称:zabbix,代码行数:34,代码来源:dbupgrade_2010.c

示例14: DBpatch_2010185

static int	DBpatch_2010185(void)
{
	if (ZBX_DB_OK > DBexecute("update sysmaps_elements set label_location=-1 where label_location is null"))
		return FAIL;

	return SUCCEED;
}
开发者ID:HupuInc,项目名称:zabbix,代码行数:7,代码来源:dbupgrade_2010.c

示例15: DBpatch_2010176

static int	DBpatch_2010176(void)
{
	DB_RESULT	result;
	DB_ROW		row;
	char		*name, *name_esc;
	int		ret = SUCCEED;

	result = DBselect("select scriptid,name from scripts");

	while (SUCCEED == ret && NULL != (row = DBfetch(result)))
	{
		name = zbx_dyn_escape_string(row[1], "/\\");

		if (0 != strcmp(name, row[1]))
		{
			name_esc = DBdyn_escape_string_len(name, 255);

			if (ZBX_DB_OK > DBexecute("update scripts set name='%s' where scriptid=%s", name_esc, row[0]))
				ret = FAIL;

			zbx_free(name_esc);
		}

		zbx_free(name);
	}
	DBfree_result(result);

	return ret;
}
开发者ID:HupuInc,项目名称:zabbix,代码行数:29,代码来源:dbupgrade_2010.c


注:本文中的DBexecute函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。