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