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