]> git.saurik.com Git - wxWidgets.git/blob - include/wx/odbc.h
ed73055dedcc1f2d6e03c575b4556b8a26de862f
[wxWidgets.git] / include / wx / odbc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: odbc.h
3 // Purpose: ODBC classes
4 // Author: Olaf Klein, Patrick Halke, Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/setup.h"
13
14 #if USE_ODBC
15
16 #ifdef __GNUG__
17 #pragma interface "odbc.h"
18 #endif
19
20 #ifndef __ODBCH__
21 #define __ODBCH__
22
23 #ifdef __WXMSW__
24 #include <windows.h>
25 #endif
26
27 #ifdef __WXGTK__
28 #include <../iodbc/postgres/isqlext.h>
29 #include <../iodbc/postgres/odbc_funcs.h>
30 #include <../iodbc/postgres/odbc_types.h>
31 #else
32 #include <sqlext.h>
33 #endif
34
35 #include "wx/defs.h"
36 #include "wx/list.h"
37 #include "wx/string.h"
38
39 typedef RETCODE wxRETCODE;
40
41 // Recordset open types
42 #define wxOPEN_TYPE_DYNASET 1
43 #define wxOPEN_TYPE_SNAPSHOT 2
44 #define wxOPEN_TYPE_FORWARD_ONLY 3
45
46 // Recordset open options
47 #define wxOPTION_DEFAULT 1
48 #define wxOPTION_APPEND_ONLY 2
49 #define wxOPTION_READ_ONLY 3
50
51 // Data types
52 class WXDLLEXPORT wxRecordSet;
53
54 class WXDLLEXPORT wxDatabase: public wxObject
55 {
56 // JACS
57 DECLARE_DYNAMIC_CLASS(wxDatabase)
58 private:
59 protected:
60 static HENV hEnv;
61 static int refCount;
62
63 HDBC hDBC;
64 char* username;
65 char* password;
66 char* datasource;
67 char* dbname;
68 char* connectstring;
69 bool isOpen;
70
71 // error-handling variables
72 wxRETCODE retcode;
73 char sqlstate[SQL_SQLSTATE_SIZE+1]; // error class and subclass
74 char errmsg[SQL_MAX_MESSAGE_LENGTH]; // error message
75 long nat_err; // error number by ODBC driver
76 bool err_occured;
77
78 wxList recordSets; // Record sets: Added by JACS
79
80 public:
81 wxDatabase(void);
82 ~wxDatabase(void);
83
84 bool Open(char *, bool exclusive =FALSE, bool readOnly =TRUE, char *username ="ODBC", char *password ="");
85 bool Close(void);
86
87 // Cleanup operations, added by JACS
88 void DeleteRecordSets(void); // Called when the database is deleted
89 void ResetRecordSets(void); // Required if the database is closed
90 inline wxList& GetRecordSets(void) { return recordSets; }
91
92 inline char *GetUsername(void) { return username; }
93 inline char *GetPassword(void) { return password; }
94 inline char *GetDataSource(void) { return datasource; }
95 inline bool IsOpen(void) { return isOpen; }
96 inline wxRETCODE GetErrorCode(void) { return retcode; }
97 inline HDBC GetHDBC(void) { return hDBC; }
98 inline HENV GetHENV(void) { return hEnv; }
99
100 void SetPassword(char *s);
101 void SetUsername(char *s);
102 void SetDataSource(char *s);
103
104 // Database attributes
105 char *GetDatabaseName(void);
106 bool CanUpdate(void);
107 bool CanTransact(void);
108 bool InWaitForDataSource(void);
109 void SetLoginTimeout(long seconds);
110 void SetQueryTimeout(long seconds);
111 void SetSynchronousMode(bool synchronous);
112
113 // Database operations
114 bool BeginTrans(void);
115 bool CommitTrans(void);
116 bool RollbackTrans(void);
117 void Cancel(void);
118
119 // Error handling
120 bool ErrorOccured(void);
121 char* GetErrorMessage(void);
122 long GetErrorNumber(void);
123 char* GetErrorClass(void);
124 inline void ErrorSnapshot(HSTMT =SQL_NULL_HSTMT);
125
126 // Overridables
127 virtual void OnSetOptions(wxRecordSet *recordSet);
128 virtual void OnWaitForDataSource(bool stillExecuting);
129
130 bool GetInfo(long infoType, long *buf);
131 bool GetInfo(long infoType, char *buf, int bufSize = -1);
132
133 // implementation = TRUE means get the DLL version.
134 // Otherwise, returns header file version.
135 wxString GetODBCVersionString(bool implementation = TRUE);
136 float GetODBCVersionFloat(bool implementation = TRUE);
137 };
138
139 // Represents a data row
140 class WXDLLEXPORT wxQueryField: public wxObject
141 {
142 // JACS
143 DECLARE_DYNAMIC_CLASS(wxQueryField)
144 private:
145 void *data;
146 short type;
147 long size;
148 bool dirty;
149
150 bool AllocData(void);
151
152 public:
153 wxQueryField(void);
154 ~wxQueryField(void);
155
156 bool SetData(void*, long);
157 void SetDirty(bool =TRUE);
158 void ClearData(void);
159 void SetType(short);
160 void SetSize(long);
161
162 void* GetData(void);
163 short GetType(void);
164 long GetSize(void);
165
166 bool IsDirty(void);
167 };
168
169 // Represents a column description
170 class WXDLLEXPORT wxQueryCol: public wxObject
171 {
172 // JACS
173 DECLARE_DYNAMIC_CLASS(wxQueryCol)
174 private:
175 short type;
176 char *name;
177 bool nullable;
178 long varsize;
179 void* var;
180
181 public:
182 wxList fields;
183
184 wxQueryCol(void);
185 ~wxQueryCol(void);
186
187 void* BindVar(void*, long);
188 void FillVar(int);
189 void AppendField(void*, long);
190 bool SetData(int, void*, long);
191 void SetName(char*);
192 void SetNullable(bool);
193 void SetFieldDirty(int, bool =TRUE);
194 void SetType(short);
195
196 char* GetName(void);
197 short GetType(void);
198 bool IsNullable(void);
199 void* GetData(int);
200 long GetSize(int);
201
202 bool IsFieldDirty(int);
203 };
204
205 class WXDLLEXPORT wxRecordSet: public wxObject
206 {
207 // JACS
208 DECLARE_DYNAMIC_CLASS(wxRecordSet)
209 private:
210 int cursor;
211 int type;
212 int options;
213
214 protected:
215 HSTMT hStmt;
216 int nFields;
217 int nParams;
218 int nRecords;
219 short nCols;
220 char *recordFilter;
221 char *sortString;
222 char *defaultSQL;
223 char* tablename;
224 wxDatabase *parentdb;
225 wxRETCODE retcode;
226 wxList cols;
227 wxList fetchbuf;
228
229 void FillVars(int);
230
231 public:
232 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
233 wxRecordSet(wxDatabase *parent = NULL, int =wxOPEN_TYPE_DYNASET, int =wxOPTION_DEFAULT);
234 ~wxRecordSet(void);
235
236 // My own, lower-level functions.
237 bool BeginQuery(int openType, char *sql = NULL, int options = wxOPTION_DEFAULT);
238 bool EndQuery(void);
239 bool Query(char* columns, char* table =NULL, char *filter =NULL);
240
241 // Attributes
242 inline int GetNumberFields(void) { return nFields; }
243 inline int GetNumberParams(void) { return nParams; }
244 long GetNumberRecords(void);
245 long GetNumberCols(void);
246 inline char *GetFilter(void) { return recordFilter; }
247 inline char *GetSortString(void) { return sortString; }
248 inline wxDatabase *GetDatabase(void) { return parentdb; }
249 inline wxRETCODE GetErrorCode(void) { return retcode; }
250 bool CanAppend(void);
251 bool CanRestart(void);
252 bool CanScroll(void);
253 bool CanTransact(void);
254 bool CanUpdate(void);
255 long GetCurrentRecord(void);
256 bool RecordCountFinal(void);
257 bool GetResultSet(void);
258 bool ExecuteSQL(char*);
259 bool GetTables(void);
260 bool GetColumns(char* =NULL);
261 bool GetPrimaryKeys(char* =NULL);
262 bool GetForeignKeys(char* , char * );
263 char *GetTableName(void);
264 void SetTableName(char*);
265 char *GetSQL(void);
266 bool IsOpen(void);
267 bool IsBOF(void);
268 bool IsEOF(void);
269 bool IsDeleted(void);
270
271 bool GetFieldData(int colPos, int dataType, void *dataPtr);
272 bool GetFieldData(const char*, int dataType, void *dataPtr);
273 void* GetFieldDataPtr(int, int);
274 void* GetFieldDataPtr(const char*, int);
275 char* GetColName(int);
276 short GetColType(int);
277 short GetColType(const char*);
278 void* BindVar(int, void*, long);
279 void* BindVar(const char*, void*, long);
280
281 void SetType(int);
282 int GetType(void);
283 void SetOptions(int);
284 int GetOptions(void);
285
286 // Update operations
287 void AddNew(void);
288 bool Delete(void);
289 void Edit(void);
290 bool Update(void);
291
292 // Record navigation
293 virtual bool Move(long rows);
294 virtual bool MoveFirst(void);
295 virtual bool MoveLast(void);
296 virtual bool MoveNext(void);
297 virtual bool MovePrev(void);
298 virtual bool GoTo(long);
299
300 // Others
301 bool GetDataSources(void);
302
303 // Associate a column name/position with a data location
304 // bool BindColumn(int colPos, int dataType, void *dataPtr);
305
306 void Cancel(void);
307 bool IsFieldDirty(int);
308 bool IsFieldDirty(const char*);
309 bool IsFieldNull(int);
310 bool IsFieldNull(const char*);
311 bool IsColNullable(int);
312 bool IsColNullable(const char*);
313 virtual bool Requery(void);
314 virtual void SetFieldDirty(int, bool dirty = TRUE);
315 virtual void SetFieldDirty(const char*, bool dirty = TRUE);
316 void SetFieldNull(void *p, bool isNull = TRUE);
317
318 // Overridables
319 virtual char *GetDefaultConnect(void);
320 virtual char *GetDefaultSQL(void);
321
322 // Internal
323
324 // Build SQL query from column specification
325 bool ConstructDefaultSQL(void);
326 void SetDefaultSQL(char *s);
327 bool ReleaseHandle(void); // Added JACS
328 };
329
330 #endif
331
332 #endif // USE_ODBC