1 ///////////////////////////////////////////////////////////////////////////////
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.
7 // Modified by: George Tasker
9 // -Added support for SQL statement logging and database cataloging
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
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.
31 ///////////////////////////////////////////////////////////////////////////////
42 // BJO 20000503: introduce new GetColumns members which are more database independant and
43 // return columns in the order they were created
44 #define OLD_GETCOLUMNS 1
47 // Use this line for wxWindows v1.x
49 // Use this line for wxWindows v2.x
50 #include "wx/version.h"
52 #if wxMAJOR_VERSION == 2
54 #pragma interface "db.h"
60 #if wxMAJOR_VERSION == 2
63 #include "wx/isqlext.h"
64 // If you use the wxCreateDataSource() function with MSW/VC6,
65 // you cannot use the iODBC headers, you must use the VC headers,
66 // plus the odbcinst.h header
69 //#include "odbcinst.h"
79 typedef double SDOUBLE
;
80 typedef unsigned int UINT
;
83 #ifndef wxODBC_FWD_ONLY_CURSORS
84 #define wxODBC_FWD_ONLY_CURSORS 1
87 enum enumDummy
{enumDum1
};
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)
92 #define SQL_C_ENUM (sizeof(enumDummy) == 2 ? SQL_C_USHORT : SQL_C_ULONG)
102 const int wxDB_PATH_MAX
= 254;
104 extern char const *SQL_LOG_FILENAME
;
105 extern char const *SQL_CATALOG_FILENAME
;
109 const int DB_TYPE_NAME_LEN
= 40;
110 const int DB_MAX_STATEMENT_LEN
= 2048;
111 const int DB_MAX_WHERE_CLAUSE_LEN
= 1024;
112 const int DB_MAX_ERROR_MSG_LEN
= 512;
113 const int DB_MAX_ERROR_HISTORY
= 5;
114 const int DB_MAX_TABLE_NAME_LEN
= 128;
115 const int DB_MAX_COLUMN_NAME_LEN
= 128;
117 const int DB_DATA_TYPE_VARCHAR
= 1;
118 const int DB_DATA_TYPE_INTEGER
= 2;
119 const int DB_DATA_TYPE_FLOAT
= 3;
120 const int DB_DATA_TYPE_DATE
= 4;
122 const int DB_SELECT_KEYFIELDS
= 1;
123 const int DB_SELECT_WHERE
= 2;
124 const int DB_SELECT_MATCHING
= 3;
125 const int DB_SELECT_STATEMENT
= 4;
127 const int DB_UPD_KEYFIELDS
= 1;
128 const int DB_UPD_WHERE
= 2;
130 const int DB_DEL_KEYFIELDS
= 1;
131 const int DB_DEL_WHERE
= 2;
132 const int DB_DEL_MATCHING
= 3;
134 const int DB_WHERE_KEYFIELDS
= 1;
135 const int DB_WHERE_MATCHING
= 2;
137 const int DB_GRANT_SELECT
= 1;
138 const int DB_GRANT_INSERT
= 2;
139 const int DB_GRANT_UPDATE
= 4;
140 const int DB_GRANT_DELETE
= 8;
141 const int DB_GRANT_ALL
= DB_GRANT_SELECT
| DB_GRANT_INSERT
| DB_GRANT_UPDATE
| DB_GRANT_DELETE
;
143 // ODBC Error codes (derived from ODBC SqlState codes)
149 DB_ERR_GENERAL_WARNING
, // SqlState = '01000'
150 DB_ERR_DISCONNECT_ERROR
, // SqlState = '01002'
151 DB_ERR_DATA_TRUNCATED
, // SqlState = '01004'
152 DB_ERR_PRIV_NOT_REVOKED
, // SqlState = '01006'
153 DB_ERR_INVALID_CONN_STR_ATTR
, // SqlState = '01S00'
154 DB_ERR_ERROR_IN_ROW
, // SqlState = '01S01'
155 DB_ERR_OPTION_VALUE_CHANGED
, // SqlState = '01S02'
156 DB_ERR_NO_ROWS_UPD_OR_DEL
, // SqlState = '01S03'
157 DB_ERR_MULTI_ROWS_UPD_OR_DEL
, // SqlState = '01S04'
158 DB_ERR_WRONG_NO_OF_PARAMS
, // SqlState = '07001'
159 DB_ERR_DATA_TYPE_ATTR_VIOL
, // SqlState = '07006'
160 DB_ERR_UNABLE_TO_CONNECT
, // SqlState = '08001'
161 DB_ERR_CONNECTION_IN_USE
, // SqlState = '08002'
162 DB_ERR_CONNECTION_NOT_OPEN
, // SqlState = '08003'
163 DB_ERR_REJECTED_CONNECTION
, // SqlState = '08004'
164 DB_ERR_CONN_FAIL_IN_TRANS
, // SqlState = '08007'
165 DB_ERR_COMM_LINK_FAILURE
, // SqlState = '08S01'
166 DB_ERR_INSERT_VALUE_LIST_MISMATCH
, // SqlState = '21S01'
167 DB_ERR_DERIVED_TABLE_MISMATCH
, // SqlState = '21S02'
168 DB_ERR_STRING_RIGHT_TRUNC
, // SqlState = '22001'
169 DB_ERR_NUMERIC_VALUE_OUT_OF_RNG
, // SqlState = '22003'
170 DB_ERR_ERROR_IN_ASSIGNMENT
, // SqlState = '22005'
171 DB_ERR_DATETIME_FLD_OVERFLOW
, // SqlState = '22008'
172 DB_ERR_DIVIDE_BY_ZERO
, // SqlState = '22012'
173 DB_ERR_STR_DATA_LENGTH_MISMATCH
, // SqlState = '22026'
174 DB_ERR_INTEGRITY_CONSTRAINT_VIOL
, // SqlState = '23000'
175 DB_ERR_INVALID_CURSOR_STATE
, // SqlState = '24000'
176 DB_ERR_INVALID_TRANS_STATE
, // SqlState = '25000'
177 DB_ERR_INVALID_AUTH_SPEC
, // SqlState = '28000'
178 DB_ERR_INVALID_CURSOR_NAME
, // SqlState = '34000'
179 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL
, // SqlState = '37000'
180 DB_ERR_DUPLICATE_CURSOR_NAME
, // SqlState = '3C000'
181 DB_ERR_SERIALIZATION_FAILURE
, // SqlState = '40001'
182 DB_ERR_SYNTAX_ERROR_OR_ACCESS_VIOL2
, // SqlState = '42000'
183 DB_ERR_OPERATION_ABORTED
, // SqlState = '70100'
184 DB_ERR_UNSUPPORTED_FUNCTION
, // SqlState = 'IM001'
185 DB_ERR_NO_DATA_SOURCE
, // SqlState = 'IM002'
186 DB_ERR_DRIVER_LOAD_ERROR
, // SqlState = 'IM003'
187 DB_ERR_SQLALLOCENV_FAILED
, // SqlState = 'IM004'
188 DB_ERR_SQLALLOCCONNECT_FAILED
, // SqlState = 'IM005'
189 DB_ERR_SQLSETCONNECTOPTION_FAILED
, // SqlState = 'IM006'
190 DB_ERR_NO_DATA_SOURCE_DLG_PROHIB
, // SqlState = 'IM007'
191 DB_ERR_DIALOG_FAILED
, // SqlState = 'IM008'
192 DB_ERR_UNABLE_TO_LOAD_TRANSLATION_DLL
, // SqlState = 'IM009'
193 DB_ERR_DATA_SOURCE_NAME_TOO_LONG
, // SqlState = 'IM010'
194 DB_ERR_DRIVER_NAME_TOO_LONG
, // SqlState = 'IM011'
195 DB_ERR_DRIVER_KEYWORD_SYNTAX_ERROR
, // SqlState = 'IM012'
196 DB_ERR_TRACE_FILE_ERROR
, // SqlState = 'IM013'
197 DB_ERR_TABLE_OR_VIEW_ALREADY_EXISTS
, // SqlState = 'S0001'
198 DB_ERR_TABLE_NOT_FOUND
, // SqlState = 'S0002'
199 DB_ERR_INDEX_ALREADY_EXISTS
, // SqlState = 'S0011'
200 DB_ERR_INDEX_NOT_FOUND
, // SqlState = 'S0012'
201 DB_ERR_COLUMN_ALREADY_EXISTS
, // SqlState = 'S0021'
202 DB_ERR_COLUMN_NOT_FOUND
, // SqlState = 'S0022'
203 DB_ERR_NO_DEFAULT_FOR_COLUMN
, // SqlState = 'S0023'
204 DB_ERR_GENERAL_ERROR
, // SqlState = 'S1000'
205 DB_ERR_MEMORY_ALLOCATION_FAILURE
, // SqlState = 'S1001'
206 DB_ERR_INVALID_COLUMN_NUMBER
, // SqlState = 'S1002'
207 DB_ERR_PROGRAM_TYPE_OUT_OF_RANGE
, // SqlState = 'S1003'
208 DB_ERR_SQL_DATA_TYPE_OUT_OF_RANGE
, // SqlState = 'S1004'
209 DB_ERR_OPERATION_CANCELLED
, // SqlState = 'S1008'
210 DB_ERR_INVALID_ARGUMENT_VALUE
, // SqlState = 'S1009'
211 DB_ERR_FUNCTION_SEQUENCE_ERROR
, // SqlState = 'S1010'
212 DB_ERR_OPERATION_INVALID_AT_THIS_TIME
, // SqlState = 'S1011'
213 DB_ERR_INVALID_TRANS_OPERATION_CODE
, // SqlState = 'S1012'
214 DB_ERR_NO_CURSOR_NAME_AVAIL
, // SqlState = 'S1015'
215 DB_ERR_INVALID_STR_OR_BUF_LEN
, // SqlState = 'S1090'
216 DB_ERR_DESCRIPTOR_TYPE_OUT_OF_RANGE
, // SqlState = 'S1091'
217 DB_ERR_OPTION_TYPE_OUT_OF_RANGE
, // SqlState = 'S1092'
218 DB_ERR_INVALID_PARAM_NO
, // SqlState = 'S1093'
219 DB_ERR_INVALID_SCALE_VALUE
, // SqlState = 'S1094'
220 DB_ERR_FUNCTION_TYPE_OUT_OF_RANGE
, // SqlState = 'S1095'
221 DB_ERR_INF_TYPE_OUT_OF_RANGE
, // SqlState = 'S1096'
222 DB_ERR_COLUMN_TYPE_OUT_OF_RANGE
, // SqlState = 'S1097'
223 DB_ERR_SCOPE_TYPE_OUT_OF_RANGE
, // SqlState = 'S1098'
224 DB_ERR_NULLABLE_TYPE_OUT_OF_RANGE
, // SqlState = 'S1099'
225 DB_ERR_UNIQUENESS_OPTION_TYPE_OUT_OF_RANGE
, // SqlState = 'S1100'
226 DB_ERR_ACCURACY_OPTION_TYPE_OUT_OF_RANGE
, // SqlState = 'S1101'
227 DB_ERR_DIRECTION_OPTION_OUT_OF_RANGE
, // SqlState = 'S1103'
228 DB_ERR_INVALID_PRECISION_VALUE
, // SqlState = 'S1104'
229 DB_ERR_INVALID_PARAM_TYPE
, // SqlState = 'S1105'
230 DB_ERR_FETCH_TYPE_OUT_OF_RANGE
, // SqlState = 'S1106'
231 DB_ERR_ROW_VALUE_OUT_OF_RANGE
, // SqlState = 'S1107'
232 DB_ERR_CONCURRENCY_OPTION_OUT_OF_RANGE
, // SqlState = 'S1108'
233 DB_ERR_INVALID_CURSOR_POSITION
, // SqlState = 'S1109'
234 DB_ERR_INVALID_DRIVER_COMPLETION
, // SqlState = 'S1110'
235 DB_ERR_INVALID_BOOKMARK_VALUE
, // SqlState = 'S1111'
236 DB_ERR_DRIVER_NOT_CAPABLE
, // SqlState = 'S1C00'
237 DB_ERR_TIMEOUT_EXPIRED
// SqlState = 'S1T00'
241 struct wxDbConnectInf
244 char Dsn
[SQL_MAX_DSN_LENGTH
+1]; // Data Source Name
245 char Uid
[20+1]; // User ID
246 char AuthStr
[20+1]; // Authorization string (password)
248 char description
[SQL_MAX_DSN_LENGTH
+1]; // Not sure what the max length is
249 char fileType
[SQL_MAX_DSN_LENGTH
+1]; // Not sure what the max length is
251 // Optionals needed for some databases like dBase
252 char defaultDir
[wxDB_PATH_MAX
]; // Directory that db file resides in
255 struct wxDbSqlTypeInfo
257 char TypeName
[DB_TYPE_NAME_LEN
];
261 // short MinimumScale;
266 class WXDLLEXPORT wxDbColFor
269 wxString s_Field
; // Formated String for Output
270 wxString s_Format
[7]; // Formated Objects - TIMESTAMP has the biggest (7)
271 wxString s_Menge
[7]; // Formated Objects - amount of things that can be formatted
272 int i_Menge
[7]; // Formated Objects - TT MM YYYY HH MM SS m
273 int i_Nation
; // 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US
274 int i_dbDataType
; // conversion of the 'sqlDataType' to the generic data type used by these classes
280 int Format(int Nation
, int dbDataType
, SWORD sqlDataType
, short columnSize
, short decimalDigits
);
284 class WXDLLEXPORT wxDbColInf
289 char tableName
[DB_MAX_TABLE_NAME_LEN
+1];
290 char colName
[DB_MAX_COLUMN_NAME_LEN
+1];
292 char typeName
[128+1];
299 int dbDataType
; // conversion of the 'sqlDataType' to the generic data type used by these classes
300 // mj10777.19991224 : new
301 int PkCol
; // Primary key column 0=No; 1= First Key, 2 = Second Key etc.
302 char PkTableName
[DB_MAX_TABLE_NAME_LEN
+1]; // Tables that use this PKey as a FKey
303 int FkCol
; // Foreign key column 0=No; 1= First Key, 2 = Second Key etc.
304 char FkTableName
[DB_MAX_TABLE_NAME_LEN
+1]; // Foreign key table name
305 wxDbColFor
*pColFor
; // How should this columns be formatted
311 class WXDLLEXPORT wxDbTableInf
// Description of a Table
314 char tableName
[DB_MAX_TABLE_NAME_LEN
+1];
315 char tableType
[254+1]; // "TABLE" or "SYSTEM TABLE" etc.
316 char tableRemarks
[254+1];
317 int numCols
; // How many Columns does this Table have: GetColumnCount(..);
318 wxDbColInf
*pColInf
; // pColInf = NULL ; User can later call GetColumns(..);
322 class WXDLLEXPORT wxDbInf
// Description of a Database
327 int numTables
; // How many tables does this database have
328 wxDbTableInf
*pTableInf
; // pTableInf = new wxDbTableInf[numTables];
338 // These are the databases currently tested and working with these classes
339 // See the comments in wxDb::Dbms() for exceptions/issues with
340 // each of these database engines
345 dbmsSYBASE_ASA
, // Adaptive Server Anywhere
346 dbmsSYBASE_ASE
, // Adaptive Server Enterprise
357 // The wxDb::errorList is copied to this variable when the wxDb object
358 // is closed. This way, the error list is still available after the
359 // database object is closed. This is necessary if the database
360 // connection fails so the calling application can show the operator
361 // why the connection failed. Note: as each wxDb object is closed, it
362 // will overwrite the errors of the previously destroyed wxDb object in
364 extern char DBerrorList
[DB_MAX_ERROR_HISTORY
][DB_MAX_ERROR_MSG_LEN
];
367 class WXDLLEXPORT wxDb
371 char *dsn
; // Data source name
372 char *uid
; // User ID
373 char *authStr
; // Authorization string (password)
374 FILE *fpSqlLog
; // Sql Log file pointer
375 wxDbSqlLogState sqlLogState
; // On or Off
378 // Private member functions
379 bool getDbInfo(void);
380 bool getDataTypeInfo(SWORD fSqlType
, wxDbSqlTypeInfo
&structSQLTypeInfo
);
381 bool setConnectionOptions(void);
382 void logError(const char *errMsg
, const char *SQLState
);
383 #if !wxODBC_BACKWARD_COMPATABILITY
385 HENV henv
; // ODBC Environment handle
386 HDBC hdbc
; // ODBC DB Connection handle
387 HSTMT hstmt
; // ODBC Statement handle
389 //Error reporting mode
392 // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
393 unsigned int nTables
;
395 // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
397 // This information is obtained from the ODBC driver by use of the
398 // SQLGetTypeInfo() function. The key piece of information is the
399 // type name the data source uses for each logical data type.
400 // e.g. VARCHAR; Oracle calls it VARCHAR2.
401 wxDbSqlTypeInfo typeInfVarchar
;
402 wxDbSqlTypeInfo typeInfInteger
;
403 wxDbSqlTypeInfo typeInfFloat
;
404 wxDbSqlTypeInfo typeInfDate
;
408 #if wxODBC_BACKWARD_COMPATABILITY
410 HENV henv
; // ODBC Environment handle
411 HDBC hdbc
; // ODBC DB Connection handle
412 HSTMT hstmt
; // ODBC Statement handle
414 //Error reporting mode
417 // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
418 unsigned int nTables
;
421 // The following structure contains database information gathered from the
422 // datasource when the datasource is first opened.
425 char dbmsName
[40]; // Name of the dbms product
426 char dbmsVer
[64]; // Version # of the dbms product
427 char driverName
[40]; // Driver name
428 char odbcVer
[60]; // ODBC version of the driver
429 char drvMgrOdbcVer
[60]; // ODBC version of the driver manager
430 char driverVer
[60]; // Driver version
431 char serverName
[80]; // Server Name, typically a connect string
432 char databaseName
[128]; // Database filename
433 char outerJoins
[2]; // Indicates whether the data source supports outer joins
434 char procedureSupport
[2]; // Indicates whether the data source supports stored procedures
435 UWORD maxConnections
; // Maximum # of connections the data source supports
436 UWORD maxStmts
; // Maximum # of HSTMTs per HDBC
437 UWORD apiConfLvl
; // ODBC API conformance level
438 UWORD cliConfLvl
; // Indicates whether the data source is SAG compliant
439 UWORD sqlConfLvl
; // SQL conformance level
440 UWORD cursorCommitBehavior
; // Indicates how cursors are affected by a db commit
441 UWORD cursorRollbackBehavior
; // Indicates how cursors are affected by a db rollback
442 UWORD supportNotNullClause
; // Indicates if data source supports NOT NULL clause
443 char supportIEF
[2]; // Integrity Enhancement Facility (Referential Integrity)
444 UDWORD txnIsolation
; // Default transaction isolation level supported by the driver
445 UDWORD txnIsolationOptions
; // Transaction isolation level options available
446 UDWORD fetchDirections
; // Fetch directions supported
447 UDWORD lockTypes
; // Lock types supported in SQLSetPos
448 UDWORD posOperations
; // Position operations supported in SQLSetPos
449 UDWORD posStmts
; // Position statements supported
450 UDWORD scrollConcurrency
; // Concurrency control options supported for scrollable cursors
451 UDWORD scrollOptions
; // Scroll Options supported for scrollable cursors
452 UDWORD staticSensitivity
; // Indicates if additions, deletions and updates can be detected
453 UWORD txnCapable
; // Indicates if the data source supports transactions
454 UDWORD loginTimeout
; // Number seconds to wait for a login request
460 wxChar errorList
[DB_MAX_ERROR_HISTORY
][DB_MAX_ERROR_MSG_LEN
];
461 wxChar errorMsg
[SQL_MAX_MESSAGE_LENGTH
];
465 #if wxODBC_BACKWARD_COMPATABILITY
466 // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
468 // This information is obtained from the ODBC driver by use of the
469 // SQLGetTypeInfo() function. The key piece of information is the
470 // type name the data source uses for each logical data type.
471 // e.g. VARCHAR; Oracle calls it VARCHAR2.
472 wxDbSqlTypeInfo typeInfVarchar
;
473 wxDbSqlTypeInfo typeInfInteger
;
474 wxDbSqlTypeInfo typeInfFloat
;
475 wxDbSqlTypeInfo typeInfDate
;
478 // Public member functions
479 wxDb(HENV
&aHenv
, bool FwdOnlyCursors
=(bool)TRUE
);
480 bool Open(char *Dsn
, char *Uid
, char *AuthStr
); // Data Source Name, User ID, Password
482 bool CommitTrans(void);
483 bool RollbackTrans(void);
484 bool DispAllErrors(HENV aHenv
, HDBC aHdbc
= SQL_NULL_HDBC
, HSTMT aHstmt
= SQL_NULL_HSTMT
);
485 bool GetNextError(HENV aHenv
, HDBC aHdbc
= SQL_NULL_HDBC
, HSTMT aHstmt
= SQL_NULL_HSTMT
);
486 void DispNextError(void);
487 bool CreateView(const char *viewName
, const char *colList
, const char *pSqlStmt
, bool attemptDrop
=TRUE
);
488 bool DropView(const char *viewName
);
489 bool ExecSql(const char *pSqlStmt
);
491 bool GetData(UWORD colNo
, SWORD cType
, PTR pData
, SDWORD maxLen
, SDWORD FAR
*cbReturned
);
492 bool Grant(int privileges
, const char *tableName
, const char *userList
= "PUBLIC");
493 int TranslateSqlState(const wxChar
*SQLState
);
494 wxDbInf
*GetCatalog(char *userID
);
495 bool Catalog(const char *userID
=NULL
, const char *fileName
= SQL_CATALOG_FILENAME
);
496 int GetKeyFields(char *tableName
, wxDbColInf
* colInf
, int nocols
);
498 wxDbColInf
*GetColumns(char *tableName
[], const char *userID
=NULL
);
499 wxDbColInf
*GetColumns(char *tableName
, int *numCols
, const char *userID
=NULL
);
501 int GetColumnCount(char *tableName
, const char *userID
=NULL
);
502 char *GetDatabaseName(void) {return dbInf
.dbmsName
;}
503 char *GetDataSource(void) {return dsn
;}
504 char *GetUsername(void) {return uid
;}
505 char *GetPassword(void) {return authStr
;}
506 bool IsOpen(void) {return dbIsOpen
;}
507 HENV
GetHENV(void) {return henv
;}
508 HDBC
GetHDBC(void) {return hdbc
;}
509 HSTMT
GetHSTMT(void) {return hstmt
;}
510 int GetTableCount() {return nTables
;}; // number of tables using this connection
511 wxDbSqlTypeInfo
GetTypeInfVarchar(){return typeInfVarchar
;}
512 wxDbSqlTypeInfo
GetTypeInfInteger(){return typeInfInteger
;}
513 wxDbSqlTypeInfo
GetTypeInfFloat() {return typeInfFloat
;}
514 wxDbSqlTypeInfo
GetTypeInfDate() {return typeInfDate
;}
516 bool TableExists(const char *tableName
, const char *userID
=NULL
, const char *path
=NULL
); // Table name can refer to a table, view, alias or synonym
517 void LogError(const char *errMsg
, const char *SQLState
= 0) {logError(errMsg
, SQLState
);}
518 void SetDebugErrorMessages(bool state
) { silent
= !state
; }
519 bool SetSqlLogging(wxDbSqlLogState state
, const wxChar
*filename
= SQL_LOG_FILENAME
, bool append
= FALSE
);
520 bool WriteSqlLog(const wxChar
*logMsg
);
522 bool FwdOnlyCursors(void) {return fwdOnlyCursors
;}
524 // These two functions are provided strictly for use by wxDbTable.
525 // DO NOT USE THESE FUNCTIONS, OR MEMORY LEAKS MAY OCCUR
526 void incrementTableCount() { nTables
++; return; }
527 void decrementTableCount() { nTables
--; return; }
532 // This structure forms a node in a linked list. The linked list of "DbList" objects
533 // keeps track of allocated database connections. This allows the application to
534 // open more than one database connection through ODBC for multiple transaction support
535 // or for multiple database support.
538 wxDbList
*PtrPrev
; // Pointer to previous item in the list
539 wxChar Dsn
[SQL_MAX_DSN_LENGTH
+1]; // Data Source Name
540 wxDb
*PtrDb
; // Pointer to the wxDb object
541 bool Free
; // Is item free or in use?
542 wxDbList
*PtrNext
; // Pointer to next item in the list
546 #include "wx/object.h"
547 class wxTablesInUse
: public wxObject
550 const char *tableName
;
557 // The following routines allow a user to get new database connections, free them
558 // for other code segments to use, or close all of them when the application has
560 wxDb WXDLLEXPORT
*wxDbGetConnection(wxDbConnectInf
*pDbConfig
, bool FwdOnlyCursors
=(bool)wxODBC_FWD_ONLY_CURSORS
);
561 bool WXDLLEXPORT
wxDbFreeConnection(wxDb
*pDb
);
562 void WXDLLEXPORT
wxDbCloseConnections(void);
563 int WXDLLEXPORT
wxDbConnectionsInUse(void);
566 // This function sets the sql log state for all open wxDb objects
567 bool wxDbSqlLog(wxDbSqlLogState state
, const wxChar
*filename
= SQL_LOG_FILENAME
);
571 // MSW/VC6 ONLY!!! Experimental
572 int WXDLLEXPORT
wxDbCreateDataSource(const char *driverName
, const char *dsn
, const char *description
="",
573 bool sysDSN
=FALSE
, const char *defDir
="", wxWindow
*parent
=NULL
);
576 // This routine allows you to query a driver manager
577 // for a list of available datasources. Call this routine
578 // the first time using SQL_FETCH_FIRST. Continue to call it
579 // using SQL_FETCH_NEXT until you've exhausted the list.
580 bool WXDLLEXPORT
wxDbGetDataSource(HENV henv
, char *Dsn
, SWORD DsnMax
, char *DsDesc
, SWORD DsDescMax
,
581 UWORD direction
= SQL_FETCH_NEXT
);
584 // Change this to 0 to remove use of all deprecated functions
585 #if wxODBC_BACKWARD_COMPATABILITY
586 //#################################################################################
587 //############### DEPRECATED functions for backward compatability #################
588 //#################################################################################
590 // Backward compability structures/classes. This will eventually go away
591 const int DB_PATH_MAX
= wxDB_PATH_MAX
;
594 typedef wxDbTableInf wxTableInf
;
595 typedef wxDbColInf wxColInf
;
596 typedef wxDbColInf CcolInf
;
597 typedef wxDbColFor wxColFor
;
598 typedef wxDbSqlTypeInfo SqlTypeInfo
;
599 typedef wxDbSqlTypeInfo wxSqlTypeInfo
;
600 typedef enum wxDbSqlLogState sqlLog
;
601 typedef enum wxDbSqlLogState wxSqlLogState
;
602 typedef enum wxDBMS dbms
;
603 typedef enum wxDBMS DBMS
;
604 typedef wxODBC_ERRORS ODBC_ERRORS
;
605 typedef wxDbConnectInf DbStuff
;
606 typedef wxDbList DbList
;
608 typedef wxTablesInUse CstructTablesInUse
;
611 // Deprecated function names that are replaced by the function names listed above
612 wxDB WXDLLEXPORT
*GetDbConnection(DbStuff
*pDbStuff
, bool FwdOnlyCursors
=(bool)wxODBC_FWD_ONLY_CURSORS
);
613 bool WXDLLEXPORT
FreeDbConnection(wxDB
*pDb
);
614 void WXDLLEXPORT
CloseDbConnections(void);
615 int WXDLLEXPORT
NumberDbConnectionsInUse(void);
617 bool SqlLog(sqlLog state
, const wxChar
*filename
= SQL_LOG_FILENAME
);
619 bool WXDLLEXPORT
GetDataSource(HENV henv
, char *Dsn
, SWORD DsnMax
, char *DsDesc
, SWORD DsDescMax
,
620 UWORD direction
= SQL_FETCH_NEXT
);
621 #endif // Deprecated structures/classes/functions