]>
Commit | Line | Data |
---|---|---|
108106cf | 1 | /////////////////////////////////////////////////////////////////////////////// |
2b5f62a0 | 2 | // Name: wx/db.h |
f6bcfd97 BP |
3 | // Purpose: Header file wxDb class. The wxDb class represents a connection |
4 | // to an ODBC data source. The wxDb class allows operations on the data | |
108106cf JS |
5 | // source such as opening and closing the data source. |
6 | // Author: Doug Card | |
30a6d2d2 | 7 | // Modified by: George Tasker |
3ca6a5f0 | 8 | // Bart Jourquin |
a9f4558f | 9 | // Mark Johnson, wxWindows@mj10777.de |
ad2522ad | 10 | // Mods: Dec, 1998: |
a2115c88 | 11 | // -Added support for SQL statement logging and database cataloging |
95ca6a20 GT |
12 | // April, 1999 |
13 | // -Added QUERY_ONLY mode support to reduce default number of cursors | |
14 | // -Added additional SQL logging code | |
a2115c88 | 15 | // -Added DEBUG-ONLY tracking of Ctable objects to detect orphaned DB connections |
95ca6a20 GT |
16 | // -Set ODBC option to only read committed writes to the DB so all |
17 | // databases operate the same in that respect | |
a2115c88 | 18 | // |
108106cf JS |
19 | // Created: 9.96 |
20 | // RCS-ID: $Id$ | |
21 | // Copyright: (c) 1996 Remstar International, Inc. | |
7e559cd8 | 22 | // Licence: wxWindows licence |
108106cf JS |
23 | /////////////////////////////////////////////////////////////////////////////// |
24 | ||
2b5f62a0 VZ |
25 | #ifndef _WX_DB_H_ |
26 | #define _WX_DB_H_ | |
a2115c88 | 27 | |
f6bcfd97 | 28 | |
43e8916f | 29 | // BJO 20000503: introduce new GetColumns members which are more database independent and |
f6bcfd97 BP |
30 | // return columns in the order they were created |
31 | #define OLD_GETCOLUMNS 1 | |
e2f4e132 | 32 | #define EXPERIMENTAL_WXDB_FUNCTIONS 1 |
f6bcfd97 | 33 | |
d4af841d GT |
34 | #include "wx/defs.h" |
35 | #include "wx/string.h" | |
36 | ||
68379eaf | 37 | #if defined(__VISUALC__) |
2b5f62a0 VZ |
38 | // we need to include standard Windows headers but we can't include |
39 | // <windows.h> directly when using MFC because it includes it itself in a | |
40 | // different manner | |
41 | #if wxUSE_MFC | |
42 | #include <afxwin.h> | |
43 | #else // !wxUSE_MFC | |
f24a3804 | 44 | #include "wx/msw/wrapwin.h" |
2b5f62a0 VZ |
45 | #endif // wxUSE_MFC/!wxUSE_MFC |
46 | ||
47 | // If you use the wxDbCreateDataSource() function with MSW/VC6, | |
48 | // you cannot use the iODBC headers, you must use the VC headers, | |
49 | // plus the odbcinst.h header - gt Nov 2 2000 | |
50 | // | |
77ffb593 | 51 | // Must add "odbccp32.lib" in \wx2\wxWidgets\src\makevc.env to the WINLIBS= line |
2b5f62a0 | 52 | // |
e2f4e132 GT |
53 | #include "sql.h" |
54 | #include "sqlext.h" | |
2889677e GT |
55 | //#if wxUSE_UNICODE |
56 | // #include <sqlucode.h> | |
57 | //#endif | |
e2f4e132 | 58 | #include "odbcinst.h" |
f7556ff0 | 59 | #else |
bfe5de86 | 60 | #if defined(__WINDOWS__) && ( defined(HAVE_W32API_H) || defined(__BORLANDC__) ) |
f24a3804 | 61 | #include "wx/msw/wrapwin.h" |
190869b2 | 62 | #endif |
2b5f62a0 | 63 | extern "C" { |
0bdb08e7 VS |
64 | #if defined(wxUSE_BUILTIN_IODBC) && wxUSE_BUILTIN_IODBC |
65 | // Use the ones from the library | |
66 | #include "wx/isql.h" | |
67 | #include "wx/isqlext.h" | |
2889677e GT |
68 | // Not available in v2.x of iODBC |
69 | #ifndef __WXMSW__ | |
cf0cf17b JS |
70 | #if wxUSE_UNICODE |
71 | typedef wxChar SQLTCHAR; | |
72 | #else | |
73 | typedef UCHAR SQLTCHAR; | |
74 | #endif | |
2889677e | 75 | #endif |
0bdb08e7 | 76 | #else |
6c1465ef VZ |
77 | #if defined( __WXMOTIF__ ) && defined( __VMS ) |
78 | // solves a type definition mismatch between IODBC and MOTIF on OpenVMS | |
79 | #define BOOL int | |
80 | #endif | |
fcdc9f6e JS |
81 | #if defined( __DARWIN__ ) |
82 | // solves a type definition mismatch between IODBC and Cocoa | |
83 | #define BOOL signed char | |
84 | #endif | |
f7556ff0 JS |
85 | #include <sql.h> |
86 | #include <sqlext.h> | |
2889677e GT |
87 | //#if wxUSE_UNICODE |
88 | // #include <sqlucode.h> | |
89 | //#endif | |
6c1465ef VZ |
90 | #if defined( __WXMOTIF__ ) && defined( __VMS ) |
91 | #undef BOOL | |
92 | #endif | |
0bdb08e7 | 93 | #endif |
2b5f62a0 | 94 | } |
aecca2c8 MB |
95 | #endif |
96 | ||
e4e45573 GT |
97 | #if wxUSE_UNICODE |
98 | #define SQL_C_WXCHAR SQL_C_WCHAR | |
99 | #else | |
100 | #define SQL_C_WXCHAR SQL_C_CHAR | |
101 | #endif | |
30a6d2d2 | 102 | |
e716b9be JS |
103 | #ifdef __DIGITALMARS__ |
104 | #if wxUSE_UNICODE | |
105 | typedef wxChar SQLTCHAR; | |
106 | #else | |
107 | typedef UCHAR SQLTCHAR; | |
108 | #endif | |
109 | #endif | |
110 | ||
595b5c4e MJ |
111 | typedef float SFLOAT; |
112 | typedef double SDOUBLE; | |
95ca6a20 GT |
113 | typedef unsigned int UINT; |
114 | #define ULONG UDWORD | |
30a6d2d2 GT |
115 | |
116 | #ifndef wxODBC_FWD_ONLY_CURSORS | |
117 | #define wxODBC_FWD_ONLY_CURSORS 1 | |
118 | #endif | |
119 | ||
95ca6a20 | 120 | enum enumDummy {enumDum1}; |
7e616b10 | 121 | |
b742792c | 122 | #ifndef SQL_C_BOOLEAN |
f3df29e3 | 123 | #define SQL_C_BOOLEAN(datatype) (sizeof(datatype) == 1 ? SQL_C_UTINYINT : (sizeof(datatype) == 2 ? SQL_C_USHORT : SQL_C_ULONG)) |
b742792c | 124 | #endif |
20987580 | 125 | |
b742792c | 126 | #ifndef SQL_C_ENUM |
f3df29e3 | 127 | #define SQL_C_ENUM (sizeof(enumDummy) == 2 ? SQL_C_USHORT : SQL_C_ULONG) |
b742792c | 128 | #endif |
20987580 | 129 | |
f3df29e3 GT |
130 | // NOTE: If SQL_C_BLOB is defined, and it is not SQL_C_BINARY, iODBC 2.x |
131 | // may not function correctly. Likely best to use SQL_C_BINARY direct | |
b742792c | 132 | #ifndef SQL_C_BLOB |
f3df29e3 GT |
133 | #ifdef SQL_C_BINARY |
134 | #define SQL_C_BLOB SQL_C_BINARY | |
b742792c GT |
135 | #endif |
136 | #endif | |
7e616b10 | 137 | |
e716b9be JS |
138 | #ifndef _WIN64 |
139 | #ifndef SQLLEN | |
140 | #define SQLLEN SQLINTEGER | |
141 | #endif | |
142 | #ifndef SQLULEN | |
143 | #define SQLULEN SQLUINTEGER | |
144 | #endif | |
145 | #endif | |
146 | ||
f6bcfd97 | 147 | const int wxDB_PATH_MAX = 254; |
95ca6a20 | 148 | |
16cba29d WS |
149 | extern WXDLLIMPEXP_DATA_ODBC(wxChar const *) SQL_LOG_FILENAME; |
150 | extern WXDLLIMPEXP_DATA_ODBC(wxChar const *) SQL_CATALOG_FILENAME; | |
108106cf | 151 | |
108106cf | 152 | // Database Globals |
95ca6a20 | 153 | const int DB_TYPE_NAME_LEN = 40; |
eb3b9dda GT |
154 | const int DB_MAX_STATEMENT_LEN = 4096; |
155 | const int DB_MAX_WHERE_CLAUSE_LEN = 2048; | |
95ca6a20 GT |
156 | const int DB_MAX_ERROR_MSG_LEN = 512; |
157 | const int DB_MAX_ERROR_HISTORY = 5; | |
158 | const int DB_MAX_TABLE_NAME_LEN = 128; | |
159 | const int DB_MAX_COLUMN_NAME_LEN = 128; | |
160 | ||
161 | const int DB_DATA_TYPE_VARCHAR = 1; | |
162 | const int DB_DATA_TYPE_INTEGER = 2; | |
163 | const int DB_DATA_TYPE_FLOAT = 3; | |
164 | const int DB_DATA_TYPE_DATE = 4; | |
b742792c | 165 | const int DB_DATA_TYPE_BLOB = 5; |
7eeba511 | 166 | const int DB_DATA_TYPE_MEMO = 6; |
95ca6a20 GT |
167 | |
168 | const int DB_SELECT_KEYFIELDS = 1; | |
169 | const int DB_SELECT_WHERE = 2; | |
170 | const int DB_SELECT_MATCHING = 3; | |
171 | const int DB_SELECT_STATEMENT = 4; | |
172 | ||
173 | const int DB_UPD_KEYFIELDS = 1; | |
174 | const int DB_UPD_WHERE = 2; | |
175 | ||
176 | const int DB_DEL_KEYFIELDS = 1; | |
177 | const int DB_DEL_WHERE = 2; | |
178 | const int DB_DEL_MATCHING = 3; | |
179 | ||
180 | const int DB_WHERE_KEYFIELDS = 1; | |
181 | const int DB_WHERE_MATCHING = 2; | |
182 | ||
183 | const int DB_GRANT_SELECT = 1; | |
184 | const int DB_GRANT_INSERT = 2; | |
185 | const int DB_GRANT_UPDATE = 4; | |
186 | const int DB_GRANT_DELETE = 8; | |
187 | const int DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT | DB_GRANT_UPDATE | DB_GRANT_DELETE; | |
108106cf JS |
188 | |
189 | // ODBC Error codes (derived from ODBC SqlState codes) | |
fdc03678 | 190 | enum wxODBC_ERRORS |
108106cf | 191 | { |
95ca6a20 GT |
192 | DB_FAILURE = 0, |
193 | DB_SUCCESS = 1, | |
194 | DB_ERR_NOT_IN_USE, | |
195 | DB_ERR_GENERAL_WARNING, // SqlState = '01000' | |
196 | DB_ERR_DISCONNECT_ERROR, // SqlState = '01002' | |
197 | DB_ERR_DATA_TRUNCATED, // SqlState = '01004' | |
198 | DB_ERR_PRIV_NOT_REVOKED, // SqlState = '01006' | |
199 | DB_ERR_INVALID_CONN_STR_ATTR, // SqlState = '01S00' | |
200 | DB_ERR_ERROR_IN_ROW, // SqlState = '01S01' | |
201 | DB_ERR_OPTION_VALUE_CHANGED, // SqlState = '01S02' | |
202 | DB_ERR_NO_ROWS_UPD_OR_DEL, // SqlState = '01S03' | |
203 | DB_ERR_MULTI_ROWS_UPD_OR_DEL, // SqlState = '01S04' | |
204 | DB_ERR_WRONG_NO_OF_PARAMS, // SqlState = '07001' | |
205 | DB_ERR_DATA_TYPE_ATTR_VIOL, // SqlState = '07006' | |
206 | DB_ERR_UNABLE_TO_CONNECT, // SqlState = '08001' | |
207 | DB_ERR_CONNECTION_IN_USE, // SqlState = '08002' | |
208 | DB_ERR_CONNECTION_NOT_OPEN, // SqlState = '08003' | |
209 | DB_ERR_REJECTED_CONNECTION, // SqlState = '08004' | |
210 | DB_ERR_CONN_FAIL_IN_TRANS, // SqlState = '08007' | |
211 | DB_ERR_COMM_LINK_FAILURE, // SqlState = '08S01' | |
212 | DB_ERR_INSERT_VALUE_LIST_MISMATCH, // SqlState = '21S01' | |
213 | DB_ERR_DERIVED_TABLE_MISMATCH, // SqlState = '21S02' | |
214 | DB_ERR_STRING_RIGHT_TRUNC, // SqlState = '22001' | |
215 | DB_ERR_NUMERIC_VALUE_OUT_OF_RNG, // SqlState = '22003' | |
216 | DB_ERR_ERROR_IN_ASSIGNMENT, // SqlState = '22005' | |
217 | DB_ERR_DATETIME_FLD_OVERFLOW, // SqlState = '22008' | |
218 | DB_ERR_DIVIDE_BY_ZERO, // SqlState = '22012' | |
219 | DB_ERR_STR_DATA_LENGTH_MISMATCH, // SqlState = '22026' | |
220 | DB_ERR_INTEGRITY_CONSTRAINT_VIOL, // SqlState = '23000' | |
221 | DB_ERR_INVALID_CURSOR_STATE, // SqlState = '24000' | |
222 | DB_ERR_INVALID_TRANS_STATE, // SqlState = '25000' | |
223 | DB_ERR_INVALID_AUTH_SPEC, // SqlState = '28000' | |
224 | DB_ERR_INVALID_CURSOR_NAME, // SqlState = '34000' | |
225 | DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL, // SqlState = '37000' | |
226 | DB_ERR_DUPLICATE_CURSOR_NAME, // SqlState = '3C000' | |
227 | DB_ERR_SERIALIZATION_FAILURE, // SqlState = '40001' | |
228 | DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2, // SqlState = '42000' | |
229 | DB_ERR_OPERATION_ABORTED, // SqlState = '70100' | |
230 | DB_ERR_UNSUPPORTED_FUNCTION, // SqlState = 'IM001' | |
231 | DB_ERR_NO_DATA_SOURCE, // SqlState = 'IM002' | |
232 | DB_ERR_DRIVER_LOAD_ERROR, // SqlState = 'IM003' | |
233 | DB_ERR_SQLALLOCENV_FAILED, // SqlState = 'IM004' | |
234 | DB_ERR_SQLALLOCCONNECT_FAILED, // SqlState = 'IM005' | |
235 | DB_ERR_SQLSETCONNECTOPTION_FAILED, // SqlState = 'IM006' | |
236 | DB_ERR_NO_DATA_SOURCE_DLG_PROHIB, // SqlState = 'IM007' | |
237 | DB_ERR_DIALOG_FAILED, // SqlState = 'IM008' | |
238 | DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL, // SqlState = 'IM009' | |
239 | DB_ERR_DATA_SOURCE_NAME_TOO_LONG, // SqlState = 'IM010' | |
240 | DB_ERR_DRIVER_NAME_TOO_LONG, // SqlState = 'IM011' | |
241 | DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR, // SqlState = 'IM012' | |
242 | DB_ERR_TRACE_FILE_ERROR, // SqlState = 'IM013' | |
243 | DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS, // SqlState = 'S0001' | |
244 | DB_ERR_TABLE_NOT_FOUND, // SqlState = 'S0002' | |
245 | DB_ERR_INDEX_ALREADY_EXISTS, // SqlState = 'S0011' | |
246 | DB_ERR_INDEX_NOT_FOUND, // SqlState = 'S0012' | |
247 | DB_ERR_COLUMN_ALREADY_EXISTS, // SqlState = 'S0021' | |
248 | DB_ERR_COLUMN_NOT_FOUND, // SqlState = 'S0022' | |
249 | DB_ERR_NO_DEFAULT_FOR_COLUMN, // SqlState = 'S0023' | |
250 | DB_ERR_GENERAL_ERROR, // SqlState = 'S1000' | |
251 | DB_ERR_MEMORY_ALLOCATION_FAILURE, // SqlState = 'S1001' | |
252 | DB_ERR_INVALID_COLUMN_NUMBER, // SqlState = 'S1002' | |
253 | DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE, // SqlState = 'S1003' | |
254 | DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE, // SqlState = 'S1004' | |
255 | DB_ERR_OPERATION_CANCELLED, // SqlState = 'S1008' | |
256 | DB_ERR_INVALID_ARGUMENT_VALUE, // SqlState = 'S1009' | |
257 | DB_ERR_FUNCTION_SEQUENCE_ERROR, // SqlState = 'S1010' | |
258 | DB_ERR_OPERATION_INVALID_AT_THIS_TIME, // SqlState = 'S1011' | |
259 | DB_ERR_INVALID_TRANS_OPERATION_CODE, // SqlState = 'S1012' | |
260 | DB_ERR_NO_CURSOR_NAME_AVAIL, // SqlState = 'S1015' | |
261 | DB_ERR_INVALID_STR_OR_BUF_LEN, // SqlState = 'S1090' | |
262 | DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE, // SqlState = 'S1091' | |
263 | DB_ERR_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1092' | |
264 | DB_ERR_INVALID_PARAM_NO, // SqlState = 'S1093' | |
265 | DB_ERR_INVALID_SCALE_VALUE, // SqlState = 'S1094' | |
266 | DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1095' | |
267 | DB_ERR_INF_TYPE_OUT_OF_RANGE, // SqlState = 'S1096' | |
268 | DB_ERR_COLUMN_TYPE_OUT_OF_RANGE, // SqlState = 'S1097' | |
269 | DB_ERR_SCOPE_TYPE_OUT_OF_RANGE, // SqlState = 'S1098' | |
270 | DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE, // SqlState = 'S1099' | |
271 | DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1100' | |
272 | DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1101' | |
273 | DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE, // SqlState = 'S1103' | |
274 | DB_ERR_INVALID_PRECISION_VALUE, // SqlState = 'S1104' | |
275 | DB_ERR_INVALID_PARAM_TYPE, // SqlState = 'S1105' | |
276 | DB_ERR_FETCH_TYPE_OUT_OF_RANGE, // SqlState = 'S1106' | |
277 | DB_ERR_ROW_VALUE_OUT_OF_RANGE, // SqlState = 'S1107' | |
278 | DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE, // SqlState = 'S1108' | |
279 | DB_ERR_INVALID_CURSOR_POSITION, // SqlState = 'S1109' | |
280 | DB_ERR_INVALID_DRIVER_COMPLETION, // SqlState = 'S1110' | |
281 | DB_ERR_INVALID_BOOKMARK_VALUE, // SqlState = 'S1111' | |
282 | DB_ERR_DRIVER_NOT_CAPABLE, // SqlState = 'S1C00' | |
283 | DB_ERR_TIMEOUT_EXPIRED // SqlState = 'S1T00' | |
108106cf JS |
284 | }; |
285 | ||
5cf34cf0 | 286 | #ifndef MAXNAME |
f3df29e3 | 287 | #define MAXNAME 31 |
5cf34cf0 GT |
288 | #endif |
289 | ||
290 | #ifndef SQL_MAX_AUTHSTR_LEN | |
f3df29e3 GT |
291 | // There does not seem to be a standard for this, so I am |
292 | // defaulting to the value that MS uses | |
293 | #define SQL_MAX_AUTHSTR_LEN MAXNAME | |
5cf34cf0 | 294 | #endif |
95ca6a20 | 295 | |
0907ea9c GT |
296 | #ifndef SQL_MAX_CONNECTSTR_LEN |
297 | // There does not seem to be a standard for this, so I am | |
298 | // defaulting to the value that MS recommends | |
299 | #define SQL_MAX_CONNECTSTR_LEN 1024 | |
300 | #endif | |
301 | ||
302 | ||
bb41dcbe | 303 | class WXDLLIMPEXP_ODBC wxDbConnectInf |
108106cf | 304 | { |
5cf34cf0 GT |
305 | private: |
306 | bool freeHenvOnDestroy; | |
0907ea9c | 307 | bool useConnectionStr; |
a2115c88 | 308 | |
5cf34cf0 | 309 | public: |
2f971924 GT |
310 | HENV Henv; |
311 | wxChar Dsn[SQL_MAX_DSN_LENGTH+1]; // Data Source Name | |
312 | wxChar Uid[SQL_MAX_USER_NAME_LEN+1]; // User ID | |
313 | wxChar AuthStr[SQL_MAX_AUTHSTR_LEN+1]; // Authorization string (password) | |
0907ea9c | 314 | wxChar ConnectionStr[SQL_MAX_CONNECTSTR_LEN+1]; // Connection string (password) |
5cf34cf0 GT |
315 | |
316 | wxString Description; // Not sure what the max length is | |
317 | wxString FileType; // Not sure what the max length is | |
318 | ||
319 | // Optionals needed for some databases like dBase | |
320 | wxString DefaultDir; // Directory that db file resides in | |
321 | ||
322 | public: | |
323 | ||
324 | wxDbConnectInf(); | |
68379eaf WS |
325 | wxDbConnectInf(HENV henv, const wxString &dsn, const wxString &userID=wxEmptyString, |
326 | const wxString &password=wxEmptyString, const wxString &defaultDir=wxEmptyString, | |
da99271d | 327 | const wxString &description=wxEmptyString, const wxString &fileType=wxEmptyString); |
5cf34cf0 GT |
328 | |
329 | ~wxDbConnectInf(); | |
330 | ||
331 | bool Initialize(); | |
332 | ||
333 | bool AllocHenv(); | |
334 | void FreeHenv(); | |
335 | ||
336 | // Accessors | |
6a71ee86 | 337 | const HENV &GetHenv() { return Henv; }; |
5cf34cf0 GT |
338 | |
339 | const wxChar *GetDsn() { return Dsn; }; | |
340 | ||
341 | const wxChar *GetUid() { return Uid; }; | |
342 | const wxChar *GetUserID() { return Uid; }; | |
343 | ||
344 | const wxChar *GetAuthStr() { return AuthStr; }; | |
345 | const wxChar *GetPassword() { return AuthStr; }; | |
346 | ||
0907ea9c GT |
347 | const wxChar *GetConnectionStr() { return ConnectionStr; }; |
348 | bool UseConnectionStr() { return useConnectionStr; }; | |
349 | ||
5cf34cf0 GT |
350 | const wxChar *GetDescription() { return Description; }; |
351 | const wxChar *GetFileType() { return FileType; }; | |
352 | const wxChar *GetDefaultDir() { return DefaultDir; }; | |
353 | ||
354 | void SetHenv(const HENV henv) { Henv = henv; }; | |
355 | ||
356 | void SetDsn(const wxString &dsn); | |
357 | ||
358 | void SetUserID(const wxString &userID); | |
359 | void SetUid(const wxString &uid) { SetUserID(uid); }; | |
360 | ||
361 | void SetPassword(const wxString &password); | |
362 | void SetAuthStr(const wxString &authstr) { SetPassword(authstr); }; | |
363 | ||
0907ea9c GT |
364 | void SetConnectionStr(const wxString &connectStr); |
365 | ||
5cf34cf0 GT |
366 | void SetDescription(const wxString &desc) { Description = desc; }; |
367 | void SetFileType(const wxString &fileType) { FileType = fileType; }; | |
368 | void SetDefaultDir(const wxString &defDir) { DefaultDir = defDir; }; | |
369 | }; // class wxDbConnectInf | |
a2115c88 | 370 | |
108106cf | 371 | |
bb41dcbe | 372 | struct WXDLLIMPEXP_ODBC wxDbSqlTypeInfo |
108106cf | 373 | { |
4fdae997 | 374 | wxString TypeName; |
02cf6fdd | 375 | SWORD FsqlType; |
4fdae997 GT |
376 | long Precision; |
377 | short CaseSensitive; | |
4fdae997 | 378 | short MaximumScale; |
fdc03678 | 379 | }; |
108106cf | 380 | |
95ca6a20 | 381 | |
bb41dcbe | 382 | class WXDLLIMPEXP_ODBC wxDbColFor |
30a6d2d2 | 383 | { |
95ca6a20 | 384 | public: |
90e572f1 MR |
385 | wxString s_Field; // Formatted String for Output |
386 | wxString s_Format[7]; // Formatted Objects - TIMESTAMP has the biggest (7) | |
387 | wxString s_Amount[7]; // Formatted Objects - amount of things that can be formatted | |
388 | int i_Amount[7]; // Formatted Objects - TT MM YYYY HH MM SS m | |
5cf34cf0 GT |
389 | int i_Nation; // 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US |
390 | int i_dbDataType; // conversion of the 'sqlDataType' to the generic data type used by these classes | |
95ca6a20 GT |
391 | SWORD i_sqlDataType; |
392 | ||
f6bcfd97 | 393 | wxDbColFor(); |
1b941f2d | 394 | ~wxDbColFor(){} |
595b5c4e | 395 | |
6a71ee86 | 396 | void Initialize(); |
e4e45573 | 397 | int Format(int Nation, int dbDataType, SWORD sqlDataType, short columnLength, short decimalDigits); |
30a6d2d2 GT |
398 | }; |
399 | ||
95ca6a20 | 400 | |
bb41dcbe | 401 | class WXDLLIMPEXP_ODBC wxDbColInf |
108106cf JS |
402 | { |
403 | public: | |
4fdae997 GT |
404 | wxChar catalog[128+1]; |
405 | wxChar schema[128+1]; | |
406 | wxChar tableName[DB_MAX_TABLE_NAME_LEN+1]; | |
407 | wxChar colName[DB_MAX_COLUMN_NAME_LEN+1]; | |
95ca6a20 | 408 | SWORD sqlDataType; |
4fdae997 | 409 | wxChar typeName[128+1]; |
e4e45573 GT |
410 | SWORD columnLength; |
411 | SWORD bufferSize; | |
95ca6a20 GT |
412 | short decimalDigits; |
413 | short numPrecRadix; | |
414 | short nullable; | |
4fdae997 | 415 | wxChar remarks[254+1]; |
95ca6a20 | 416 | int dbDataType; // conversion of the 'sqlDataType' to the generic data type used by these classes |
30a6d2d2 GT |
417 | // mj10777.19991224 : new |
418 | int PkCol; // Primary key column 0=No; 1= First Key, 2 = Second Key etc. | |
4fdae997 | 419 | wxChar PkTableName[DB_MAX_TABLE_NAME_LEN+1]; // Tables that use this PKey as a FKey |
30a6d2d2 | 420 | int FkCol; // Foreign key column 0=No; 1= First Key, 2 = Second Key etc. |
4fdae997 | 421 | wxChar FkTableName[DB_MAX_TABLE_NAME_LEN+1]; // Foreign key table name |
f6bcfd97 | 422 | wxDbColFor *pColFor; // How should this columns be formatted |
3ca6a5f0 BP |
423 | |
424 | wxDbColInf(); | |
425 | ~wxDbColInf(); | |
da99271d GT |
426 | |
427 | bool Initialize(); | |
30a6d2d2 GT |
428 | }; |
429 | ||
95ca6a20 | 430 | |
bb41dcbe | 431 | class WXDLLIMPEXP_ODBC wxDbTableInf // Description of a Table |
95ca6a20 | 432 | { |
30a6d2d2 | 433 | public: |
4fdae997 GT |
434 | wxChar tableName[DB_MAX_TABLE_NAME_LEN+1]; |
435 | wxChar tableType[254+1]; // "TABLE" or "SYSTEM TABLE" etc. | |
436 | wxChar tableRemarks[254+1]; | |
02cf6fdd | 437 | UWORD numCols; // How many Columns does this Table have: GetColumnCount(..); |
f6bcfd97 | 438 | wxDbColInf *pColInf; // pColInf = NULL ; User can later call GetColumns(..); |
da99271d | 439 | |
3ca6a5f0 BP |
440 | wxDbTableInf(); |
441 | ~wxDbTableInf(); | |
da99271d GT |
442 | |
443 | bool Initialize(); | |
30a6d2d2 GT |
444 | }; |
445 | ||
95ca6a20 | 446 | |
bb41dcbe | 447 | class WXDLLIMPEXP_ODBC wxDbInf // Description of a Database |
95ca6a20 | 448 | { |
30a6d2d2 | 449 | public: |
4fdae997 GT |
450 | wxChar catalog[128+1]; |
451 | wxChar schema[128+1]; | |
f6bcfd97 BP |
452 | int numTables; // How many tables does this database have |
453 | wxDbTableInf *pTableInf; // pTableInf = new wxDbTableInf[numTables]; | |
3ca6a5f0 BP |
454 | |
455 | wxDbInf(); | |
456 | ~wxDbInf(); | |
6a71ee86 | 457 | |
da99271d | 458 | bool Initialize(); |
108106cf JS |
459 | }; |
460 | ||
95ca6a20 | 461 | |
f6bcfd97 | 462 | enum wxDbSqlLogState |
1fc5dd6f | 463 | { |
95ca6a20 GT |
464 | sqlLogOFF, |
465 | sqlLogON | |
1fc5dd6f JS |
466 | }; |
467 | ||
95ca6a20 | 468 | // These are the databases currently tested and working with these classes |
f6bcfd97 | 469 | // See the comments in wxDb::Dbms() for exceptions/issues with |
95ca6a20 | 470 | // each of these database engines |
fdc03678 | 471 | enum wxDBMS |
a2115c88 | 472 | { |
95ca6a20 GT |
473 | dbmsUNIDENTIFIED, |
474 | dbmsORACLE, | |
475 | dbmsSYBASE_ASA, // Adaptive Server Anywhere | |
476 | dbmsSYBASE_ASE, // Adaptive Server Enterprise | |
477 | dbmsMS_SQL_SERVER, | |
478 | dbmsMY_SQL, | |
479 | dbmsPOSTGRES, | |
480 | dbmsACCESS, | |
481 | dbmsDBASE, | |
f6bcfd97 | 482 | dbmsINFORMIX, |
e2f4e132 | 483 | dbmsVIRTUOSO, |
d8a0a1c9 | 484 | dbmsDB2, |
1b12ab16 | 485 | dbmsINTERBASE, |
9f4de2dc | 486 | dbmsPERVASIVE_SQL, |
215a0070 | 487 | dbmsXBASE_SEQUITER, |
2889677e GT |
488 | dbmsFIREBIRD, |
489 | dbmsMAXDB, | |
490 | dbmsFuture1, | |
491 | dbmsFuture2, | |
492 | dbmsFuture3, | |
493 | dbmsFuture4, | |
494 | dbmsFuture5, | |
495 | dbmsFuture6, | |
496 | dbmsFuture7, | |
497 | dbmsFuture8, | |
498 | dbmsFuture9, | |
499 | dbmsFuture10 | |
a2115c88 GT |
500 | }; |
501 | ||
95ca6a20 | 502 | |
f6bcfd97 | 503 | // The wxDb::errorList is copied to this variable when the wxDb object |
a2115c88 | 504 | // is closed. This way, the error list is still available after the |
595b5c4e | 505 | // database object is closed. This is necessary if the database |
a2115c88 | 506 | // connection fails so the calling application can show the operator |
f6bcfd97 BP |
507 | // why the connection failed. Note: as each wxDb object is closed, it |
508 | // will overwrite the errors of the previously destroyed wxDb object in | |
a2115c88 | 509 | // this variable. |
8a77c0d7 | 510 | |
16cba29d | 511 | extern WXDLLIMPEXP_DATA_ODBC(wxChar) |
580820e3 | 512 | DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN+1]; |
a2115c88 | 513 | |
95ca6a20 | 514 | |
bb41dcbe | 515 | class WXDLLIMPEXP_ODBC wxDb |
108106cf JS |
516 | { |
517 | private: | |
95ca6a20 | 518 | bool dbIsOpen; |
20987580 | 519 | bool dbIsCached; // Was connection created by caching functions |
0907ea9c | 520 | bool dbOpenedWithConnectionString; // Was the database connection opened with a connection string |
4fdae997 GT |
521 | wxString dsn; // Data source name |
522 | wxString uid; // User ID | |
523 | wxString authStr; // Authorization string (password) | |
0907ea9c GT |
524 | wxString inConnectionStr; // Connection string used to connect to the database |
525 | wxString outConnectionStr;// Connection string returned by the database when a connection is successfully opened | |
95ca6a20 | 526 | FILE *fpSqlLog; // Sql Log file pointer |
f6bcfd97 | 527 | wxDbSqlLogState sqlLogState; // On or Off |
95ca6a20 | 528 | bool fwdOnlyCursors; |
e2f4e132 | 529 | wxDBMS dbmsType; // Type of datasource - i.e. Oracle, dBase, SQLServer, etc |
95ca6a20 GT |
530 | |
531 | // Private member functions | |
68379eaf | 532 | bool getDbInfo(bool failOnDataTypeUnsupported=true); |
f6bcfd97 | 533 | bool getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo); |
95ca6a20 | 534 | bool setConnectionOptions(void); |
4fdae997 | 535 | void logError(const wxString &errMsg, const wxString &SQLState); |
4fdae997 | 536 | const wxChar *convertUserID(const wxChar *userID, wxString &UserID); |
5f72522e | 537 | bool determineDataTypes(bool failOnDataTypeUnsupported); |
da99271d | 538 | void initialize(); |
68379eaf | 539 | bool open(bool failOnDataTypeUnsupported=true); |
4fdae997 | 540 | |
f6bcfd97 BP |
541 | #if !wxODBC_BACKWARD_COMPATABILITY |
542 | // ODBC handles | |
543 | HENV henv; // ODBC Environment handle | |
544 | HDBC hdbc; // ODBC DB Connection handle | |
545 | HSTMT hstmt; // ODBC Statement handle | |
546 | ||
547 | //Error reporting mode | |
548 | bool silent; | |
549 | ||
550 | // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!! | |
551 | unsigned int nTables; | |
552 | ||
553 | // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE. | |
3ca6a5f0 | 554 | // |
f6bcfd97 BP |
555 | // This information is obtained from the ODBC driver by use of the |
556 | // SQLGetTypeInfo() function. The key piece of information is the | |
557 | // type name the data source uses for each logical data type. | |
558 | // e.g. VARCHAR; Oracle calls it VARCHAR2. | |
559 | wxDbSqlTypeInfo typeInfVarchar; | |
560 | wxDbSqlTypeInfo typeInfInteger; | |
561 | wxDbSqlTypeInfo typeInfFloat; | |
562 | wxDbSqlTypeInfo typeInfDate; | |
b742792c | 563 | wxDbSqlTypeInfo typeInfBlob; |
7eeba511 | 564 | wxDbSqlTypeInfo typeInfMemo; |
f6bcfd97 | 565 | #endif |
a3439c7d | 566 | |
108106cf | 567 | public: |
b742792c | 568 | |
20987580 GT |
569 | void setCached(bool cached) { dbIsCached = cached; }; // This function must only be called by wxDbGetConnection() and wxDbCloseConnections!!! |
570 | bool IsCached() { return dbIsCached; }; | |
571 | ||
b742792c GT |
572 | bool GetDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo) |
573 | { return getDataTypeInfo(fSqlType, structSQLTypeInfo); } | |
574 | ||
f6bcfd97 BP |
575 | #if wxODBC_BACKWARD_COMPATABILITY |
576 | // ODBC handles | |
577 | HENV henv; // ODBC Environment handle | |
578 | HDBC hdbc; // ODBC DB Connection handle | |
579 | HSTMT hstmt; // ODBC Statement handle | |
580 | ||
581 | //Error reporting mode | |
582 | bool silent; | |
583 | ||
584 | // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!! | |
585 | unsigned int nTables; | |
586 | #endif | |
587 | ||
95ca6a20 GT |
588 | // The following structure contains database information gathered from the |
589 | // datasource when the datasource is first opened. | |
590 | struct | |
591 | { | |
4fdae997 GT |
592 | wxChar dbmsName[40]; // Name of the dbms product |
593 | wxChar dbmsVer[64]; // Version # of the dbms product | |
594 | wxChar driverName[40]; // Driver name | |
595 | wxChar odbcVer[60]; // ODBC version of the driver | |
596 | wxChar drvMgrOdbcVer[60]; // ODBC version of the driver manager | |
597 | wxChar driverVer[60]; // Driver version | |
598 | wxChar serverName[80]; // Server Name, typically a connect string | |
599 | wxChar databaseName[128]; // Database filename | |
600 | wxChar outerJoins[2]; // Indicates whether the data source supports outer joins | |
601 | wxChar procedureSupport[2]; // Indicates whether the data source supports stored procedures | |
602 | wxChar accessibleTables[2]; // Indicates whether the data source only reports accessible tables in SQLTables. | |
95ca6a20 GT |
603 | UWORD maxConnections; // Maximum # of connections the data source supports |
604 | UWORD maxStmts; // Maximum # of HSTMTs per HDBC | |
605 | UWORD apiConfLvl; // ODBC API conformance level | |
606 | UWORD cliConfLvl; // Indicates whether the data source is SAG compliant | |
607 | UWORD sqlConfLvl; // SQL conformance level | |
608 | UWORD cursorCommitBehavior; // Indicates how cursors are affected by a db commit | |
609 | UWORD cursorRollbackBehavior; // Indicates how cursors are affected by a db rollback | |
610 | UWORD supportNotNullClause; // Indicates if data source supports NOT NULL clause | |
4fdae997 | 611 | wxChar supportIEF[2]; // Integrity Enhancement Facility (Referential Integrity) |
95ca6a20 GT |
612 | UDWORD txnIsolation; // Default transaction isolation level supported by the driver |
613 | UDWORD txnIsolationOptions; // Transaction isolation level options available | |
614 | UDWORD fetchDirections; // Fetch directions supported | |
615 | UDWORD lockTypes; // Lock types supported in SQLSetPos | |
616 | UDWORD posOperations; // Position operations supported in SQLSetPos | |
617 | UDWORD posStmts; // Position statements supported | |
618 | UDWORD scrollConcurrency; // Concurrency control options supported for scrollable cursors | |
619 | UDWORD scrollOptions; // Scroll Options supported for scrollable cursors | |
620 | UDWORD staticSensitivity; // Indicates if additions, deletions and updates can be detected | |
621 | UWORD txnCapable; // Indicates if the data source supports transactions | |
622 | UDWORD loginTimeout; // Number seconds to wait for a login request | |
623 | } dbInf; | |
624 | ||
95ca6a20 | 625 | // ODBC Error Inf. |
95ca6a20 | 626 | SWORD cbErrorMsg; |
95ca6a20 | 627 | int DB_STATUS; |
13973396 JJ |
628 | #ifdef __VMS |
629 | // The DECC compiler chokes when in db.cpp the array is accessed outside | |
630 | // its bounds. Maybe this change should also applied for other platforms. | |
631 | wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN+1]; | |
632 | #else | |
f6bcfd97 | 633 | wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN]; |
13973396 | 634 | #endif |
f6bcfd97 | 635 | wxChar errorMsg[SQL_MAX_MESSAGE_LENGTH]; |
c497d0b2 | 636 | SQLINTEGER nativeError; |
f6bcfd97 | 637 | wxChar sqlState[20]; |
95ca6a20 | 638 | |
f6bcfd97 BP |
639 | #if wxODBC_BACKWARD_COMPATABILITY |
640 | // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE. | |
3ca6a5f0 | 641 | // |
f6bcfd97 BP |
642 | // This information is obtained from the ODBC driver by use of the |
643 | // SQLGetTypeInfo() function. The key piece of information is the | |
95ca6a20 GT |
644 | // type name the data source uses for each logical data type. |
645 | // e.g. VARCHAR; Oracle calls it VARCHAR2. | |
f6bcfd97 BP |
646 | wxDbSqlTypeInfo typeInfVarchar; |
647 | wxDbSqlTypeInfo typeInfInteger; | |
648 | wxDbSqlTypeInfo typeInfFloat; | |
649 | wxDbSqlTypeInfo typeInfDate; | |
b742792c | 650 | wxDbSqlTypeInfo typeInfBlob; |
f6bcfd97 | 651 | #endif |
595b5c4e | 652 | |
95ca6a20 | 653 | // Public member functions |
6a71ee86 | 654 | wxDb(const HENV &aHenv, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS); |
20987580 | 655 | ~wxDb(); |
5cf34cf0 | 656 | |
e25cdb86 | 657 | // Data Source Name, User ID, Password and whether open should fail on data type not supported |
68379eaf | 658 | bool Open(const wxString& inConnectStr, bool failOnDataTypeUnsupported=true); |
11bfe4bf VZ |
659 | ///This version of Open will open the odbc source selection dialog. Cast a wxWindow::GetHandle() to SQLHWND to use. |
660 | bool Open(const wxString& inConnectStr, SQLHWND parentWnd, bool failOnDataTypeUnsupported=true); | |
68379eaf WS |
661 | bool Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr, bool failOnDataTypeUnsupported=true); |
662 | bool Open(wxDbConnectInf *dbConnectInf, bool failOnDataTypeUnsupported=true); | |
e2f4e132 | 663 | bool Open(wxDb *copyDb); // pointer to a wxDb whose connection info should be copied rather than re-queried |
95ca6a20 GT |
664 | void Close(void); |
665 | bool CommitTrans(void); | |
666 | bool RollbackTrans(void); | |
667 | bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); | |
668 | bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); | |
669 | void DispNextError(void); | |
68379eaf | 670 | bool CreateView(const wxString &viewName, const wxString &colList, const wxString &pSqlStmt, bool attemptDrop=true); |
4fdae997 GT |
671 | bool DropView(const wxString &viewName); |
672 | bool ExecSql(const wxString &pSqlStmt); | |
f110f395 | 673 | bool ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcols); |
95ca6a20 | 674 | bool GetNext(void); |
e716b9be | 675 | bool GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SQLLEN FAR *cbReturned); |
4fdae997 GT |
676 | bool Grant(int privileges, const wxString &tableName, const wxString &userList = wxT("PUBLIC")); |
677 | int TranslateSqlState(const wxString &SQLState); | |
678 | wxDbInf *GetCatalog(const wxChar *userID=NULL); | |
679 | bool Catalog(const wxChar *userID=NULL, const wxString &fileName=SQL_CATALOG_FILENAME); | |
02cf6fdd | 680 | int GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCols); |
4fdae997 GT |
681 | |
682 | wxDbColInf *GetColumns(wxChar *tableName[], const wxChar *userID=NULL); | |
68379eaf | 683 | wxDbColInf *GetColumns(const wxString &tableName, UWORD *numCols, const wxChar *userID=NULL); |
4fdae997 | 684 | |
dba2120c | 685 | int GetColumnCount(const wxString &tableName, const wxChar *userID=NULL); |
b742792c | 686 | const wxChar *GetDatabaseName(void) {return dbInf.dbmsName;} |
4fdae997 GT |
687 | const wxString &GetDataSource(void) {return dsn;} |
688 | const wxString &GetDatasourceName(void){return dsn;} | |
689 | const wxString &GetUsername(void) {return uid;} | |
690 | const wxString &GetPassword(void) {return authStr;} | |
0907ea9c GT |
691 | const wxString &GetConnectionInStr(void) {return inConnectionStr;} |
692 | const wxString &GetConnectionOutStr(void) {return outConnectionStr;} | |
b742792c | 693 | bool IsOpen(void) {return dbIsOpen;} |
0907ea9c | 694 | bool OpenedWithConnectionString(void) {return dbOpenedWithConnectionString;} |
b742792c GT |
695 | HENV GetHENV(void) {return henv;} |
696 | HDBC GetHDBC(void) {return hdbc;} | |
697 | HSTMT GetHSTMT(void) {return hstmt;} | |
698 | int GetTableCount() {return nTables;} // number of tables using this connection | |
699 | wxDbSqlTypeInfo GetTypeInfVarchar() {return typeInfVarchar;} | |
700 | wxDbSqlTypeInfo GetTypeInfInteger() {return typeInfInteger;} | |
701 | wxDbSqlTypeInfo GetTypeInfFloat() {return typeInfFloat;} | |
702 | wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;} | |
703 | wxDbSqlTypeInfo GetTypeInfBlob() {return typeInfBlob;} | |
7eeba511 | 704 | wxDbSqlTypeInfo GetTypeInfMemo() {return typeInfMemo;} |
b742792c GT |
705 | |
706 | // tableName can refer to a table, view, alias or synonym | |
68379eaf | 707 | bool TableExists(const wxString &tableName, const wxChar *userID=NULL, |
b742792c | 708 | const wxString &tablePath=wxEmptyString); |
68379eaf WS |
709 | bool TablePrivileges(const wxString &tableName, const wxString &priv, |
710 | const wxChar *userID=NULL, const wxChar *schema=NULL, | |
b742792c GT |
711 | const wxString &path=wxEmptyString); |
712 | ||
243d4b36 GT |
713 | // These two functions return the table name or column name in a form ready |
714 | // for use in SQL statements. For example, if the datasource allows spaces | |
715 | // in the table name or column name, the returned string will have the | |
68379eaf | 716 | // correct enclosing marks around the name to allow it to be properly |
243d4b36 | 717 | // included in a SQL statement |
5bdad317 GT |
718 | const wxString SQLTableName(const wxChar *tableName); |
719 | const wxString SQLColumnName(const wxChar *colName); | |
243d4b36 | 720 | |
68379eaf | 721 | void LogError(const wxString &errMsg, const wxString &SQLState = wxEmptyString) |
b742792c | 722 | { logError(errMsg, SQLState); } |
f6bcfd97 | 723 | void SetDebugErrorMessages(bool state) { silent = !state; } |
68379eaf WS |
724 | bool SetSqlLogging(wxDbSqlLogState state, const wxString &filename = SQL_LOG_FILENAME, |
725 | bool append = false); | |
4fdae997 | 726 | bool WriteSqlLog(const wxString &logMsg); |
b742792c | 727 | |
fdc03678 | 728 | wxDBMS Dbms(void); |
4fdae997 GT |
729 | bool ModifyColumn(const wxString &tableName, const wxString &columnName, |
730 | int dataType, ULONG columnLength=0, | |
da99271d | 731 | const wxString &optionalParam=wxEmptyString); |
4fdae997 | 732 | |
f6bcfd97 BP |
733 | bool FwdOnlyCursors(void) {return fwdOnlyCursors;} |
734 | ||
9eb11d19 VZ |
735 | // return the string with all special SQL characters escaped |
736 | wxString EscapeSqlChars(const wxString& value); | |
737 | ||
f6bcfd97 BP |
738 | // These two functions are provided strictly for use by wxDbTable. |
739 | // DO NOT USE THESE FUNCTIONS, OR MEMORY LEAKS MAY OCCUR | |
740 | void incrementTableCount() { nTables++; return; } | |
741 | void decrementTableCount() { nTables--; return; } | |
742 | ||
743 | }; // wxDb | |
108106cf | 744 | |
fdc03678 | 745 | |
108106cf JS |
746 | // This structure forms a node in a linked list. The linked list of "DbList" objects |
747 | // keeps track of allocated database connections. This allows the application to | |
748 | // open more than one database connection through ODBC for multiple transaction support | |
749 | // or for multiple database support. | |
fdc03678 | 750 | struct wxDbList |
108106cf | 751 | { |
4fdae997 GT |
752 | wxDbList *PtrPrev; // Pointer to previous item in the list |
753 | wxString Dsn; // Data Source Name | |
754 | wxString Uid; // User ID | |
755 | wxString AuthStr; // Authorization string (password) | |
0907ea9c | 756 | wxString ConnectionStr; // Connection string used instead of DSN |
4fdae997 GT |
757 | wxDb *PtrDb; // Pointer to the wxDb object |
758 | bool Free; // Is item free or in use? | |
759 | wxDbList *PtrNext; // Pointer to next item in the list | |
108106cf JS |
760 | }; |
761 | ||
5cf34cf0 | 762 | |
154f22b3 | 763 | #ifdef __WXDEBUG__ |
e115e771 | 764 | #include "wx/object.h" |
fdc03678 | 765 | class wxTablesInUse : public wxObject |
a2115c88 | 766 | { |
95ca6a20 | 767 | public: |
4fdae997 | 768 | const wxChar *tableName; |
95ca6a20 | 769 | ULONG tableID; |
f6bcfd97 | 770 | class wxDb *pDb; |
fdc03678 | 771 | }; // wxTablesInUse |
a2115c88 GT |
772 | #endif |
773 | ||
fdc03678 | 774 | |
108106cf JS |
775 | // The following routines allow a user to get new database connections, free them |
776 | // for other code segments to use, or close all of them when the application has | |
777 | // completed. | |
bb41dcbe VS |
778 | wxDb WXDLLIMPEXP_ODBC *wxDbGetConnection(wxDbConnectInf *pDbConfig, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS); |
779 | bool WXDLLIMPEXP_ODBC wxDbFreeConnection(wxDb *pDb); | |
780 | void WXDLLIMPEXP_ODBC wxDbCloseConnections(void); | |
781 | int WXDLLIMPEXP_ODBC wxDbConnectionsInUse(void); | |
95ca6a20 | 782 | |
108106cf | 783 | |
20987580 GT |
784 | // Writes a message to the wxLog window (stdout usually) when an internal error |
785 | // situation occurs. This function only works in DEBUG builds | |
f157ad08 | 786 | const wxChar WXDLLIMPEXP_ODBC * |
886dd7d2 VZ |
787 | wxDbLogExtendedErrorMsg(const wxChar *userText, |
788 | wxDb *pDb, | |
789 | const wxChar *ErrFile, | |
790 | int ErrLine); | |
5bdad317 | 791 | |
20987580 | 792 | |
f6bcfd97 | 793 | // This function sets the sql log state for all open wxDb objects |
bb41dcbe | 794 | bool WXDLLIMPEXP_ODBC |
886dd7d2 | 795 | wxDbSqlLog(wxDbSqlLogState state, const wxString &filename = SQL_LOG_FILENAME); |
fdc03678 | 796 | |
95ca6a20 | 797 | |
fdc03678 GT |
798 | #if 0 |
799 | // MSW/VC6 ONLY!!! Experimental | |
da99271d | 800 | int WXDLLEXPORT wxDbCreateDataSource(const wxString &driverName, const wxString &dsn, const wxString &description=wxEmptyString, |
68379eaf | 801 | bool sysDSN=false, const wxString &defDir=wxEmptyString, wxWindow *parent=NULL); |
fdc03678 | 802 | #endif |
a2115c88 | 803 | |
108106cf JS |
804 | // This routine allows you to query a driver manager |
805 | // for a list of available datasources. Call this routine | |
806 | // the first time using SQL_FETCH_FIRST. Continue to call it | |
807 | // using SQL_FETCH_NEXT until you've exhausted the list. | |
bb41dcbe | 808 | bool WXDLLIMPEXP_ODBC |
e4e45573 GT |
809 | wxDbGetDataSource(HENV henv, wxChar *Dsn, SWORD DsnMaxLength, wxChar *DsDesc, |
810 | SWORD DsDescMaxLength, UWORD direction = SQL_FETCH_NEXT); | |
fdc03678 GT |
811 | |
812 | ||
813 | // Change this to 0 to remove use of all deprecated functions | |
f6bcfd97 | 814 | #if wxODBC_BACKWARD_COMPATABILITY |
fdc03678 | 815 | //################################################################################# |
3103e8a9 | 816 | //############### DEPRECATED functions for backward compatibility ################# |
fdc03678 GT |
817 | //################################################################################# |
818 | ||
819 | // Backward compability structures/classes. This will eventually go away | |
f6bcfd97 BP |
820 | const int DB_PATH_MAX = wxDB_PATH_MAX; |
821 | ||
822 | typedef wxDb wxDB; | |
823 | typedef wxDbTableInf wxTableInf; | |
824 | typedef wxDbColInf wxColInf; | |
825 | typedef wxDbColInf CcolInf; | |
826 | typedef wxDbColFor wxColFor; | |
827 | typedef wxDbSqlTypeInfo SqlTypeInfo; | |
828 | typedef wxDbSqlTypeInfo wxSqlTypeInfo; | |
829 | typedef enum wxDbSqlLogState sqlLog; | |
830 | typedef enum wxDbSqlLogState wxSqlLogState; | |
831 | typedef enum wxDBMS dbms; | |
832 | typedef enum wxDBMS DBMS; | |
833 | typedef wxODBC_ERRORS ODBC_ERRORS; | |
834 | typedef wxDbConnectInf DbStuff; | |
835 | typedef wxDbList DbList; | |
27508856 | 836 | #ifdef __WXDEBUG__ |
f6bcfd97 | 837 | typedef wxTablesInUse CstructTablesInUse; |
27508856 | 838 | #endif |
fdc03678 GT |
839 | |
840 | // Deprecated function names that are replaced by the function names listed above | |
bb41dcbe | 841 | wxDB WXDLLIMPEXP_ODBC |
886dd7d2 | 842 | *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS); |
bb41dcbe VS |
843 | bool WXDLLIMPEXP_ODBC FreeDbConnection(wxDB *pDb); |
844 | void WXDLLIMPEXP_ODBC CloseDbConnections(void); | |
845 | int WXDLLIMPEXP_ODBC NumberDbConnectionsInUse(void); | |
fdc03678 | 846 | |
2b5f62a0 | 847 | bool SqlLog(sqlLog state, const wxChar *filename = SQL_LOG_FILENAME); |
fdc03678 | 848 | |
bb41dcbe | 849 | bool WXDLLIMPEXP_ODBC |
e4e45573 | 850 | GetDataSource(HENV henv, char *Dsn, SWORD DsnMaxLength, char *DsDesc, SWORD DsDescMaxLength, |
886dd7d2 VZ |
851 | UWORD direction = SQL_FETCH_NEXT); |
852 | ||
fdc03678 | 853 | #endif // Deprecated structures/classes/functions |
108106cf | 854 | |
2b5f62a0 VZ |
855 | #endif // _WX_DB_H_ |
856 |