本文整理汇总了C++中CppSQLite3Statement::bind方法的典型用法代码示例。如果您正苦于以下问题:C++ CppSQLite3Statement::bind方法的具体用法?C++ CppSQLite3Statement::bind怎么用?C++ CppSQLite3Statement::bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CppSQLite3Statement
的用法示例。
在下文中一共展示了CppSQLite3Statement::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runCreateStatements
void BaseDatabaseUnitImpl::runCreateStatements()
{
loadDatabaseInfo();
if (database_)
{
try
{
uint32_t version = databaseInfo_->latest_.version_;
for (auto it = databaseInfo_->latest_.tableList_.begin(); it != databaseInfo_->latest_.tableList_.end(); ++it)
{
CppSQLite3Statement statement = database_->compileStatement(it->statement_.c_str());
runTransaction(statement);
}
CppSQLite3Statement statement = database_->compileStatement(SQL_VERSION_TABLE_CREATE);
runTransaction(statement);
statement = database_->compileStatement(SQL_VERSION_TABLE_SET_VERSION);
statement.bind(1, VERSION_KEY);
statement.bind(2, (int)version);
runTransaction(statement);
runUpdateStatements();
}
catch (CppSQLite3Exception e)
{
LOG_ERR_R(DATABASE_MANAGER_LOG_TAG, _T("Failed to run create statements, error: %u"), e.errorCode());
LOG_ERR_D_A(DATABASE_MANAGER_LOG_TAG_A, "Message: %s", e.errorMessage());
}
}
}
示例2: sqlInsertRecentSessionInfoEntity
BOOL DatabaseModule_Impl::sqlInsertRecentSessionInfoEntity(IN const module::SessionEntity& sessionInfo)
{
try
{
CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(insertRecentSessionSql.c_str());
stmt.bind(1, sessionInfo.sessionID.c_str());
stmt.bind(2, int(sessionInfo.sessionType));
stmt.bind(3, int(sessionInfo.updatedTime));
stmt.bind(4, int(sessionInfo.latestmsgId));
stmt.bind(5, sessionInfo.latestMsgContent.c_str());
stmt.bind(6, sessionInfo.latestMsgFromId.c_str());
if (0 == stmt.execDML())
{
return FALSE;
}
}
catch (CppSQLite3Exception& sqliteException)
{
#ifdef _DEBUG
MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
LOG__(ERR, _T("insert failed,error msg:%s"), csErrMsg);
return FALSE;
}
catch (...)
{
LOG__(ERR, _T("db unknown exception"));
return FALSE;
}
return TRUE;
}
示例3: ExportToSqliteDB
//##ModelId=474D30760272
bool CClip_ImportExport::ExportToSqliteDB(CppSQLite3DB &db)
{
bool bRet = false;
try
{
//Add to Main Table
m_Desc.Replace(_T("'"), _T("''"));
db.execDMLEx(_T("insert into Main values(NULL, %d, '%s');"), CURRENT_EXPORT_VERSION, m_Desc);
long lId = (long)db.lastRowId();
//Add to Data table
CClipFormat* pCF;
CppSQLite3Statement stmt = db.compileStatement(_T("insert into Data values (NULL, ?, ?, ?, ?);"));
for(int i = m_Formats.GetSize()-1; i >= 0 ; i--)
{
pCF = & m_Formats.ElementAt(i);
stmt.bind(1, lId);
stmt.bind(2, GetFormatName(pCF->m_cfType));
long lOriginalSize = GlobalSize(pCF->m_hgData);
stmt.bind(3, lOriginalSize);
const unsigned char *Data = (const unsigned char *)GlobalLock(pCF->m_hgData);
if(Data)
{
//First compress the data
long lZippedSize = compressBound(lOriginalSize);
Bytef *pZipped = new Bytef[lZippedSize];
if(pZipped)
{
int nZipReturn = compress(pZipped, (uLongf *)&lZippedSize, (const Bytef *)Data, lOriginalSize);
if(nZipReturn == Z_OK)
{
stmt.bind(4, pZipped, lZippedSize);
}
delete []pZipped;
pZipped = NULL;
}
}
GlobalUnlock(pCF->m_hgData);
stmt.execDML();
stmt.reset();
m_Formats.RemoveAt(i);
}
bRet = true;
}
CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
return bRet;
}
示例4: sqlInsertOrReplaceGroupInfoEntity
BOOL DatabaseModule_Impl::sqlInsertOrReplaceGroupInfoEntity(IN const module::GroupInfoEntity& groupInfo)
{
try
{
CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(insertGroupInfoSql.c_str());
stmt.bind(1, groupInfo.gId.c_str());
stmt.bind(2, util::cStringToString(groupInfo.csName).c_str());
stmt.bind(3, util::cStringToString(groupInfo.desc).c_str());
stmt.bind(4, groupInfo.avatarUrl.c_str());
stmt.bind(5, groupInfo.creatorId.c_str());
stmt.bind(6, int(groupInfo.type));
stmt.bind(7, int(groupInfo.version));
stmt.bind(8, int(groupInfo.groupUpdated));
stmt.bind(9, int(groupInfo.shieldStatus));
std::string& strJson = _makeJsonForGroupMembers(groupInfo.groupMemeberList);
stmt.bind(10, strJson.c_str());
stmt.execDML();
}
catch (CppSQLite3Exception& sqliteException)
{
#ifdef _DEBUG
MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
LOG__(ERR, _T("insert failed,error msg:%s"), csErrMsg);
return FALSE;
}
catch (...)
{
LOG__(ERR, _T("db unknown exception"));
return FALSE;
}
return TRUE;
}
示例5: values
void CBrainMemory::SetSystemItem(int64 Item,AnsiString Info){
CppSQLite3Buffer SQL;
CppSQLite3Query Result;
char a[30],b[30];
int64toa(ROOM_SYSTEM,a);
int64toa(Item,b);
SQL.format("select b from \"%s\" where a = \"%s\";",a,b);
Result = BrainDB.execQuery(SQL);
bool Find = !Result.eof();
Result.finalize();
if(!Find){
SQL.format("insert into \"%s\" values (\"%s\", ?)",
a,
b);
}else{
SQL.format("update \"%s\" set b = ? where a = \"%s\";",
a,
b
);
}
CppSQLite3Statement State = BrainDB.compileStatement(SQL);
State.bind(1,Info.c_str()); //替换第一个问号
State.execDML();
}
示例6: sqlDeleteGroupInfoEntity
BOOL DatabaseModule_Impl::sqlDeleteGroupInfoEntity(IN const std::string& groupId)
{
try
{
CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(deleteGroupInfoSql.c_str());
stmt.bind(1, groupId.c_str());
stmt.execDML();
}
catch (CppSQLite3Exception& sqliteException)
{
#ifdef _DEBUG
MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
LOG__(ERR, _T("delete failed,error msg:%s"), csErrMsg);
return FALSE;
}
catch (...)
{
LOG__(ERR, _T("db unknown exception"));
return FALSE;
}
return TRUE;
}
示例7: compileStatement
int CppSQLite3DB::insertBlob(const CString& szSQL, const unsigned char *data, int dataLength)
{
CppSQLite3Statement statement = compileStatement(szSQL);
statement.bind(1, data, dataLength);
return statement.execDML();
}
示例8: runUpdateStatements
void BaseDatabaseUnitImpl::runUpdateStatements()
{
loadDatabaseInfo();
if (database_)
{
uint32_t version = getDatabaseVersion();
if (version > 0)
{
auto it = databaseInfo_->updateMap_.find(boost::lexical_cast<std::string>(version + 1));
if (it != databaseInfo_->updateMap_.end())
{
try
{
for (it; it != databaseInfo_->updateMap_.end(); ++it)
{
for (auto it2 = it->second.tableList_.begin(); it2 != it->second.tableList_.end(); ++it2)
{
CppSQLite3Statement statement = database_->compileStatement(it2->statement_.c_str());
runTransaction(statement);
}
try
{
version = boost::lexical_cast<uint32_t>(it->first);
}
catch (...)
{
}
}
CppSQLite3Statement statement = database_->compileStatement(SQL_VERSION_TABLE_SET_VERSION);
statement.bind(1, VERSION_KEY);
statement.bind(2, (int)version);
runTransaction(statement);
}
catch (CppSQLite3Exception e)
{
LOG_ERR_R(DATABASE_MANAGER_LOG_TAG, _T("Failed to run update statements, error: %u"), e.errorCode());
LOG_ERR_D_A(DATABASE_MANAGER_LOG_TAG_A, "Message: %s", e.errorMessage());
}
}
}
}
}
示例9: CString
int CppSQLite3DB::updateBlob(const CString& szTableName, const CString& szFieldName, const unsigned char* data, int dataLength, const CString& szWhere)
{
CString sql = CString("update ") + szTableName + " set " + szFieldName + "=? where " + szWhere;
CppSQLite3Statement statement = compileStatement(sql);
statement.bind(1, data, dataLength);
return statement.execDML();
}
示例10: sqlInsertFileTransferHistory
BOOL DatabaseModule_Impl::sqlInsertFileTransferHistory(IN TransferFileEntity& fileInfo)
{
if (fileInfo.nClientMode == IM::BaseDefine::ClientFileRole::CLIENT_OFFLINE_UPLOAD
|| fileInfo.nClientMode == IM::BaseDefine::ClientFileRole::CLIENT_REALTIME_SENDER)
{
LOG__(DEBG, _T("fileInfo.nClientMode not fixed"));
return FALSE;
}
try
{
CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(insertFileTransferHistorySql.c_str());
stmt.bind(1, fileInfo.sTaskID.c_str());
stmt.bind(2, fileInfo.sFromID.c_str());
std::string filename = util::cStringToString(fileInfo.getRealFileName());
stmt.bind(3, filename.c_str());
std::string savePath = util::cStringToString(fileInfo.getSaveFilePath());
stmt.bind(7, savePath.c_str());
stmt.bind(8, (Int32)fileInfo.nFileSize);
stmt.bind(9, time(0));
stmt.execDML();
}
catch (CppSQLite3Exception& sqliteException)
{
#ifdef _DEBUG
MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
LOG__(ERR, _T("failed,error msg:%s"), csErrMsg);
return FALSE;
}
catch (...)
{
LOG__(ERR, _T("unknown exception"));
return FALSE;
}
return TRUE;
}
示例11: Delete
/** 해당 ID에 대한 전체 Message 삭제
*/
BOOL CMessageHelper::Delete(const char *szId, BYTE nMessageType)
{
if(!CheckDB()) return FALSE;
if(!Open()) return FALSE;
try
{
CppSQLite3Statement stmt;
if(nMessageType > 0)
{
stmt = m_SqliteHelper.compileStatement(
"DELETE FROM MessageTbl "
"WHERE targetId = ? AND messageType = ? ; ");
stmt.bind(1, szId);
stmt.bind(2, nMessageType);
} else {
stmt = m_SqliteHelper.compileStatement(
"DELETE FROM MessageTbl "
"WHERE targetId = ?; ");
stmt.bind(1, szId);
}
stmt.execDML();
stmt.finalize();
Close();
}
catch ( CppSQLite3Exception& e )
{
Close();
XDEBUG(ANSI_COLOR_RED "DB ERROR DELETE: %d %s\r\n" ANSI_NORMAL, e.errorCode(), e.errorMessage());
return FALSE;
}
return TRUE;
}
示例12: sqlBatchInsertRecentSessionInfos
BOOL DatabaseModule_Impl::sqlBatchInsertRecentSessionInfos(IN std::vector<module::SessionEntity>& sessionList)
{
try
{
CppSQLite3Statement stmtBegin = m_pSqliteDB->compileStatement(BeginInsert.c_str());
stmtBegin.execDML();
for (module::SessionEntity sessionInfo : sessionList)
{
CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(insertRecentSessionSql.c_str());
stmt.bind(1, sessionInfo.sessionID.c_str());
stmt.bind(2, int(sessionInfo.sessionType));
stmt.bind(3, int(sessionInfo.updatedTime));
stmt.bind(4, int(sessionInfo.latestmsgId));
stmt.bind(5, sessionInfo.latestMsgContent.c_str());
stmt.bind(6, sessionInfo.latestMsgFromId.c_str());
stmt.execDML();
}
CppSQLite3Statement stmtEnd = m_pSqliteDB->compileStatement(EndInsert.c_str());
stmtEnd.execDML();
}
catch (CppSQLite3Exception& e)
{
CString csErrMsg = util::stringToCString(e.errorMessage());
LOG__(ERR, _T("batch insert failed,error msg:%s"), csErrMsg);
CppSQLite3Statement stmtRollback = m_pSqliteDB->compileStatement(RollBack.c_str());
stmtRollback.execDML();
return FALSE;
}
catch (...)
{
LOG__(ERR, _T("batch insert unknown exception"));
return FALSE;
}
return TRUE;
}
示例13: sqlBatchInsertGroupInfos
BOOL DatabaseModule_Impl::sqlBatchInsertGroupInfos(IN module::GroupInfoMap& mapGroupInfos)
{
try
{
CppSQLite3Statement stmtBegin = m_pSqliteDB->compileStatement(BeginInsert.c_str());
stmtBegin.execDML();
for (auto kv : mapGroupInfos)
{
module::GroupInfoEntity& groupInfo = kv.second;
CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(insertGroupInfoSql.c_str());
stmt.bind(1, groupInfo.gId.c_str());
stmt.bind(2, util::cStringToString(groupInfo.csName).c_str());
stmt.bind(3, util::cStringToString(groupInfo.desc).c_str());
stmt.bind(4, groupInfo.avatarUrl.c_str());
stmt.bind(5, groupInfo.creatorId.c_str());
stmt.bind(6, int(groupInfo.type));
stmt.bind(7, int(groupInfo.version));
stmt.bind(8, int(groupInfo.groupUpdated));
stmt.bind(9, int(groupInfo.shieldStatus));
std::string& strJson = _makeJsonForGroupMembers(groupInfo.groupMemeberList);
stmt.bind(10, strJson.c_str());
stmt.execDML();
}
CppSQLite3Statement stmtEnd = m_pSqliteDB->compileStatement(EndInsert.c_str());
stmtEnd.execDML();
}
catch (CppSQLite3Exception& e)
{
CString csErrMsg = util::stringToCString(e.errorMessage());
LOG__(ERR, _T("batch insert failed,error msg:%s"), csErrMsg);
CppSQLite3Statement stmtRollback = m_pSqliteDB->compileStatement(RollBack.c_str());
stmtRollback.execDML();
return FALSE;
}
catch (...)
{
LOG__(ERR, _T("batch insert unknown exception"));
return FALSE;
}
return TRUE;
}
示例14: sqlGetGroupInfoByGId
BOOL DatabaseModule_Impl::sqlGetGroupInfoByGId(IN std::string& gId, OUT module::GroupInfoEntity& groupInfo)
{
try
{
CppSQLite3Statement stmt;
stmt = m_pSqliteDB->compileStatement(getGroupInfoByGIdSql.c_str());
stmt.bind(1, gId.c_str());
CppSQLite3Query query = stmt.execQuery();
if (!query.eof())
{
groupInfo.gId = gId;
groupInfo.csName = util::stringToCString(query.getStringField(2));
groupInfo.desc = util::stringToCString(query.getStringField(3));
groupInfo.avatarUrl = query.getStringField(4);
groupInfo.creatorId = query.getStringField(5);
groupInfo.type = query.getIntField(6);
groupInfo.version = query.getIntField(7);
groupInfo.groupUpdated = query.getIntField(8);
groupInfo.shieldStatus = query.getIntField(9);
_parseJsonForGroupMembers(query.getStringField(10), groupInfo.groupMemeberList);
}
else
{
return FALSE;
}
}
catch (CppSQLite3Exception& sqliteException)
{
#ifdef _DEBUG
MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
LOG__(ERR, _T("db failed,error msg:%s"),
csErrMsg);
return FALSE;
}
catch (...)
{
LOG__(ERR, _T("db unknown exception"));
return FALSE;
}
return TRUE;
}
示例15: Add
/** Message Queuing.
*
* @param szId Sensor ID
* @param nMessageId 사용자 정의 Message ID
* @param nMessageType Message Type (0x01 Immediately, 0x02 Lazy, 0x03 Passive)
* @param nDuration Lazy, Passive 일 경우 유지 시간(sec)
* @param nErrorHandler Error Handler
* @param nPreHandler Pre-Action Handler
* @param nPostHandler Post-Action Handler
* @param nUserData User Data
* @param nDataLength Message length
* @param pszData Message
*
*/
BOOL CMessageHelper::Add(const char *szId, UINT nMessageId, BYTE nMessageType, UINT nDuration,
UINT nErrorHandler, UINT nPreHandler, UINT nPostHandler, UINT nUserData, int nDataLength, const BYTE *pszData)
{
int i=1;
if(!CheckDB()) return FALSE;
if(!Open()) return FALSE;
try
{
CppSQLite3Statement stmt = m_SqliteHelper.compileStatement(
"INSERT INTO MessageTbl "
"( targetId, messageId, messageType, duration, "
" errorHandler, preHandler, postHandler, userData, payload ) "
"VALUES "
"( ?, ?, ?, ?, "
" ?, ?, ?, ?, ?);");
stmt.bind(i, szId); i++;
stmt.bind(i, (const int)nMessageId); i++;
stmt.bind(i, nMessageType); i++;
stmt.bind(i, (const int)nDuration); i++;
stmt.bind(i, (const int)nErrorHandler); i++;
stmt.bind(i, (const int)nPreHandler); i++;
stmt.bind(i, (const int)nPostHandler); i++;
stmt.bind(i, (const int)nUserData); i++;
stmt.bind(i, pszData, nDataLength); i++;
stmt.execDML();
stmt.finalize();
Close();
return TRUE;
}
catch ( CppSQLite3Exception& e )
{
Close();
XDEBUG(ANSI_COLOR_RED "DB ERROR: %d %s\r\n" ANSI_NORMAL, e.errorCode(), e.errorMessage());
}
return FALSE;
}