]>
Commit | Line | Data |
---|---|---|
108106cf JS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: db.h | |
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 | |
5 | // source such as opening and closing the data source. | |
6 | // Author: Doug Card | |
30a6d2d2 | 7 | // Modified by: George Tasker |
a2115c88 GT |
8 | // Mods: Dec, 1998: |
9 | // -Added support for SQL statement logging and database cataloging | |
10 | // April, 1999 | |
11 | // -Added QUERY_ONLY mode support to reduce default number of cursors | |
12 | // -Added additional SQL logging code | |
13 | // -Added DEBUG-ONLY tracking of Ctable objects to detect orphaned DB connections | |
14 | // -Set ODBC option to only read committed writes to the DB so all | |
15 | // databases operate the same in that respect | |
16 | // | |
108106cf JS |
17 | // Created: 9.96 |
18 | // RCS-ID: $Id$ | |
19 | // Copyright: (c) 1996 Remstar International, Inc. | |
20 | // Licence: wxWindows licence, plus: | |
a2115c88 | 21 | // Notice: This class library and its intellectual design are free of charge for use, |
108106cf JS |
22 | // modification, enhancement, debugging under the following conditions: |
23 | // 1) These classes may only be used as part of the implementation of a | |
24 | // wxWindows-based application | |
25 | // 2) All enhancements and bug fixes are to be submitted back to the wxWindows | |
26 | // user groups free of all charges for use with the wxWindows library. | |
27 | // 3) These classes may not be distributed as part of any other class library, | |
28 | // DLL, text (written or electronic), other than a complete distribution of | |
29 | // the wxWindows GUI development toolkit. | |
1fc5dd6f | 30 | // |
108106cf JS |
31 | /////////////////////////////////////////////////////////////////////////////// |
32 | ||
33 | /* | |
34 | // SYNOPSIS START | |
35 | // SYNOPSIS STOP | |
36 | */ | |
37 | ||
38 | #ifndef DB_DOT_H | |
39 | #define DB_DOT_H | |
a2115c88 GT |
40 | |
41 | // Use this line for wxWindows v1.x | |
42 | //#include "wx_ver.h" | |
43 | // Use this line for wxWindows v2.x | |
44 | #include "wx/version.h" | |
45 | ||
46 | #if wxMAJOR_VERSION == 2 | |
47 | #ifdef __GNUG__ | |
48 | #pragma interface "db.h" | |
49 | #endif | |
108106cf JS |
50 | #endif |
51 | ||
16b52fa1 RR |
52 | #include "wx/setup.h" |
53 | ||
a2115c88 GT |
54 | #if wxMAJOR_VERSION == 2 |
55 | extern "C" { | |
16b52fa1 RR |
56 | #include "wx/isql.h" |
57 | #include "wx/isqlext.h" | |
a2115c88 GT |
58 | } |
59 | #else // version == 1 | |
60 | extern "C" { | |
61 | #include "iodbc.h" | |
62 | #include "isqlext.h" | |
63 | } | |
64 | #endif | |
30a6d2d2 | 65 | |
a2115c88 GT |
66 | typedef float SFLOAT; |
67 | typedef double SDOUBLE; | |
68 | typedef unsigned int UINT; | |
69 | #define ULONG UDWORD | |
e5ad8528 | 70 | /* |
30a6d2d2 | 71 | #ifdef __UNIX__ |
d194ddf2 GT |
72 | # ifndef strnicmp |
73 | # define strnicmp strncasecmp | |
74 | # endif | |
75 | # ifndef stricmp | |
76 | # define stricmp strcasecmp | |
77 | # endif | |
e7549107 | 78 | #elif defined(__WXMAC__) |
d194ddf2 GT |
79 | #else |
80 | # include <io.h> | |
a2115c88 | 81 | #endif |
30a6d2d2 GT |
82 | */ |
83 | ||
84 | #ifndef wxODBC_FWD_ONLY_CURSORS | |
85 | #define wxODBC_FWD_ONLY_CURSORS 1 | |
86 | #endif | |
87 | ||
7e616b10 | 88 | |
a2115c88 | 89 | enum enumDummy {enumDum1}; |
7e616b10 | 90 | |
a2115c88 GT |
91 | #define SQL_C_BOOLEAN(datatype) (sizeof(datatype) == 1 ? SQL_C_UTINYINT : (sizeof(datatype) == 2 ? SQL_C_USHORT : SQL_C_ULONG)) |
92 | // #define SQL_C_BOOLEAN (sizeof(Bool) == 2 ? SQL_C_USHORT : SQL_C_ULONG) | |
7e616b10 | 93 | |
a2115c88 | 94 | #define SQL_C_ENUM (sizeof(enumDummy) == 2 ? SQL_C_USHORT : SQL_C_ULONG) |
108106cf | 95 | |
a2115c88 GT |
96 | #ifndef TRUE |
97 | #define TRUE 1 | |
7e616b10 RR |
98 | #endif |
99 | ||
a2115c88 GT |
100 | #ifndef FALSE |
101 | #define FALSE 0 | |
102 | #endif | |
108106cf | 103 | |
a2115c88 | 104 | const int DB_PATH_MAX = 254; |
108106cf | 105 | |
108106cf | 106 | // Database Globals |
7e616b10 | 107 | const int DB_TYPE_NAME_LEN = 40; |
a2115c88 GT |
108 | const int DB_MAX_STATEMENT_LEN = 2048; |
109 | const int DB_MAX_WHERE_CLAUSE_LEN = 1024; | |
110 | const int DB_MAX_ERROR_MSG_LEN = 512; | |
111 | const int DB_MAX_ERROR_HISTORY = 5; | |
7e616b10 RR |
112 | const int DB_MAX_TABLE_NAME_LEN = 128; |
113 | const int DB_MAX_COLUMN_NAME_LEN = 128; | |
114 | ||
a2115c88 GT |
115 | const int DB_DATA_TYPE_VARCHAR = 1; |
116 | const int DB_DATA_TYPE_INTEGER = 2; | |
7e616b10 | 117 | const int DB_DATA_TYPE_FLOAT = 3; |
a2115c88 | 118 | const int DB_DATA_TYPE_DATE = 4; |
7e616b10 RR |
119 | |
120 | const int DB_SELECT_KEYFIELDS = 1; | |
121 | const int DB_SELECT_WHERE = 2; | |
122 | const int DB_SELECT_MATCHING = 3; | |
123 | const int DB_SELECT_STATEMENT = 4; | |
124 | ||
125 | const int DB_UPD_KEYFIELDS = 1; | |
126 | const int DB_UPD_WHERE = 2; | |
127 | ||
128 | const int DB_DEL_KEYFIELDS = 1; | |
129 | const int DB_DEL_WHERE = 2; | |
130 | const int DB_DEL_MATCHING = 3; | |
131 | ||
132 | const int DB_WHERE_KEYFIELDS = 1; | |
a2115c88 | 133 | const int DB_WHERE_MATCHING = 2; |
7e616b10 RR |
134 | |
135 | const int DB_GRANT_SELECT = 1; | |
136 | const int DB_GRANT_INSERT = 2; | |
137 | const int DB_GRANT_UPDATE = 4; | |
138 | const int DB_GRANT_DELETE = 8; | |
139 | const int DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT | DB_GRANT_UPDATE | DB_GRANT_DELETE; | |
108106cf JS |
140 | |
141 | // ODBC Error codes (derived from ODBC SqlState codes) | |
142 | enum ODBC_ERRORS | |
143 | { | |
a2115c88 GT |
144 | DB_FAILURE = 0, |
145 | DB_SUCCESS = 1, | |
108106cf JS |
146 | DB_ERR_NOT_IN_USE, |
147 | DB_ERR_GENERAL_WARNING, // SqlState = '01000' | |
148 | DB_ERR_DISCONNECT_ERROR, // SqlState = '01002' | |
149 | DB_ERR_DATA_TRUNCATED, // SqlState = '01004' | |
150 | DB_ERR_PRIV_NOT_REVOKED, // SqlState = '01006' | |
151 | DB_ERR_INVALID_CONN_STR_ATTR, // SqlState = '01S00' | |
152 | DB_ERR_ERROR_IN_ROW, // SqlState = '01S01' | |
153 | DB_ERR_OPTION_VALUE_CHANGED, // SqlState = '01S02' | |
154 | DB_ERR_NO_ROWS_UPD_OR_DEL, // SqlState = '01S03' | |
155 | DB_ERR_MULTI_ROWS_UPD_OR_DEL, // SqlState = '01S04' | |
156 | DB_ERR_WRONG_NO_OF_PARAMS, // SqlState = '07001' | |
157 | DB_ERR_DATA_TYPE_ATTR_VIOL, // SqlState = '07006' | |
158 | DB_ERR_UNABLE_TO_CONNECT, // SqlState = '08001' | |
159 | DB_ERR_CONNECTION_IN_USE, // SqlState = '08002' | |
160 | DB_ERR_CONNECTION_NOT_OPEN, // SqlState = '08003' | |
161 | DB_ERR_REJECTED_CONNECTION, // SqlState = '08004' | |
162 | DB_ERR_CONN_FAIL_IN_TRANS, // SqlState = '08007' | |
163 | DB_ERR_COMM_LINK_FAILURE, // SqlState = '08S01' | |
164 | DB_ERR_INSERT_VALUE_LIST_MISMATCH, // SqlState = '21S01' | |
165 | DB_ERR_DERIVED_TABLE_MISMATCH, // SqlState = '21S02' | |
166 | DB_ERR_STRING_RIGHT_TRUNC, // SqlState = '22001' | |
167 | DB_ERR_NUMERIC_VALUE_OUT_OF_RNG, // SqlState = '22003' | |
168 | DB_ERR_ERROR_IN_ASSIGNMENT, // SqlState = '22005' | |
169 | DB_ERR_DATETIME_FLD_OVERFLOW, // SqlState = '22008' | |
170 | DB_ERR_DIVIDE_BY_ZERO, // SqlState = '22012' | |
171 | DB_ERR_STR_DATA_LENGTH_MISMATCH, // SqlState = '22026' | |
172 | DB_ERR_INTEGRITY_CONSTRAINT_VIOL, // SqlState = '23000' | |
173 | DB_ERR_INVALID_CURSOR_STATE, // SqlState = '24000' | |
174 | DB_ERR_INVALID_TRANS_STATE, // SqlState = '25000' | |
175 | DB_ERR_INVALID_AUTH_SPEC, // SqlState = '28000' | |
176 | DB_ERR_INVALID_CURSOR_NAME, // SqlState = '34000' | |
177 | DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL, // SqlState = '37000' | |
178 | DB_ERR_DUPLICATE_CURSOR_NAME, // SqlState = '3C000' | |
179 | DB_ERR_SERIALIZATION_FAILURE, // SqlState = '40001' | |
180 | DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2, // SqlState = '42000' | |
181 | DB_ERR_OPERATION_ABORTED, // SqlState = '70100' | |
182 | DB_ERR_UNSUPPORTED_FUNCTION, // SqlState = 'IM001' | |
183 | DB_ERR_NO_DATA_SOURCE, // SqlState = 'IM002' | |
184 | DB_ERR_DRIVER_LOAD_ERROR, // SqlState = 'IM003' | |
185 | DB_ERR_SQLALLOCENV_FAILED, // SqlState = 'IM004' | |
186 | DB_ERR_SQLALLOCCONNECT_FAILED, // SqlState = 'IM005' | |
187 | DB_ERR_SQLSETCONNECTOPTION_FAILED, // SqlState = 'IM006' | |
188 | DB_ERR_NO_DATA_SOURCE_DLG_PROHIB, // SqlState = 'IM007' | |
189 | DB_ERR_DIALOG_FAILED, // SqlState = 'IM008' | |
190 | DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL, // SqlState = 'IM009' | |
191 | DB_ERR_DATA_SOURCE_NAME_TOO_LONG, // SqlState = 'IM010' | |
192 | DB_ERR_DRIVER_NAME_TOO_LONG, // SqlState = 'IM011' | |
193 | DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR, // SqlState = 'IM012' | |
194 | DB_ERR_TRACE_FILE_ERROR, // SqlState = 'IM013' | |
195 | DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS, // SqlState = 'S0001' | |
196 | DB_ERR_TABLE_NOT_FOUND, // SqlState = 'S0002' | |
197 | DB_ERR_INDEX_ALREADY_EXISTS, // SqlState = 'S0011' | |
198 | DB_ERR_INDEX_NOT_FOUND, // SqlState = 'S0012' | |
199 | DB_ERR_COLUMN_ALREADY_EXISTS, // SqlState = 'S0021' | |
200 | DB_ERR_COLUMN_NOT_FOUND, // SqlState = 'S0022' | |
201 | DB_ERR_NO_DEFAULT_FOR_COLUMN, // SqlState = 'S0023' | |
202 | DB_ERR_GENERAL_ERROR, // SqlState = 'S1000' | |
203 | DB_ERR_MEMORY_ALLOCATION_FAILURE, // SqlState = 'S1001' | |
204 | DB_ERR_INVALID_COLUMN_NUMBER, // SqlState = 'S1002' | |
205 | DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE, // SqlState = 'S1003' | |
206 | DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE, // SqlState = 'S1004' | |
207 | DB_ERR_OPERATION_CANCELLED, // SqlState = 'S1008' | |
208 | DB_ERR_INVALID_ARGUMENT_VALUE, // SqlState = 'S1009' | |
209 | DB_ERR_FUNCTION_SEQUENCE_ERROR, // SqlState = 'S1010' | |
210 | DB_ERR_OPERATION_INVALID_AT_THIS_TIME, // SqlState = 'S1011' | |
211 | DB_ERR_INVALID_TRANS_OPERATION_CODE, // SqlState = 'S1012' | |
212 | DB_ERR_NO_CURSOR_NAME_AVAIL, // SqlState = 'S1015' | |
213 | DB_ERR_INVALID_STR_OR_BUF_LEN, // SqlState = 'S1090' | |
214 | DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE, // SqlState = 'S1091' | |
215 | DB_ERR_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1092' | |
216 | DB_ERR_INVALID_PARAM_NO, // SqlState = 'S1093' | |
217 | DB_ERR_INVALID_SCALE_VALUE, // SqlState = 'S1094' | |
218 | DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1095' | |
219 | DB_ERR_INF_TYPE_OUT_OF_RANGE, // SqlState = 'S1096' | |
220 | DB_ERR_COLUMN_TYPE_OUT_OF_RANGE, // SqlState = 'S1097' | |
221 | DB_ERR_SCOPE_TYPE_OUT_OF_RANGE, // SqlState = 'S1098' | |
222 | DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE, // SqlState = 'S1099' | |
223 | DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1100' | |
224 | DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE, // SqlState = 'S1101' | |
225 | DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE, // SqlState = 'S1103' | |
226 | DB_ERR_INVALID_PRECISION_VALUE, // SqlState = 'S1104' | |
227 | DB_ERR_INVALID_PARAM_TYPE, // SqlState = 'S1105' | |
228 | DB_ERR_FETCH_TYPE_OUT_OF_RANGE, // SqlState = 'S1106' | |
229 | DB_ERR_ROW_VALUE_OUT_OF_RANGE, // SqlState = 'S1107' | |
230 | DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE, // SqlState = 'S1108' | |
231 | DB_ERR_INVALID_CURSOR_POSITION, // SqlState = 'S1109' | |
232 | DB_ERR_INVALID_DRIVER_COMPLETION, // SqlState = 'S1110' | |
233 | DB_ERR_INVALID_BOOKMARK_VALUE, // SqlState = 'S1111' | |
234 | DB_ERR_DRIVER_NOT_CAPABLE, // SqlState = 'S1C00' | |
235 | DB_ERR_TIMEOUT_EXPIRED // SqlState = 'S1T00' | |
236 | }; | |
237 | ||
238 | struct DbStuff | |
239 | { | |
240 | HENV Henv; | |
a2115c88 GT |
241 | char Dsn[SQL_MAX_DSN_LENGTH+1]; // Data Source Name |
242 | char Uid[20+1]; // User ID | |
243 | char AuthStr[20+1]; // Authorization string (password) | |
244 | ||
245 | char description[SQL_MAX_DSN_LENGTH+1]; // Not sure what the max length is | |
246 | char fileType[SQL_MAX_DSN_LENGTH+1]; // Not sure what the max length is | |
247 | ||
248 | // Optionals needed for some databases like dBase | |
249 | char defaultDir[DB_PATH_MAX]; // Directory that db file resides in | |
108106cf JS |
250 | }; |
251 | ||
252 | typedef struct | |
253 | { | |
254 | char TypeName[DB_TYPE_NAME_LEN]; | |
255 | int FsqlType; | |
256 | long Precision; | |
257 | short CaseSensitive; | |
258 | // short MinimumScale; | |
259 | short MaximumScale; | |
260 | } SqlTypeInfo; | |
261 | ||
30a6d2d2 GT |
262 | class WXDLLEXPORT wxColFor |
263 | { | |
264 | public: | |
265 | wxString s_Field; // Formated String for Output | |
266 | wxString s_Format[7]; // Formated Objekts - TIMESTAMP has the biggest (7) | |
267 | wxString s_Menge[7]; // Formated Objekts - amount of things that can be formatted | |
268 | int i_Menge[7]; // Formated Objekts - TT MM YYYY HH MM SS m | |
269 | int i_Nation; // 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US | |
270 | int i_dbDataType; // conversion of the 'sqlDataType' to the generic data type used by these classes | |
271 | SWORD i_sqlDataType; | |
272 | ||
273 | wxColFor(); | |
274 | ~wxColFor(); | |
275 | int Format(int Nation, int dbDataType,SWORD sqlDataType,short columnSize,short decimalDigits); | |
276 | }; | |
277 | ||
278 | class WXDLLEXPORT wxColInf | |
108106cf JS |
279 | { |
280 | public: | |
30a6d2d2 GT |
281 | char catalog[128+1]; |
282 | char schema[128+1]; | |
283 | char tableName[DB_MAX_TABLE_NAME_LEN+1]; | |
284 | char colName[DB_MAX_COLUMN_NAME_LEN+1]; | |
285 | SWORD sqlDataType; | |
286 | char typeName[128+1]; | |
287 | SWORD columnSize; | |
288 | SWORD bufferLength; | |
289 | short decimalDigits; | |
290 | short numPrecRadix; | |
291 | short nullable; | |
292 | char remarks[254+1]; | |
293 | int dbDataType; // conversion of the 'sqlDataType' to the generic data type used by these classes | |
294 | // mj10777.19991224 : new | |
295 | int PkCol; // Primary key column 0=No; 1= First Key, 2 = Second Key etc. | |
296 | char PkTableName[DB_MAX_TABLE_NAME_LEN+1]; // Tables that use this PKey as a FKey | |
297 | int FkCol; // Foreign key column 0=No; 1= First Key, 2 = Second Key etc. | |
298 | char FkTableName[DB_MAX_TABLE_NAME_LEN+1]; // Foreign key table name | |
299 | wxColFor *pColFor; // How should this columns be formatted | |
300 | }; | |
301 | ||
302 | class WXDLLEXPORT wxTableInf // Description of a Table | |
303 | { // mj10777 : used in wxDbInf and GetCatalog(..) | |
304 | public: | |
305 | char tableName[DB_MAX_TABLE_NAME_LEN+1]; | |
306 | char tableType[254+1]; // "TABLE" or "SYSTEM TABLE" etc. | |
307 | char tableRemarks[254+1]; | |
308 | int numCols; // How many Columns does this Table have: GetColumnCount(..); | |
309 | wxColInf *pColInf; // pColInf = NULL ; User can later call GetColumns(..); | |
310 | }; | |
311 | ||
312 | class WXDLLEXPORT wxDbInf // Description of a Database | |
313 | { // mj10777 : used in GetCatalog(..) | |
314 | public: | |
315 | char catalog[128+1]; | |
316 | char schema[128+1]; | |
317 | int numTables; // How many tables does this database have | |
318 | wxTableInf *pTableInf; // pTableInf = new wxTableInf[numTables]; | |
108106cf JS |
319 | }; |
320 | ||
1fc5dd6f JS |
321 | enum sqlLog |
322 | { | |
323 | sqlLogOFF, | |
324 | sqlLogON | |
325 | }; | |
326 | ||
a2115c88 GT |
327 | enum dbms |
328 | { | |
329 | dbmsUNIDENTIFIED, | |
330 | dbmsORACLE, | |
331 | dbmsSYBASE_ASA, // Adaptive Server Anywhere | |
332 | dbmsSYBASE_ASE, // Adaptive Server Enterprise | |
333 | dbmsMS_SQL_SERVER, | |
334 | dbmsMY_SQL, | |
335 | dbmsPOSTGRES, | |
336 | dbmsACCESS, | |
ac465026 GT |
337 | dbmsDBASE, |
338 | dbmsINFORMIX | |
a2115c88 GT |
339 | }; |
340 | ||
341 | typedef enum dbms DBMS; | |
342 | ||
343 | // The wxDB::errorList is copied to this variable when the wxDB object | |
344 | // is closed. This way, the error list is still available after the | |
345 | // database object is closed. This is necessary if the database | |
346 | // connection fails so the calling application can show the operator | |
347 | // why the connection failed. Note: as each wxDB object is closed, it | |
348 | // will overwrite the errors of the previously destroyed wxDB object in | |
349 | // this variable. | |
350 | extern char DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN]; | |
351 | ||
30a6d2d2 GT |
352 | // Backward compability for Remstar classes. This |
353 | // will eventually go away, so the wxColXxxx classes | |
354 | // should be used | |
355 | typedef wxColInf CcolInf; | |
356 | ||
9f8de18f | 357 | class WXDLLEXPORT wxDB |
108106cf JS |
358 | { |
359 | private: | |
360 | ||
361 | // Private data | |
1fc5dd6f JS |
362 | bool dbIsOpen; |
363 | char *dsn; // Data source name | |
364 | char *uid; // User ID | |
365 | char *authStr; // Authorization string (password) | |
366 | FILE *fpSqlLog; // Sql Log file pointer | |
367 | enum sqlLog sqlLogState; // On or Off | |
108106cf JS |
368 | |
369 | // Private member functions | |
370 | bool getDbInfo(void); | |
371 | bool getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo); | |
372 | bool setConnectionOptions(void); | |
0b0ca94c | 373 | void logError(const char *errMsg, const char *SQLState); |
108106cf | 374 | |
a3439c7d GT |
375 | bool fwdOnlyCursors; |
376 | ||
108106cf JS |
377 | public: |
378 | ||
379 | // The following structure contains database information gathered from the | |
380 | // datasource when the datasource is first opened. | |
381 | struct | |
382 | { | |
383 | char dbmsName[40]; // Name of the dbms product | |
a2115c88 | 384 | char dbmsVer[64]; // Version # of the dbms product |
108106cf | 385 | char driverName[40]; // Driver name |
1acd7ba6 RR |
386 | char odbcVer[60]; // ODBC version of the driver |
387 | char drvMgrOdbcVer[60]; // ODBC version of the driver manager | |
388 | char driverVer[60]; // Driver version | |
389 | char serverName[80]; // Server Name, typically a connect string | |
108106cf JS |
390 | char databaseName[128]; // Database filename |
391 | char outerJoins[2]; // Indicates whether the data source supports outer joins | |
392 | char procedureSupport[2]; // Indicates whether the data source supports stored procedures | |
393 | UWORD maxConnections; // Maximum # of connections the data source supports | |
394 | UWORD maxStmts; // Maximum # of HSTMTs per HDBC | |
395 | UWORD apiConfLvl; // ODBC API conformance level | |
396 | UWORD cliConfLvl; // Indicates whether the data source is SAG compliant | |
397 | UWORD sqlConfLvl; // SQL conformance level | |
398 | UWORD cursorCommitBehavior; // Indicates how cursors are affected by a db commit | |
399 | UWORD cursorRollbackBehavior; // Indicates how cursors are affected by a db rollback | |
400 | UWORD supportNotNullClause; // Indicates if data source supports NOT NULL clause | |
401 | char supportIEF[2]; // Integrity Enhancement Facility (Referential Integrity) | |
402 | UDWORD txnIsolation; // Default transaction isolation level supported by the driver | |
403 | UDWORD txnIsolationOptions; // Transaction isolation level options available | |
404 | UDWORD fetchDirections; // Fetch directions supported | |
405 | UDWORD lockTypes; // Lock types supported in SQLSetPos | |
406 | UDWORD posOperations; // Position operations supported in SQLSetPos | |
407 | UDWORD posStmts; // Position statements supported | |
408 | UDWORD scrollConcurrency; // Concurrency control options supported for scrollable cursors | |
409 | UDWORD scrollOptions; // Scroll Options supported for scrollable cursors | |
410 | UDWORD staticSensitivity; // Indicates if additions, deletions and updates can be detected | |
411 | UWORD txnCapable; // Indicates if the data source supports transactions | |
412 | UDWORD loginTimeout; // Number seconds to wait for a login request | |
413 | } dbInf; | |
414 | ||
415 | // ODBC handles | |
416 | HENV henv; // ODBC Environment handle | |
417 | HDBC hdbc; // ODBC DB Connection handle | |
418 | HSTMT hstmt; // ODBC Statement handle | |
419 | ||
420 | // ODBC Error Inf. | |
421 | char sqlState[20]; | |
422 | SDWORD nativeError; | |
423 | char errorMsg[SQL_MAX_MESSAGE_LENGTH]; | |
424 | SWORD cbErrorMsg; | |
425 | char errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN]; | |
426 | int DB_STATUS; | |
427 | ||
428 | //Error reporting mode | |
429 | bool silent; | |
430 | ||
a2115c88 GT |
431 | // Number of Ctable objects connected to this db object |
432 | unsigned int nTables; | |
433 | ||
108106cf JS |
434 | // Inf. about logical data types VARCHAR, INTEGER, FLOAT and DATE. |
435 | // This inf. is obtained from the ODBC driver by use of the | |
436 | // SQLGetTypeInfo() function. The key piece of inf. is the | |
437 | // type name the data source uses for each logical data type. | |
438 | // e.g. VARCHAR; Oracle calls it VARCHAR2. | |
439 | SqlTypeInfo typeInfVarchar, typeInfInteger, typeInfFloat, typeInfDate; | |
440 | ||
441 | // Public member functions | |
b47c832e | 442 | wxDB(HENV &aHenv, bool FwdOnlyCursors=(bool)TRUE); |
1fc5dd6f JS |
443 | bool Open(char *Dsn, char *Uid, char *AuthStr); // Data Source Name, User ID, Password |
444 | void Close(void); | |
445 | bool CommitTrans(void); | |
446 | bool RollbackTrans(void); | |
447 | bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); | |
448 | bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); | |
449 | void DispNextError(void); | |
0b0ca94c GT |
450 | bool CreateView(const char *viewName, const char *colList, const char *pSqlStmt, bool attemptDrop=TRUE); |
451 | bool DropView(const char *viewName); | |
452 | bool ExecSql(const char *pSqlStmt); | |
a2115c88 GT |
453 | bool GetNext(void); |
454 | bool GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SDWORD FAR *cbReturned); | |
30a6d2d2 GT |
455 | bool Grant(int privileges, const char *tableName, const char *userList = "PUBLIC"); |
456 | int TranslateSqlState(const char *SQLState); | |
457 | wxDbInf *GetCatalog(char *userID); | |
458 | bool Catalog(const char *userID=NULL, const char *fileName = "Catalog.txt"); | |
459 | int GetKeyFields(char *tableName, wxColInf* colInf,int nocols); | |
460 | wxColInf *GetColumns(char *tableName[], const char *userID=NULL); | |
461 | wxColInf *GetColumns(char *tableName, int *numCols, const char *userID=NULL); | |
462 | int GetColumnCount(char *tableName, const char *userID=NULL); | |
1fc5dd6f JS |
463 | char *GetDatabaseName(void) {return dbInf.dbmsName;} |
464 | char *GetDataSource(void) {return dsn;} | |
a2115c88 GT |
465 | char *GetUsername(void) {return uid;} |
466 | char *GetPassword(void) {return authStr;} | |
1fc5dd6f JS |
467 | bool IsOpen(void) {return dbIsOpen;} |
468 | HENV GetHENV(void) {return henv;} | |
469 | HDBC GetHDBC(void) {return hdbc;} | |
a2115c88 | 470 | HSTMT GetHSTMT(void) {return hstmt;} |
0b0ca94c GT |
471 | bool TableExists(const char *tableName, const char *userID=NULL, const char *path=NULL); // Table name can refer to a table, view, alias or synonym |
472 | void LogError(const char *errMsg, const char *SQLState = 0) {logError(errMsg, SQLState);} | |
473 | bool SqlLog(enum sqlLog state, const char *filename = "sqllog.txt", bool append = FALSE); | |
474 | bool WriteSqlLog(const char *logMsg); | |
a2115c88 | 475 | DBMS Dbms(void); |
a3439c7d | 476 | bool FwdOnlyCursors(void) {return fwdOnlyCursors;} |
108106cf JS |
477 | |
478 | }; // wxDB | |
479 | ||
480 | // This structure forms a node in a linked list. The linked list of "DbList" objects | |
481 | // keeps track of allocated database connections. This allows the application to | |
482 | // open more than one database connection through ODBC for multiple transaction support | |
483 | // or for multiple database support. | |
484 | ||
485 | struct DbList | |
486 | { | |
487 | DbList *PtrPrev; // Pointer to previous item in the list | |
488 | char Dsn[SQL_MAX_DSN_LENGTH+1]; // Data Source Name | |
489 | wxDB *PtrDb; // Pointer to the wxDB object | |
490 | bool Free; // Is item free or in use? | |
491 | DbList *PtrNext; // Pointer to next item in the list | |
492 | }; | |
493 | ||
a2115c88 | 494 | |
154f22b3 | 495 | #ifdef __WXDEBUG__ |
e115e771 | 496 | #include "wx/object.h" |
a2115c88 GT |
497 | class CstructTablesInUse : public wxObject |
498 | { | |
499 | public: | |
500 | const char *tableName; | |
501 | ULONG tableID; | |
502 | class wxDB *pDb; | |
503 | }; // CstructTablesInUse | |
504 | #endif | |
505 | ||
108106cf JS |
506 | // The following routines allow a user to get new database connections, free them |
507 | // for other code segments to use, or close all of them when the application has | |
508 | // completed. | |
509 | ||
30a6d2d2 | 510 | wxDB WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS); |
a1218415 UU |
511 | bool WXDLLEXPORT FreeDbConnection(wxDB *pDb); |
512 | void WXDLLEXPORT CloseDbConnections(void); | |
513 | int WXDLLEXPORT NumberDbConnectionsInUse(void); | |
108106cf | 514 | |
a2115c88 | 515 | // This function sets the sql log state for all open wxDB objects |
0b0ca94c | 516 | bool SqlLog(enum sqlLog state, const char *filename = "sqllog.txt"); |
a2115c88 | 517 | |
108106cf JS |
518 | // This routine allows you to query a driver manager |
519 | // for a list of available datasources. Call this routine | |
520 | // the first time using SQL_FETCH_FIRST. Continue to call it | |
521 | // using SQL_FETCH_NEXT until you've exhausted the list. | |
30a6d2d2 | 522 | bool WXDLLEXPORT GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax, |
108106cf JS |
523 | UWORD direction = SQL_FETCH_NEXT); |
524 | ||
525 | #endif |