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