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