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