本文整理汇总了C++中IPreparedQuery类的典型用法代码示例。如果您正苦于以下问题:C++ IPreparedQuery类的具体用法?C++ IPreparedQuery怎么用?C++ IPreparedQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPreparedQuery类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: SQL_GetError
static cell_t SQL_GetError(IPluginContext *pContext, const cell_t *params)
{
IDatabase *db = NULL;
IPreparedQuery *stmt = NULL;
HandleError err;
if ((err = ReadDbOrStmtHndl(params[1], pContext, &db, &stmt)) != HandleError_None)
{
return pContext->ThrowNativeError("Invalid statement or db Handle %x (error: %d)", params[1], err);
}
const char *error = "";
if (db)
{
error = db->GetError();
} else if (stmt) {
error = stmt->GetError();
}
if (error[0] == '\0')
{
return false;
}
pContext->StringToLocalUTF8(params[2], params[3], error, NULL);
return 1;
}
示例3: SQL_GetInsertId
static cell_t SQL_GetInsertId(IPluginContext *pContext, const cell_t *params)
{
IDatabase *db = NULL;
IQuery *query = NULL;
IPreparedQuery *stmt = NULL;
HandleError err;
if (((err = ReadDbOrStmtHndl(params[1], pContext, &db, &stmt)) != HandleError_None)
&& ((err = ReadQueryAndDbHndl(params[1], pContext, &query, &db)) != HandleError_None))
{
return pContext->ThrowNativeError("Invalid statement, db, or query Handle %x (error: %d)", params[1], err);
}
if (query)
{
return db->GetInsertIDForQuery(query);
}
else if (db)
{
return db->GetInsertID();
}
else if (stmt)
{
return stmt->GetInsertID();
}
return pContext->ThrowNativeError("Unknown error reading db/stmt/query handles");
}
示例4: OnHandleDestroy
virtual void OnHandleDestroy(HandleType_t type, void *object)
{
if (type == hCombinedQueryType)
{
CombinedQuery *combined = (CombinedQuery *)object;
combined->query->Destroy();
delete combined;
} else if (type == hStmtType) {
IPreparedQuery *query = (IPreparedQuery *)object;
query->Destroy();
}
}
示例5: SQL_Execute
static cell_t SQL_Execute(IPluginContext *pContext, const cell_t *params)
{
IPreparedQuery *stmt;
HandleError err;
if ((err = ReadStmtHndl(params[1], pContext, &stmt)) != HandleError_None)
{
return pContext->ThrowNativeError("Invalid statement Handle %x (error: %d)", params[1], err);
}
return stmt->Execute() ? 1 : 0;
}
示例6: PrepareQueryEx
IQuery *SqDatabase::DoQueryEx(const char *query, size_t len)
{
IPreparedQuery *pQuery = PrepareQueryEx(query, len, NULL, 0, NULL);
if (!pQuery)
{
return NULL;
}
if (!pQuery->Execute())
{
pQuery->Destroy();
return NULL;
}
return pQuery;
}
示例7: SQL_BindParamFloat
static cell_t SQL_BindParamFloat(IPluginContext *pContext, const cell_t *params)
{
IPreparedQuery *stmt;
HandleError err;
if ((err = ReadStmtHndl(params[1], pContext, &stmt)) != HandleError_None)
{
return pContext->ThrowNativeError("Invalid statement Handle %x (error: %d)", params[1], err);
}
if (!stmt->BindParamFloat(params[2], sp_ctof(params[3])))
{
return pContext->ThrowNativeError("Could not bind parameter %d as a float", params[2]);
}
return 1;
}
示例8: SQL_BindParamString
static cell_t SQL_BindParamString(IPluginContext *pContext, const cell_t *params)
{
IPreparedQuery *stmt;
HandleError err;
if ((err = ReadStmtHndl(params[1], pContext, &stmt)) != HandleError_None)
{
return pContext->ThrowNativeError("Invalid statement Handle %x (error: %d)", params[1], err);
}
char *str;
pContext->LocalToString(params[3], &str);
if (!stmt->BindParamString(params[2], str, params[4] ? true : false))
{
return pContext->ThrowNativeError("Could not bind parameter %d as a string", params[2]);
}
return 1;
}