84 lines
1.2 KiB
C++
84 lines
1.2 KiB
C++
|
|
#include <stdlib.h>
|
|||
|
|
#include <stdio.h>
|
|||
|
|
|
|||
|
|
#ifdef WIN32
|
|||
|
|
#include <Windows.h>
|
|||
|
|
#include <tchar.h>
|
|||
|
|
|
|||
|
|
|
|||
|
|
#include <_ast.h>
|
|||
|
|
#include <_memchk.h>
|
|||
|
|
#include "sqlite3.h"
|
|||
|
|
#include "../include/SQLiteDB.h"
|
|||
|
|
|
|||
|
|
CSQLiteDB::CSQLiteDB()
|
|||
|
|
{
|
|||
|
|
m_pDB = NULL;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
CSQLiteDB::~CSQLiteDB()
|
|||
|
|
{
|
|||
|
|
close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int CSQLiteDB::copen(const char * sDBFile)
|
|||
|
|
{
|
|||
|
|
sqlite3 *pDB;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|||
|
|
int nErr = sqlite3_open(sDBFile, &pDB);
|
|||
|
|
return checkOpenResult(nErr, pDB);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int CSQLiteDB::wopen(const wchar_t * wsDBFile)
|
|||
|
|
{
|
|||
|
|
sqlite3 *pDB;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|||
|
|
int nErr = sqlite3_open16(wsDBFile, &pDB);
|
|||
|
|
return checkOpenResult(nErr, pDB);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CSQLiteDB::close()
|
|||
|
|
{
|
|||
|
|
if (m_pDB)
|
|||
|
|
{
|
|||
|
|
sqlite3_close(m_pDB);
|
|||
|
|
m_pDB = NULL;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
unsigned short CSQLiteDB::getPageSize()
|
|||
|
|
{
|
|||
|
|
if (!opened())
|
|||
|
|
return 0;
|
|||
|
|
CSQLiteStatement stmt(this, "PRAGMA page_size;");
|
|||
|
|
if (stmt.step())
|
|||
|
|
return stmt.val_int(0);
|
|||
|
|
else return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int CSQLiteDB::getErrorCode()
|
|||
|
|
{
|
|||
|
|
if (!opened())
|
|||
|
|
return 0;
|
|||
|
|
return sqlite3_errcode(m_pDB);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const wchar_t * CSQLiteDB::getErrorMessage()
|
|||
|
|
{
|
|||
|
|
if (!opened())
|
|||
|
|
return NULL;
|
|||
|
|
return (const wchar_t *)sqlite3_errmsg16(m_pDB);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int CSQLiteDB::checkOpenResult(int nErr, sqlite3 *pdb)
|
|||
|
|
{
|
|||
|
|
if (nErr == SQLITE_OK)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳɹ<DDB3><C9B9><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿⲢ<DDBF><E2B2A2><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD>
|
|||
|
|
close();
|
|||
|
|
m_pDB = pdb;
|
|||
|
|
}
|
|||
|
|
return nErr;
|
|||
|
|
}
|
|||
|
|
#endif
|