////////////////////////////////////////////////////////////////////////////////
// CppSQLite3 - A C++ wrapper around the SQLite3 embedded database library.
//
// Copyright (c) 2004..2007 Rob Groves. All Rights Reserved. rob.groves@btinternet.com
//
// Permission to use, copy, modify, and distribute this software and its
// documentation for any purpose, without fee, and without a written
// agreement, is hereby granted, provided that the above copyright notice,
// this paragraph and the following two paragraphs appear in all copies,
// modifications, and distributions.
//
// IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
// INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
// PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
// EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
// ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO OBLIGATION
// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
//
// V3.0 03/08/2004 -Initial Version for sqlite3
//
// V3.1 16/09/2004 -Implemented getXXXXField using sqlite3 functions
// -Added CppSQLiteDB3::tableExists()
//
// V3.2 01/07/2005 -Fixed execScalar to handle a NULL result
// 12/07/2007 -Added int64 functions to CppSQLite3Query
// -Throw exception from CppSQLite3DB::close() if error
// -Trap above exception in CppSQLite3DB::~CppSQLite3DB()
// -Fix to CppSQLite3DB::compile() as provided by Dave Rollins.
// -sqlite3_prepare replaced with sqlite3_prepare_v2
// -Added Name based parameter binding to CppSQLite3Statement.
////////////////////////////////////////////////////////////////////////////////
#include "CppSQLite3.h"
#include <cstdlib>
// Named constant for passing to CppSQLite3Exception when passing it a string
// that cannot be deleted.
static const bool DONT_DELETE_MSG=false;
////////////////////////////////////////////////////////////////////////////////
// Prototypes for SQLite functions not included in SQLite DLL, but copied below
// from SQLite encode.c
////////////////////////////////////////////////////////////////////////////////
int sqlite3_encode_binary(const unsigned char *in, int n, unsigned char *out);
int sqlite3_decode_binary(const unsigned char *in, unsigned char *out);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
CppSQLite3Exception::CppSQLite3Exception(const int nErrCode,
char* szErrMess,
bool bDeleteMsg/*=true*/) :
mnErrCode(nErrCode)
{
mpszErrMess = sqlite3_mprintf("%s[%d]: %s",
errorCodeAsString(nErrCode),
nErrCode,
szErrMess ? szErrMess : "");
if (bDeleteMsg && szErrMess)
{
sqlite3_free(szErrMess);
}
}
CppSQLite3Exception::CppSQLite3Exception(const CppSQLite3Exception& e) :
mnErrCode(e.mnErrCode)
{
mpszErrMess = 0;
if (e.mpszErrMess)
{
mpszErrMess = sqlite3_mprintf("%s", e.mpszErrMess);
}
}
const char* CppSQLite3Exception::errorCodeAsString(int nErrCode)
{
switch (nErrCode)
{
case SQLITE_OK : return "SQLITE_OK";
case SQLITE_ERROR : return "SQLITE_ERROR";
case SQLITE_INTERNAL : return "SQLITE_INTERNAL";
case SQLITE_PERM : return "SQLITE_PERM";
case SQLITE_ABORT : return "SQLITE_ABORT";
case SQLITE_BUSY : return "SQLITE_BUSY";
case SQLITE_LOCKED : return "SQLITE_LOCKED";
case SQLITE_NOMEM : return "SQLITE_NOMEM";
case SQLITE_READONLY : return "SQLITE_READONLY";
case SQLITE_INTERRUPT : return "SQLITE_INTERRUPT";
case SQLITE_IOERR : return "SQLITE_IOERR";
case SQLITE_CORRUPT : return "SQLITE_CORRUPT";
case SQLITE_NOTFOUND : return "SQLITE_NOTFOUND";
case SQLITE_FULL : return "SQLITE_FULL";
case SQLITE_CANTOPEN : return "SQLITE_CANTOPEN";
case SQLITE_PROTOCOL : return "SQLITE_PROTOCOL";
case SQLITE_EMPTY : return "SQLITE_EMPTY";
case SQLITE_SCHEMA : return "SQLITE_SCHEMA";
case SQLITE_TOOBIG : return "SQLITE_TOOBIG";
case SQLITE_CONSTRAINT : return "SQLITE_CONSTRAINT";
case SQLITE_MISMATCH : return "SQLITE_MISMATCH";
case SQLITE_MISUSE : return "SQLITE_MISUSE";
case SQLITE_NOLFS : return "SQLITE_NOLFS";
case SQLITE_AUTH : return "SQLITE_AUTH";
case SQLITE_FORMAT : return "SQLITE_FORMAT";
case SQLITE_RANGE : return "SQLITE_RANGE";
case SQLITE_ROW : return "SQLITE_ROW";
case SQLITE_DONE : return "SQLITE_DONE";
case CPPSQLITE_ERROR : return "CPPSQLITE_ERROR";
default: return "UNKNOWN_ERROR";
}
}
CppSQLite3Exception::~CppSQLite3Exception()
{
if (mpszErrMess)
{
sqlite3_free(mpszErrMess);
mpszErrMess = 0;
}
}
////////////////////////////////////////////////////////////////////////////////
CppSQLite3Buffer::CppSQLite3Buffer()
{
mpBuf = 0;
}
CppSQLite3Buffer::~CppSQLite3Buffer()
{
clear();
}
void CppSQLite3Buffer::clear()
{
if (mpBuf)
{
sqlite3_free(mpBuf);
mpBuf = 0;
}
}
const char* CppSQLite3Buffer::format(const char* szFormat, ...)
{
clear();
va_list va;
va_start(va, szFormat);
mpBuf = sqlite3_vmprintf(szFormat, va);
va_end(va);
return mpBuf;
}
////////////////////////////////////////////////////////////////////////////////
CppSQLite3Binary::CppSQLite3Binary() :
mpBuf(0),
mnBinaryLen(0),
mnBufferLen(0),
mnEncodedLen(0),
mbEncoded(false)
{
}
CppSQLite3Binary::~CppSQLite3Binary()
{
clear();
}
void CppSQLite3Binary::setBinary(const unsigned char* pBuf, int nLen)
{
mpBuf = allocBuffer(nLen);
memcpy(mpBuf, pBuf, nLen);
}
void CppSQLite3Binary::setEncoded(const unsigned char* pBuf)
{
clear();
mnEncodedLen = strlen((const char*)pBuf);
mnBufferLen = mnEncodedLen + 1; // Allow for NULL terminator
mpBuf = (unsigned char*)malloc(mnBufferLen);
if (!mpBuf)
{
throw CppSQLite3Exception(CPPSQLITE_ERROR,
"Cannot allocate memory",
DONT_DELETE_MSG);
}
memcpy(mpBuf, pBuf, mnBufferLen);
mbEncoded = true;
}
const unsigned char* CppSQLite3Binary::getEncoded()
{
if (!mbEncoded)
{
unsigned char* ptmp = (unsigned char*)malloc(mnBinaryLen);
memcpy(ptmp, mpBuf, mnBinaryLen);
mnEncodedLen = sqlite3_encode_binary(ptmp, mnBinaryLen, mpBuf);
free(ptmp);
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;
}
没有合适的资源?快使用搜索试试~ 我知道了~
sqlite3,c++封装类
5星 · 超过95%的资源 需积分: 14 231 下载量 24 浏览量
2015-09-01
13:59:28
上传
评论
收藏 252KB GZ 举报
温馨提示
共28个文件
cpp:7个
sln:4个
vcproj:4个
sqlite3官方推荐的c++封装类,其中接口简单,并有异常处理机制。资源里面附带Demo,亲测可用
资源推荐
资源详情
资源评论
收起资源包目录
sqlite3封装类.gz (28个子文件)
CppSQLiteDemo
CppSQLiteDemo.dsw 549B
CppSQLiteDemo.dsp 4KB
CppSQLiteDemo.vcproj 5KB
CppSQLiteDemo.sln 915B
CppSQLite3Demo.cpp 11KB
CppSQLiteDemoMT
CppSQLiteDemoMT.vcproj 5KB
CppSQLiteDemoMT.dsp 4KB
CppSQLiteDemoMT.sln 919B
CppSQLiteDemoMT.dsw 553B
CppSQLite3DemoMT.cpp 12KB
ManagedDemo
ManagedDemo.vcproj 4KB
ManagedDemo.cpp 10KB
stdafx.h 166B
stdafx.cpp 211B
AssemblyInfo.cpp 2KB
ManagedDemo.sln 911B
Common
sqlite3.h 115KB
sqlite3.dll 354KB
CppSQLite3.h 8KB
CppSQLite3.cpp 35KB
sqlite3.exp 14KB
sqlite3.def 2KB
sqlite3.lib 30KB
CppSQLiteDemoExt
CppSQLiteDemoExt.sln 921B
CppSQLiteDemoExt.dsw 555B
CppSQLiteDemoExt.vcproj 5KB
CppSQLiteDemoExt.dsp 4KB
CppSQLite3DemoExt.cpp 11KB
共 28 条
- 1
z526882183
- 粉丝: 16
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- yolov5,SSD 可能使用到的一些代码
- 基于c51单片机+DS1302+DHT11温湿度模块+LCD1602显示的万年历硬件原理图+BOM+软件程源码序+仿真图.zip
- NSGA2的MATLAB代码
- Messagepassingtest_GCN_DGL.py
- Sh,Docker 运维好帮手,一招通过 sh 脚本批量快速启动和重启多个Docker 容器
- PCF2123.pdf
- 打开注册表操作.doc
- Windows 常见运行运行库32+64
- WMJUL8iC.html
- 基于3KW光伏并网单相逆变器设计(TMS320F28035控制板+显示板+STM32F103功率板)硬件(原理图+PCB)工程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页