设为首页 加入收藏

TOP

C++使用Sqlite3,使用CppSQLite3的封装(五)
2016-04-27 17:25:21 】 浏览:2638
Tags:使用 Sqlite3 CppSQLite3 封装
mbEncoded = true; } return mpBuf; } const unsigned char* CppSQLite3Binary::getBinary() { if (mbEncoded) { // in/out buffers can be the same mnBinaryLen = sqlite3_decode_binary(mpBuf, mpBuf); if (mnBinaryLen == -1) { throw CppSQLite3Exception(CPPSQLITE_ERROR, "Cannot decode binary", DONT_DELETE_MSG); } mbEncoded = false; } return mpBuf; } int CppSQLite3Binary::getBinaryLength() { getBinary(); return mnBinaryLen; } unsigned char* CppSQLite3Binary::allocBuffer(int nLen) { clear(); // Allow extra space for encoded binary as per comments in // SQLite encode.c See bottom of this file for implementation // of SQLite functions use 3 instead of 2 just to be sure ;-) mnBinaryLen = nLen; mnBufferLen = 3 + (257*nLen)/254; mpBuf = (unsigned char*)malloc(mnBufferLen); if (!mpBuf) { throw CppSQLite3Exception(CPPSQLITE_ERROR, "Cannot allocate memory", DONT_DELETE_MSG); } mbEncoded = false; return mpBuf; } void CppSQLite3Binary::clear() { if (mpBuf) { mnBinaryLen = 0; mnBufferLen = 0; free(mpBuf); mpBuf = 0; } } //////////////////////////////////////////////////////////////////////////////// CppSQLite3Query::CppSQLite3Query() { mpVM = 0; mbEof = true; mnCols = 0; mbOwnVM = false; } CppSQLite3Query::CppSQLite3Query(const CppSQLite3Query& rQuery) { mpVM = rQuery.mpVM; // Only one object can own the VM const_cast (rQuery).mpVM = 0; mbEof = rQuery.mbEof; mnCols = rQuery.mnCols; mbOwnVM = rQuery.mbOwnVM; } CppSQLite3Query::CppSQLite3Query(sqlite3* pDB, sqlite3_stmt* pVM, bool bEof, bool bOwnVM/*=true*/) { mpDB = pDB; mpVM = pVM; mbEof = bEof; mnCols = sqlite3_column_count(mpVM); mbOwnVM = bOwnVM; } CppSQLite3Query::~CppSQLite3Query() { try { finalize(); } catch (...) { } } CppSQLite3Query& CppSQLite3Query::operator=(const CppSQLite3Query& rQuery) { try { finalize(); } catch (...) { } mpVM = rQuery.mpVM; // Only one object can own the VM const_cast (rQuery).mpVM = 0; mbEof = rQuery.mbEof; mnCols = rQuery.mnCols; mbOwnVM = rQuery.mbOwnVM; return *this; } int CppSQLite3Query::numFields() { checkVM(); return mnCols; } const char* CppSQLite3Query::fieldValue(int nField) { checkVM(); if (nField < 0 || nField > mnCols-1) { throw CppSQLite3Exception(CPPSQLITE_ERROR, "Invalid field index requested", DONT_DELETE_MSG); } return (const char*)sqlite3_column_text(mpVM, nField); } const char* CppSQLite3Query::fieldValue(const char* szField) { int nField = fieldIndex(szField); return (const char*)sqlite3_column_text(mpVM, nField); } int CppSQLite3Query::getIntField(int nField, int nNullValue/*=0*/) { if (fieldDataType(nField) == SQLITE_NULL) { return nNullValue; } else { return sqlite3_column_int(mpVM, nField); } } int CppSQLite3Query::getIntField(const char* szField, int nNullValue/*=0*/) { int nField = fieldIndex(szField); return getIntField(nField, nNullValue); } sqlite_int64 CppSQLite3Query::getInt64Field(int nField, sqlite_int64 nNullValue/*=0*/) { if (fieldDataType(nField) == SQLITE_NULL) { return nNullValue; } else { return sqlite3_column_int64(mpVM, nField); } } sqlite_int64 CppSQLite3Query::getInt64Field(const char* szField, sqlite_int64 nNullValue/*=0*/) { int nField = fieldIndex(szField); return getInt64Field(nField, nNullValue); } double CppSQLite3Query::getFloatField(int nField, double fNullValue/*=0.0*/) { if (fieldDataType(nField) == SQLITE_NULL) { return fNullValue; } else { return sqlite3_column_double(mpVM, nField); } } double CppSQLite3Query::getFloatField(const char* s
首页 上一页 2 3 4 5 6 7 8 下一页 尾页 5/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++11新特性 下一篇c++内存管理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目