Version: 1.0.0
database.h
Go to the documentation of this file.
1 #ifndef _WX_DATABASE_H_
2 #define _WX_DATABASE_H_
3 
4 #include "wx/database/wxprec.h"
5 #include "wx/config.h"
6 
7 WX_DECLARE_HASH_SET( wxDatabaseResultSet*, wxPointerHash, wxPointerEqual, wxDatabaseResultSetHashSet );
8 WX_DECLARE_HASH_SET( wxPreparedStatement*, wxPointerHash, wxPointerEqual, wxDatabaseStatementHashSet );
9 
11 {
12 public:
14  wxDatabase();
15 
17  virtual ~wxDatabase();
18 
19  // Open database
20  virtual bool Open(const wxString& strDatabase) = 0;
21 
22  /***
23  * Causes the database specified by db to become the default (current) database on the connection
24  * If unimplemented just return false (Equivalent to unsuccessful operation)
25  */
26  virtual bool ChangeDatabase(const wxString& database) { return false; }
27 
29  virtual bool Close() = 0;
30 
32  virtual bool IsOpen() = 0;
33 
34  // transaction support
36  virtual void BeginTransaction() = 0;
38  virtual void Commit() = 0;
40  virtual void RollBack() = 0;
41 
42  // query database
44  virtual int RunQuery(const wxString& strQuery);
46  virtual int RunQuery(const wxString& strQuery, bool bParseQueries) = 0;
48  virtual wxDatabaseResultSet* RunQueryWithResults(const wxString& strQuery) = 0;
49 
51  virtual bool CloseResultSet(wxDatabaseResultSet* pResultSet);
52 
53  // wxPreparedStatement support
55  virtual wxPreparedStatement* PrepareStatement(const wxString& strQuery) = 0;
57  virtual bool CloseStatement(wxPreparedStatement* pStatement);
58 
59  // function names more consistent with JDBC and wxSQLite3
60  // these just provide wrappers for existing functions
62  int ExecuteUpdate(const wxString& strQuery) { return RunQuery(strQuery); }
64  wxDatabaseResultSet* ExecuteQuery(const wxString& strQuery) { return RunQueryWithResults(strQuery); }
65 
66  // Database schema API contributed by M. Szeftel (author of wxActiveRecordGenerator)
68  virtual bool TableExists(const wxString& table) = 0;
70  virtual bool ViewExists(const wxString& view) = 0;
72  virtual wxArrayString GetTables() = 0;
74  virtual wxArrayString GetViews() = 0;
76  virtual wxArrayString GetColumns(const wxString& table) = 0;
78  virtual wxArrayString GetPKColumns(const wxString& table) = 0;
79 
80  // Database single result retrieval API contributed by Guru Kathiresan
84 
88  virtual int GetSingleResultInt(const wxString& strSQL, int nField, bool bRequireUniqueResult = true);
89  virtual int GetSingleResultInt(const wxString& strSQL, const wxString& strField, bool bRequireUniqueResult = true);
90 
94  virtual wxString GetSingleResultString(const wxString& strSQL, int nField, bool bRequireUniqueResult = true);
95  virtual wxString GetSingleResultString(const wxString& strSQL, const wxString& strField, bool bRequireUniqueResult = true);
96 
100  virtual long GetSingleResultLong(const wxString& strSQL, int nField, bool bRequireUniqueResult = true);
101  virtual long GetSingleResultLong(const wxString& strSQL, const wxString& strField, bool bRequireUniqueResult = true);
102 
106  virtual bool GetSingleResultBool(const wxString& strSQL, int nField, bool bRequireUniqueResult = true);
107  virtual bool GetSingleResultBool(const wxString& strSQL, const wxString& strField, bool bRequireUniqueResult = true);
108 
112  virtual wxDateTime GetSingleResultDate(const wxString& strSQL, int nField, bool bRequireUniqueResult = true);
113  virtual wxDateTime GetSingleResultDate(const wxString& strSQL, const wxString& strField, bool bRequireUniqueResult = true);
114 
118  virtual void* GetSingleResultBlob(const wxString& strSQL, int nField, wxMemoryBuffer& Buffer, bool bRequireUniqueResult = true);
119  virtual void* GetSingleResultBlob(const wxString& strSQL, const wxString& strField, wxMemoryBuffer& Buffer, bool bRequireUniqueResult = true);
120 
124  virtual double GetSingleResultDouble(const wxString& strSQL, int nField, bool bRequireUniqueResult = true);
125  virtual double GetSingleResultDouble(const wxString& strSQL, const wxString& strField, bool bRequireUniqueResult = true);
126 
128  virtual wxArrayInt GetResultsArrayInt(const wxString& strSQL, int nField);
129  virtual wxArrayInt GetResultsArrayInt(const wxString& strSQL, const wxString& Field);
130 
131  virtual wxArrayString GetResultsArrayString(const wxString& strSQL, int nField);
132  virtual wxArrayString GetResultsArrayString(const wxString& strSQL, const wxString& Field);
133 
134  virtual wxArrayLong GetResultsArrayLong(const wxString& strSQL, int nField);
135  virtual wxArrayLong GetResultsArrayLong(const wxString& strSQL, const wxString& Field);
136 
137  virtual wxArrayDouble GetResultsArrayDouble(const wxString& strSQL, int nField);
138  virtual wxArrayDouble GetResultsArrayDouble(const wxString& strSQL, const wxString& Field);
139 
141  void CloseResultSets();
143  void CloseStatements();
144 
145  //AML start
149  const wxString& GetTypeName() { return m_typeName; }
153  bool IsViaODBC() { return m_isViaODBC; }
157  const wxString& GetLibraryPath() { return m_libraryPath; }
161  static wxDatabase* GetDatabase(wxConfigBase& config, wxString* err = NULL, const wxString& path = "/");
162 private:
163 #if wxUSE_DATABASE_SQLITE
164  static wxDatabase* GetSqliteDatabase(wxConfigBase& config, wxString* err = NULL);
165 #endif
166 #if wxUSE_DATABASE_POSTGRESQL
167  static wxDatabase* GetPostgresDatabase(wxConfigBase& config, wxString* err = NULL);
168 #endif
169 #if wxUSE_DATABASE_MYSQL
170  static wxDatabase* GetMysqlDatabase(wxConfigBase& config, wxString* err = NULL);
171 #endif
172 #if wxUSE_DATABASE_ODBC
173  static wxDatabase* GetOdbcDatabase(wxConfigBase& config, wxString* err = NULL);
174 #endif
175 #if wxUSE_DATABASE_TDS
176  static wxDatabase* GetTdsDatabase(wxConfigBase& config, wxString* err = NULL);
177 #endif
178  //AML end
179 protected:
181  void LogResultSetForCleanup(wxDatabaseResultSet* pResultSet) { m_ResultSets.insert(pResultSet); }
183  void LogStatementForCleanup(wxPreparedStatement* pStatement) { m_Statements.insert(pStatement); }
184 
185 private:
186  int GetSingleResultInt(const wxString& strSQL, const wxVariant* field, bool bRequireUniqueResult = true);
187  wxString GetSingleResultString(const wxString& strSQL, const wxVariant* field, bool bRequireUniqueResult = true);
188  long GetSingleResultLong(const wxString& strSQL, const wxVariant* field, bool bRequireUniqueResult = true);
189  bool GetSingleResultBool(const wxString& strSQL, const wxVariant* field, bool bRequireUniqueResult = true);
190  wxDateTime GetSingleResultDate(const wxString& strSQL, const wxVariant* field, bool bRequireUniqueResult = true);
191  void* GetSingleResultBlob(const wxString& strSQL, const wxVariant* field, wxMemoryBuffer& Buffer, bool bRequireUniqueResult = true);
192  double GetSingleResultDouble(const wxString& strSQL, const wxVariant* field, bool bRequireUniqueResult = true);
193  wxArrayInt GetResultsArrayInt(const wxString& strSQL, const wxVariant* field);
194  wxArrayString GetResultsArrayString(const wxString& strSQL, const wxVariant* field);
195  wxArrayLong GetResultsArrayLong(const wxString& strSQL, const wxVariant* field);
196 #if wxCHECK_VERSION(2, 7, 0)
197  wxArrayDouble GetResultsArrayDouble(const wxString& strSQL, const wxVariant* field);
198 #endif
199 
200  wxDatabaseResultSetHashSet m_ResultSets;
201  wxDatabaseStatementHashSet m_Statements;
202  //AML start
203  wxString m_typeName;
205  wxString m_libraryPath;
206  //AML end
207 };
208 
209 #endif//_WX_DATABASE_H_
210 
virtual bool ChangeDatabase(const wxString &database)
Definition: database.h:26
const wxString & GetTypeName()
Get a descriptive name for the type of database.
Definition: database.h:149
int ExecuteUpdate(const wxString &strQuery)
See RunQuery.
Definition: database.h:62
wxDatabaseResultSetHashSet m_ResultSets
Definition: database.h:200
wxDatabaseResultSet * ExecuteQuery(const wxString &strQuery)
See RunQueryWithResults.
Definition: database.h:64
wxString m_libraryPath
Definition: database.h:205
bool m_isViaODBC
Definition: database.h:204
bool IsViaODBC()
Is the connection via ODBC.
Definition: database.h:153
WX_DECLARE_HASH_SET(wxDatabaseResultSet *, wxPointerHash, wxPointerEqual, wxDatabaseResultSetHashSet)
void LogStatementForCleanup(wxPreparedStatement *pStatement)
Add prepared statement object pointer to the list for "garbage collection".
Definition: database.h:183
void LogResultSetForCleanup(wxDatabaseResultSet *pResultSet)
Add result set object pointer to the list for "garbage collection".
Definition: database.h:181
wxString m_typeName
Definition: database.h:203
#define WXDLLIMPEXP_DATABASE
wxDatabaseStatementHashSet m_Statements
Definition: database.h:201
const wxString & GetLibraryPath()
Get the library path required by the database.
Definition: database.h:157