00001
00002
00003
00004
00005
00006
00007
00009
00010 #ifndef __wx_dbi_sqlite_h__
00011 #define __wx_dbi_sqlite_h__
00012
00013 #ifdef wxDBI_SQLITE
00014
00015 #include <wx/dbi.h>
00016
00017 #include <sqlite3.h>
00018
00019 namespace wx
00020 {
00021
00022 namespace DBI
00023 {
00024
00025
00026 #if wxUSE_UNICODE
00027 #define SQLite3_open(a, b) sqlite3_open16(a, b)
00028 #define SQLite3_prepare(a, b, c, d, e) sqlite3_prepare16(a, b, c, d, e)
00029 #define SQLite3_errmsg(a) sqlite3_errmsg16(a)
00030
00031 #define SQLiteString void *
00032 #define wxStringBytes(x) (2 * x.Length())
00033 #define SQLiteStringTowxString(x) cnv.cMB2WC((const char *) x)
00034
00035 #else // wxUSE_UNICODE
00036 #define SQLite3_open(a, b) sqlite3_open(a, b)
00037 #define SQLite3_prepare(a, b, c, d, e) sqlite3_prepare(a, b, c, d, e)
00038 #define SQLite3_errmsg(a) sqlite3_errmsg(a)
00039
00040
00041 #define wxStringBytes(x) (x.Length())
00042 #endif // wxUSE_UNICODE
00043
00044
00045 #define SQLite3_close(a) sqlite3_close(a)
00046 #define SQLite3_finalize(a) sqlite3_finalize(a)
00047
00048 #define SQLITE_DATABASE_PATHNAME wxT("PathName")
00049 #define SQLITE_CREATEIFMISSING wxT("CreateIfMissing")
00050
00051 class SQLite : public Database
00052 {
00053
00054 friend class SQLiteStatement;
00055
00056
00057 public:
00061 SQLite();
00062
00067 ~SQLite()
00068 {
00069 Disconnect();
00070 }
00071
00073
00074
00075
00076
00077
00078 public:
00079
00080
00091 virtual void Connect(const ConnectionInfo& cni);
00092 virtual void Disconnect();
00093 bool IsConnected();
00094
00095
00096 void Begin();
00097 void Rollback();
00098 void Commit();
00099
00100
00101 Statement * Prepare(wxString const& sQuery);
00102
00103
00104 wxArrayString GetDatabases();
00105 bool DatabaseExists(const wxString& sDatabaseName);
00106 wxArrayString GetTables();
00107 bool TableExists(const wxString& sTableName);
00108
00110
00111 public:
00112
00114
00115 private:
00116 sqlite3 * plite;
00117 wxString sDatabasePathName;
00118 };
00119
00120 class SQLiteStatement : public Statement
00121 {
00122
00123
00124 public:
00125 SQLiteStatement(Database * pdbOwner, const wxString& sNewQuery);
00126 ~SQLiteStatement();
00127
00128 public:
00129 bool DataAvailable();
00130
00135 void ExecutePrepared(const ArrayRecord& raParameters = ArrayRecord());
00136
00141 void ExecuteTemporary(const ArrayRecord& raParameters = ArrayRecord());
00142 long GetLastInsertId();
00143
00144 protected:
00145 int GetFieldCount();
00146 void MoveNext();
00147 void GetFieldValue
00148 (
00149 int nIndex,
00150 wxVariant& v
00151 );
00152 wxString GetFieldName
00153 (
00154 int nIndex
00155 );
00156
00157 private:
00158 void Execute(const ArrayRecord& raParameters);
00159
00160 private:
00161 sqlite3_stmt * pls;
00162 int nStepReturn;
00163 };
00164
00165 }
00166
00167 }
00168
00169 #endif // def wxDBI_SQLITE
00170
00171 #endif // ndef __wx_dbi_sqlite_h__
00172