-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLite.h
97 lines (72 loc) · 2.26 KB
/
SQLite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "sqlite3.h"
#include <string>
#include <vector>
namespace SQLite
{
//////////////////////////////////////////////////////////////////////////
// Typedefs
//////////////////////////////////////////////////////////////////////////
// I use this one for a sequential array in memory,
// So I can write directly to it
typedef std::vector<char> stdvstring;
typedef std::vector<stdvstring> vstrlist;
typedef vstrlist row;
//////////////////////////////////////////////////////////////////////////
// Classes
//////////////////////////////////////////////////////////////////////////
class Table; // Forward declaration
class TablePtr; // Forward declaration
// Main wrapper
class Database
{
public:
Database(void);
virtual ~Database(void);
int Open(std::string strFileName );
void Close();
bool IsOpen();
sqlite3 * GetPtr(){ return m_sqlite3; };
int GetLastError(){ return m_iLastError; };
void ClearError() { m_iLastError=SQLITE_OK; };
Table QuerySQL(std::string strSQL );
int ExecuteSQL(std::string strSQL );
int IsSQLComplete(std::string strSQL );
int GetLastChangesCount();
sqlite_int64 GetLastInsertRowID();
bool BeginTransaction();
bool CommitTransaction();
bool RollbackTransaction();
private:
sqlite3 * m_sqlite3;
int m_iLastError;
void ConvertUTF8ToString( char * strInUTF8MB, stdvstring & strOut );
};
class Table
{
friend class Database;
public:
Table(void){ m_iRows=m_iCols=0; m_iPos=-1; };
virtual ~Table() {};
int GetColCount(){ if (this==0) return 0; return m_iCols; };
int GetRowCount(){ if (this==0) return 0; return m_iRows; };
int GetCurRow(){ if (this==0) return -1; return m_iPos; };
std::string GetColName( int iCol );
void ResetRow(){ m_iPos = -1; };
bool GoFirst();
bool GoLast();
bool GoNext();
bool GoPrev();
bool GoRow(unsigned int iRow);
std::string GetValue(std::string lpColName);
std::string GetValue(int iColIndex);
std::string operator [] (std::string lpColName);
std::string operator [] (int iColIndex);
void JoinTable(Table & tblJoin);
private:
int m_iRows, m_iCols;
row m_strlstCols;
std::vector<row> m_lstRows;
int m_iPos;
};
}