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