本文整理汇总了C++中IDatabase类的典型用法代码示例。如果您正苦于以下问题:C++ IDatabase类的具体用法?C++ IDatabase怎么用?C++ IDatabase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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_Connect
static cell_t SQL_Connect(IPluginContext *pContext, const cell_t *params)
{
char *conf, *err;
size_t maxlength = (size_t)params[4];
bool persistent = params[2] ? true : false;
pContext->LocalToString(params[1], &conf);
pContext->LocalToString(params[3], &err);
IDBDriver *driver;
IDatabase *db;
if (!g_DBMan.Connect(conf, &driver, &db, persistent, err, maxlength))
{
return BAD_HANDLE;
}
Handle_t hndl = g_DBMan.CreateHandle(DBHandle_Database, db, pContext->GetIdentity());
if (!hndl)
{
db->Close();
return BAD_HANDLE;
}
/* HACK! Add us to the dependency list */
CExtension *pExt = g_Extensions.GetExtensionFromIdent(driver->GetIdentity());
if (pExt)
{
g_Extensions.BindChildPlugin(pExt, g_PluginSys.GetPluginByCtx(pContext->GetContext()));
}
return hndl;
}
示例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: 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;
}
示例5: SQL_QuoteString
static cell_t SQL_QuoteString(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 *input, *output;
size_t maxlength = (size_t)params[4];
pContext->LocalToString(params[2], &input);
pContext->LocalToString(params[3], &output);
size_t written;
bool s = db->QuoteString(input, output, maxlength, &written);
cell_t *addr;
pContext->LocalToPhysAddr(params[5], &addr);
*addr = (cell_t)written;
return s ? 1 : 0;
}
示例6: SQL_QuoteStringFmt
static cell AMX_NATIVE_CALL SQL_QuoteStringFmt(AMX *amx, cell *params)
{
int len;
char *str = MF_FormatAmxString(amx, params, 4, &len);
size_t newsize;
static char buffer[8192];
if (params[1] != 0)
{
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
if (!pDb)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid database handle: %d", params[1]);
return 0;
}
if (pDb->QuoteString(str, buffer, sizeof(buffer)-1, &newsize) == 0)
{
MF_SetAmxString(amx, params[2], buffer, params[3]);
return newsize;
} else {
return -1;
}
} else {
if (g_Mysql.QuoteString(str, buffer, sizeof(buffer)-1, &newsize) == 0)
{
MF_SetAmxString(amx, params[2], buffer, params[3]);
return newsize;
} else {
return -1;
}
}
}
示例7: SQL_SetCharset
static cell AMX_NATIVE_CALL SQL_SetCharset(AMX *amx, cell *params)
{
SQL_Connection *sql = (SQL_Connection *)GetHandle(params[1], Handle_Connection);
if (!sql)
{
IDatabase *pDb = (IDatabase *)GetHandle(params[1], Handle_Database);
if (!pDb)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid info tuple or database handle: %d", params[1]);
return 0;
}
int len;
return pDb->SetCharacterSet(MF_GetAmxString(amx, params[2], 0, &len));
}
else
{
int len;
const char *charset = MF_GetAmxString(amx, params[2], 0, &len);
if (!sql->charset || stricmp(charset, sql->charset))
{
sql->charset = strdup(charset);
}
return 1;
}
return 0;
}
示例8: memset
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;
}
}
示例9: attachSystemTablesLocal
void attachSystemTablesLocal(IDatabase & system_database)
{
system_database.attachTable("one", StorageSystemOne::create("one"));
system_database.attachTable("numbers", StorageSystemNumbers::create("numbers", false));
system_database.attachTable("numbers_mt", StorageSystemNumbers::create("numbers_mt", true));
system_database.attachTable("databases", StorageSystemDatabases::create("databases"));
system_database.attachTable("tables", StorageSystemTables::create("tables"));
system_database.attachTable("columns", StorageSystemColumns::create("columns"));
system_database.attachTable("functions", StorageSystemFunctions::create("functions"));
system_database.attachTable("events", StorageSystemEvents::create("events"));
system_database.attachTable("settings", StorageSystemSettings::create("settings"));
system_database.attachTable("build_options", StorageSystemBuildOptions::create("build_options"));
}
示例10: SQL_ExecuteTransaction
static cell_t SQL_ExecuteTransaction(IPluginContext *pContext, const cell_t *params)
{
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
IDatabase *db = NULL;
HandleError err = g_DBMan.ReadHandle(params[1], DBHandle_Database, (void **)&db);
if (err != HandleError_None)
return pContext->ThrowNativeError("Invalid database handle %x (error: %d)", params[1], err);
Transaction *txn;
if ((err = handlesys->ReadHandle(params[2], hTransactionType, &sec, (void **)&txn)) != HandleError_None)
return pContext->ThrowNativeError("Invalid transaction handle %x (error %d)", params[2], err);
if (!db->GetDriver()->IsThreadSafe())
return pContext->ThrowNativeError("Driver \"%s\" is not thread safe!", db->GetDriver()->GetIdentifier());
IPluginFunction *onSuccess = NULL;
IPluginFunction *onError = NULL;
if (params[3] != -1 && ((onSuccess = pContext->GetFunctionById(params[3])) == NULL))
return pContext->ThrowNativeError("Function id %x is invalid", params[3]);
if (params[4] != -1 && ((onError = pContext->GetFunctionById(params[4])) == NULL))
return pContext->ThrowNativeError("Function id %x is invalid", params[4]);
cell_t data = params[5];
PrioQueueLevel priority = PrioQueue_Normal;
if (params[6] == (cell_t)PrioQueue_High)
priority = PrioQueue_High;
else if (params[6] == (cell_t)PrioQueue_Low)
priority = PrioQueue_Low;
TTransactOp *op = new TTransactOp(db, txn, params[2], pContext->GetIdentity(), onSuccess, onError, data);
// The handle owns the underlying Transaction object, but we want to close
// the plugin's view both to ensure reliable access for us and to prevent
// further tampering on the main thread. To do this, TTransactOp clones the
// transaction handle and automatically closes it. Therefore, it's safe to
// close the plugin's handle here.
handlesys->FreeHandle(params[2], &sec);
IPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext());
if (pPlugin->GetProperty("DisallowDBThreads", NULL) || !g_DBMan.AddToThreadQueue(op, priority))
{
// Do everything right now.
op->RunThreadPart();
op->RunThinkPart();
op->Destroy();
}
return 0;
}
示例11: OnHandleDestroy
void DBManager::OnHandleDestroy(HandleType_t type, void *object)
{
if (type == m_DriverType)
{
/* Ignore */
return;
}
if (g_HandleSys.TypeCheck(type, m_DatabaseType))
{
IDatabase *pdb = (IDatabase *)object;
pdb->Close();
}
}
示例12: SQL_UnlockDatabase
static cell_t SQL_UnlockDatabase(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);
}
db->UnlockFromFullAtomicOperation();
return 1;
}
示例13: SQL_TQuery
static cell_t SQL_TQuery(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);
}
if (!db->GetDriver()->IsThreadSafe())
{
return pContext->ThrowNativeError("Driver \"%s\" is not thread safe!", db->GetDriver()->GetIdentifier());
}
IPluginFunction *pf = pContext->GetFunctionById(params[2]);
if (!pf)
{
return pContext->ThrowNativeError("Function id %x is invalid", params[2]);
}
char *query;
pContext->LocalToString(params[3], &query);
cell_t data = params[4];
PrioQueueLevel level = PrioQueue_Normal;
if (params[5] == (cell_t)PrioQueue_High)
{
level = PrioQueue_High;
} else if (params[5] == (cell_t)PrioQueue_Low) {
level = PrioQueue_Low;
}
CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
TQueryOp *op = new TQueryOp(db, pf, query, data);
if (pPlugin->GetProperty("DisallowDBThreads", NULL)
|| !g_DBMan.AddToThreadQueue(op, level))
{
/* Do everything right now */
op->RunThreadPart();
op->RunThinkPart();
op->Destroy();
}
return 1;
}
示例14: attachSystemTablesServer
void attachSystemTablesServer(IDatabase & system_database, bool has_zookeeper)
{
attachSystemTablesLocal(system_database);
system_database.attachTable("parts", StorageSystemParts::create("parts"));
system_database.attachTable("processes", StorageSystemProcesses::create("processes"));
system_database.attachTable("metrics", StorageSystemMetrics::create("metrics"));
system_database.attachTable("merges", StorageSystemMerges::create("merges"));
system_database.attachTable("replicas", StorageSystemReplicas::create("replicas"));
system_database.attachTable("replication_queue", StorageSystemReplicationQueue::create("replication_queue"));
system_database.attachTable("dictionaries", StorageSystemDictionaries::create("dictionaries"));
system_database.attachTable("clusters", StorageSystemClusters::create("clusters"));
system_database.attachTable("graphite_retentions", StorageSystemGraphite::create("graphite_retentions"));
if (has_zookeeper)
system_database.attachTable("zookeeper", StorageSystemZooKeeper::create("zookeeper"));
}
示例15: SQL_SetCharset
static cell_t SQL_SetCharset(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 *characterset;
pContext->LocalToString(params[2], &characterset);
return db->SetCharacterSet(characterset);
}