设为首页 加入收藏

TOP

C++使用Sqlite3,使用CppSQLite3的封装(八)
2016-04-27 17:25:21 】 浏览:2643
Tags:使用 Sqlite3 CppSQLite3 封装
ow CppSQLite3Exception(nRes, "Error binding string param", DONT_DELETE_MSG); } } void CppSQLite3Statement::bind(int nParam, const int nValue) { checkVM(); int nRes = sqlite3_bind_int(mpVM, nParam, nValue); if (nRes != SQLITE_OK) { throw CppSQLite3Exception(nRes, "Error binding int param", DONT_DELETE_MSG); } } void CppSQLite3Statement::bind(int nParam, const double dValue) { checkVM(); int nRes = sqlite3_bind_double(mpVM, nParam, dValue); if (nRes != SQLITE_OK) { throw CppSQLite3Exception(nRes, "Error binding double param", DONT_DELETE_MSG); } } void CppSQLite3Statement::bind(int nParam, const unsigned char* blobValue, int nLen) { checkVM(); int nRes = sqlite3_bind_blob(mpVM, nParam, (const void*)blobValue, nLen, SQLITE_TRANSIENT); if (nRes != SQLITE_OK) { throw CppSQLite3Exception(nRes, "Error binding blob param", DONT_DELETE_MSG); } } void CppSQLite3Statement::bindNull(int nParam) { checkVM(); int nRes = sqlite3_bind_null(mpVM, nParam); if (nRes != SQLITE_OK) { throw CppSQLite3Exception(nRes, "Error binding NULL param", DONT_DELETE_MSG); } } int CppSQLite3Statement::bindParameterIndex(const char* szParam) { checkVM(); int nParam = sqlite3_bind_parameter_index(mpVM, szParam); int nn = sqlite3_bind_parameter_count(mpVM); const char* sz1 = sqlite3_bind_parameter_name(mpVM, 1); const char* sz2 = sqlite3_bind_parameter_name(mpVM, 2); if (!nParam) { char buf[128]; sprintf(buf, "Parameter '%s' is not valid for this statement", szParam); throw CppSQLite3Exception(CPPSQLITE_ERROR, buf, DONT_DELETE_MSG); } return nParam; } void CppSQLite3Statement::bind(const char* szParam, const char* szValue) { int nParam = bindParameterIndex(szParam); bind(nParam, szValue); } void CppSQLite3Statement::bind(const char* szParam, const int nValue) { int nParam = bindParameterIndex(szParam); bind(nParam, nValue); } void CppSQLite3Statement::bind(const char* szParam, const double dwValue) { int nParam = bindParameterIndex(szParam); bind(nParam, dwValue); } void CppSQLite3Statement::bind(const char* szParam, const unsigned char* blobValue, int nLen) { int nParam = bindParameterIndex(szParam); bind(nParam, blobValue, nLen); } void CppSQLite3Statement::bindNull(const char* szParam) { int nParam = bindParameterIndex(szParam); bindNull(nParam); } void CppSQLite3Statement::reset() { if (mpVM) { int nRet = sqlite3_reset(mpVM); if (nRet != SQLITE_OK) { const char* szError = sqlite3_errmsg(mpDB); throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG); } } } void CppSQLite3Statement::finalize() { if (mpVM) { int nRet = sqlite3_finalize(mpVM); mpVM = 0; if (nRet != SQLITE_OK) { const char* szError = sqlite3_errmsg(mpDB); throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG); } } } void CppSQLite3Statement::checkDB() { if (mpDB == 0) { throw CppSQLite3Exception(CPPSQLITE_ERROR, "Database not open", DONT_DELETE_MSG); } } void CppSQLite3Statement::checkVM() { if (mpVM == 0) { throw CppSQLite3Exception(CPPSQLITE_ERROR, "Null Virtual Machine pointer", DONT_DELETE_MSG); } } //////////////////////////////////////////////////////////////////////////////// CppSQLite3DB::CppSQLite3DB() { mpDB = 0; mnBusyTimeoutMs = 60000; // 60 seconds } CppSQLite3DB::CppSQLite3DB(const CppSQLite3DB& db) { mpDB = db.mpDB; mnBusyTimeoutMs = 60000; // 60 seconds } CppSQLite3DB::~CppSQLite3DB() { try { close(); } catch (...) { } } CppSQLite3DB& CppSQLite3DB::ope
首页 上一页 5 6 7 8 9 10 下一页 尾页 8/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++11新特性 下一篇c++内存管理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目