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


C++ IDatabase::PrepareQuery方法代码示例

本文整理汇总了C++中IDatabase::PrepareQuery方法的典型用法代码示例。如果您正苦于以下问题:C++ IDatabase::PrepareQuery方法的具体用法?C++ IDatabase::PrepareQuery怎么用?C++ IDatabase::PrepareQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDatabase的用法示例。


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

示例1: SQL_PrepareQuery

static cell_t SQL_PrepareQuery(IPluginContext *pContext, const cell_t *params)
{
	IDatabase *db = NULL;
	HandleError err;

	if ((err = g_DBMan.ReadHandle(params[1], DBHandle_Database, (void **)&db))
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid database Handle %x (error: %d)", params[1], err);
	}

	char *query, *error;
	size_t maxlength = (size_t)params[4];
	pContext->LocalToString(params[2], &query);
	pContext->LocalToString(params[3], &error);

	IPreparedQuery *qr = db->PrepareQuery(query, error, maxlength);

	if (!qr)
	{
		return BAD_HANDLE;
	}

	Handle_t hndl = g_HandleSys.CreateHandle(hStmtType, qr, pContext->GetIdentity(), g_pCoreIdent, NULL);
	if (hndl == BAD_HANDLE)
	{
		qr->Destroy();
		return BAD_HANDLE;
	}

	return hndl;
}
开发者ID:pmrowla,项目名称:sourcemod-1.5,代码行数:32,代码来源:smn_database.cpp

示例2: RunThread

void MysqlThread::RunThread(IThreadHandle *pHandle)
{
	DatabaseInfo info;

	info.database = m_db.chars();
	info.pass = "";
	info.user = "";
	info.host = "";
	info.port = 0;

	float save_time = m_qrInfo.queue_time;

	memset(&m_qrInfo, 0, sizeof(m_qrInfo));

	m_qrInfo.queue_time = save_time;

	IDatabase *pDatabase = g_Sqlite.Connect(&info, &m_qrInfo.amxinfo.info.errorcode, m_qrInfo.amxinfo.error, 254);
	IQuery *pQuery = NULL;
	if (!pDatabase)
	{
		m_qrInfo.connect_success = false;
		m_qrInfo.query_success = false;
	} else {
		m_qrInfo.connect_success = true;
		pQuery = pDatabase->PrepareQuery(m_query.chars());
		if (!pQuery->Execute2(&m_qrInfo.amxinfo.info, m_qrInfo.amxinfo.error, 254))
		{
			m_qrInfo.query_success = false;
		} else {
			m_qrInfo.query_success = true;
		}
	}

	if (m_qrInfo.query_success && m_qrInfo.amxinfo.info.rs)
	{
		m_atomicResult.CopyFrom(m_qrInfo.amxinfo.info.rs);
		m_qrInfo.amxinfo.info.rs = &m_atomicResult;
	}

	if (pQuery)
	{
		m_qrInfo.amxinfo.pQuery = pQuery;
	} else {
		m_qrInfo.amxinfo.opt_ptr = new char[m_query.length() + 1];
		strcpy(m_qrInfo.amxinfo.opt_ptr, m_query.chars());
	}

	if (pDatabase)
	{
		pDatabase->FreeHandle();
		pDatabase = NULL;
	}
}
开发者ID:Chuvi-w,项目名称:amxmodx,代码行数:53,代码来源:threading.cpp

示例3: MakeHandle

static cell AMX_NATIVE_CALL SQL_PrepareQuery(AMX *amx, cell *params)
{
	IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
	if (!pDb)
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
		return 0;
	}

	int len;
	char *fmt = MF_FormatAmxString(amx, params, 2, &len);

	IQuery *pQuery = pDb->PrepareQuery(fmt);
	if (!pQuery)
		return 0;

	AmxQueryInfo *qinfo = new AmxQueryInfo;
	qinfo->pQuery = pQuery;

	memset(&qinfo->info, 0, sizeof(QueryInfo));

	return MakeHandle(qinfo, Handle_Query, FreeQuery);
}
开发者ID:Arkshine,项目名称:amxmodx,代码行数:23,代码来源:basic_sql.cpp


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