SQLite是一个老牌的轻量级别的文件数据库,完全免费,使用方便,不需要安装,无须任何配置,也不需要管理员;
下面Sqlite代码的封装是我用在ThumbMap中
#include "sqlite3.h"
class SQLITEENGINE_API CSqliteReader
{
public:
CSqliteReader(void);
~CSqliteReader(void);
public:
void SetSqliteStmt(sqlite3_stmt *pStmp, sqlite3 *pSqliteDB, BOOL bDeleteStmt = TRUE);
BOOL Read();
int GetFieldCount() const;
const WCHAR* FieldName(int nIndex) const;
int FieldDataType(int nIndex) const;
BOOL FieldIsNull(int nIndex) const;
ULONG GetULong(int nIndex);
long GetLong(int nIndex);
int GetInt(int nIndex);
LONG64 GetInt64(int nIndex);
double GetDouble(int nIndex);
float GetFloat(int nIndex);
const char* GetString(int nIndex);
const WCHAR* GetWString(int nIndex);
const BYTE* GetBlob(int nIndex, int& nLen);
private:
sqlite3_stmt *m_pStmp;
sqlite3 *m_pSqliteDB;
BOOL m_bDeleteStmt;
};
class SQLITEENGINE_API CStatementParam
{
public:
CStatementParam(void);
~CStatementParam(void);
public:
void SetSqliteStmt(sqlite3_stmt *pStmp, sqlite3 *pSqliteDB);
int GetParamCount() const;
BOOL Reset();
BOOL ExecuteReader(CSqliteReader &oReader);
int ExecuteNonQuery();
BOOL SetParam(int nIndex, long nParam);
BOOL SetParam(int nIndex, ULONG nParam);
BOOL SetParam(int nIndex, int nParam);
BOOL SetParam(int nIndex, LONG64 nParam);
BOOL SetParam(int nIndex, float fParam);
BOOL SetParam(int nIndex, double fParam);
BOOL SetParam(int nIndex, LPCWSTR lpcwParam);
BOOL SetParam(int nIndex, LPCSTR lpcsParam);
BOOL SetParam(int nIndex, const BYTE *pBlob, int nLen);
private:
sqlite3_stmt *m_pStmp;
sqlite3 *m_pSqliteDB;
};
class SQLITEENGINE_API CSqliteDB
{
public:
CSqliteDB(void);
~CSqliteDB(void);
public:
BOOL Open(LPCWSTR lpcwSqlite);
BOOL OpenRead(LPCWSTR lpcwSqlite);
BOOL Create(LPCWSTR lpcwSqlite);
void Close();
BOOL IsOpen() const;
//---------------------------------------------------
int ExecScalar(LPCWSTR szSQL);
BOOL TableExists(LPCWSTR szTable);
BOOL ExecuteReader(LPCWSTR szSQL, CSqliteReader &oReader);
BOOL StatementParam(LPCWSTR szSQL, CStatementParam &oStatementParam);
int ExecuteNonQuery(LPCWSTR szSQL);
sqlite3 *GetSqliteDB() const { return m_pSqliteDB; }
private:
sqlite3 *m_pSqliteDB;
};
#include "StdAfx.h"
#include "SqliteDB.h"
//-----------------------------------------------------------------------------------------------------
//
// class CSqliteReader
//
//------------