本文整理汇总了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;
}
示例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;
}
}
示例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);
}