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