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; }
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(); } }
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; }