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 // Mark Johnson, wxWindows@mj10777.de
11 // -Added support for SQL statement logging and database cataloging
13 // -Added QUERY_ONLY mode support to reduce default number of cursors
14 // -Added additional SQL logging code
15 // -Added DEBUG-ONLY tracking of Ctable objects to detect orphaned DB connections
16 // -Set ODBC option to only read committed writes to the DB so all
17 // databases operate the same in that respect
21 // Copyright: (c) 1996 Remstar International, Inc.
22 // Licence: wxWindows licence, plus:
23 // Notice: This class library and its intellectual design are free of charge for use,
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.
33 ///////////////////////////////////////////////////////////////////////////////
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
47 #define EXPERIMENTAL_WXDB_FUNCTIONS 0
49 // Use this line for wxWindows v1.x
51 // Use this line for wxWindows v2.x
52 #include "wx/version.h"
54 #if wxMAJOR_VERSION == 2
56 #pragma interface "db.h"
62 #if wxMAJOR_VERSION == 2
65 #include "wx/isqlext.h"
66 // If you use the wxCreateDataSource() function with MSW/VC6,
67 // you cannot use the iODBC headers, you must use the VC headers,
68 // plus the odbcinst.h header
71 //#include "odbcinst.h"
81 typedef double SDOUBLE
;
82 typedef unsigned int UINT
;
85 #ifndef wxODBC_FWD_ONLY_CURSORS
86 #define wxODBC_FWD_ONLY_CURSORS 1
89 enum enumDummy
{enumDum1
};
91 #define SQL_C_BOOLEAN(datatype) (sizeof(datatype) == 1 ? SQL_C_UTINYINT : (sizeof(datatype) == 2 ? SQL_C_USHORT : SQL_C_ULONG))
92 // #define SQL_C_BOOLEAN (sizeof(Bool) == 2 ? SQL_C_USHORT : SQL_C_ULONG)
94 #define SQL_C_ENUM (sizeof(enumDummy) == 2 ? SQL_C_USHORT : SQL_C_ULONG)
104 const int wxDB_PATH_MAX
= 254;
106 extern char const *SQL_LOG_FILENAME
;
107 extern char const *SQL_CATALOG_FILENAME
;
111 const int DB_TYPE_NAME_LEN
= 40;
112 const int DB_MAX_STATEMENT_LEN
= 2048;
113 const int DB_MAX_WHERE_CLAUSE_LEN
= 1024;
114 const int DB_MAX_ERROR_MSG_LEN
= 512;
115 const int DB_MAX_ERROR_HISTORY
= 5;
116 const int DB_MAX_TABLE_NAME_LEN
= 128;
117 const int DB_MAX_COLUMN_NAME_LEN
= 128;
119 const int DB_DATA_TYPE_VARCHAR
= 1;
120 const int DB_DATA_TYPE_INTEGER
= 2;
121 const int DB_DATA_TYPE_FLOAT
= 3;
122 const int DB_DATA_TYPE_DATE
= 4;
124 const int DB_SELECT_KEYFIELDS
= 1;
125 const int DB_SELECT_WHERE
= 2;
126 const int DB_SELECT_MATCHING
= 3;
127 const int DB_SELECT_STATEMENT
= 4;
129 const int DB_UPD_KEYFIELDS
= 1;
130 const int DB_UPD_WHERE
= 2;
132 const int DB_DEL_KEYFIELDS
= 1;
133 const int DB_DEL_WHERE
= 2;
134 const int DB_DEL_MATCHING
= 3;
136 const int DB_WHERE_KEYFIELDS
= 1;
137 const int DB_WHERE_MATCHING
= 2;
139 const int DB_GRANT_SELECT
= 1;
140 const int DB_GRANT_INSERT
= 2;
141 const int DB_GRANT_UPDATE
= 4;
142 const int DB_GRANT_DELETE
= 8;
143 const int DB_GRANT_ALL
= DB_GRANT_SELECT
| DB_GRANT_INSERT
| DB_GRANT_UPDATE
| DB_GRANT_DELETE
;
145 // ODBC Error codes (derived from ODBC SqlState codes)
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'
243 struct wxDbConnectInf
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)
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
253 // Optionals needed for some databases like dBase
254 char defaultDir
[wxDB_PATH_MAX
]; // Directory that db file resides in
257 struct wxDbSqlTypeInfo
259 char TypeName
[DB_TYPE_NAME_LEN
];
263 // short MinimumScale;
268 class WXDLLEXPORT wxDbColFor
271 wxString s_Field
; // Formated String for Output
272 wxString s_Format
[7]; // Formated Objects - TIMESTAMP has the biggest (7)
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
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
282 int Format(int Nation
, int dbDataType
, SWORD sqlDataType
, short columnSize
, short decimalDigits
);
286 class WXDLLEXPORT wxDbColInf
291 char tableName
[DB_MAX_TABLE_NAME_LEN
+1];
292 char colName
[DB_MAX_COLUMN_NAME_LEN
+1];
294 char typeName
[128+1];
301 int dbDataType
; // conversion of the 'sqlDataType' to the generic data type used by these classes
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
307 wxDbColFor
*pColFor
; // How should this columns be formatted
316 class WXDLLEXPORT wxDbTableInf
// Description of a Table
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(..);
329 class WXDLLEXPORT wxDbInf
// Description of a Database
334 int numTables
; // How many tables does this database have
335 wxDbTableInf
*pTableInf
; // pTableInf = new wxDbTableInf[numTables];
348 // These are the databases currently tested and working with these classes
349 // See the comments in wxDb::Dbms() for exceptions/issues with
350 // each of these database engines
355 dbmsSYBASE_ASA
, // Adaptive Server Anywhere
356 dbmsSYBASE_ASE
, // Adaptive Server Enterprise
367 // The wxDb::errorList is copied to this variable when the wxDb object
368 // is closed. This way, the error list is still available after the
369 // database object is closed. This is necessary if the database
370 // connection fails so the calling application can show the operator
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
374 extern char DBerrorList
[DB_MAX_ERROR_HISTORY
][DB_MAX_ERROR_MSG_LEN
];
377 class WXDLLEXPORT wxDb
381 char *dsn
; // Data source name
382 char *uid
; // User ID
383 char *authStr
; // Authorization string (password)
384 FILE *fpSqlLog
; // Sql Log file pointer
385 wxDbSqlLogState sqlLogState
; // On or Off
388 // Private member functions
389 bool getDbInfo(void);
390 bool getDataTypeInfo(SWORD fSqlType
, wxDbSqlTypeInfo
&structSQLTypeInfo
);
391 bool setConnectionOptions(void);
392 void logError(const char *errMsg
, const char *SQLState
);
393 #if !wxODBC_BACKWARD_COMPATABILITY
395 HENV henv
; // ODBC Environment handle
396 HDBC hdbc
; // ODBC DB Connection handle
397 HSTMT hstmt
; // ODBC Statement handle
399 //Error reporting mode
402 // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
403 unsigned int nTables
;
405 // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
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
;
418 #if wxODBC_BACKWARD_COMPATABILITY
420 HENV henv
; // ODBC Environment handle
421 HDBC hdbc
; // ODBC DB Connection handle
422 HSTMT hstmt
; // ODBC Statement handle
424 //Error reporting mode
427 // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
428 unsigned int nTables
;
431 // The following structure contains database information gathered from the
432 // datasource when the datasource is first opened.
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
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.
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
473 wxChar errorList
[DB_MAX_ERROR_HISTORY
][DB_MAX_ERROR_MSG_LEN
];
474 wxChar errorMsg
[SQL_MAX_MESSAGE_LENGTH
];
478 #if wxODBC_BACKWARD_COMPATABILITY
479 // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
481 // This information is obtained from the ODBC driver by use of the
482 // SQLGetTypeInfo() function. The key piece of information is the
483 // type name the data source uses for each logical data type.
484 // e.g. VARCHAR; Oracle calls it VARCHAR2.
485 wxDbSqlTypeInfo typeInfVarchar
;
486 wxDbSqlTypeInfo typeInfInteger
;
487 wxDbSqlTypeInfo typeInfFloat
;
488 wxDbSqlTypeInfo typeInfDate
;
491 // Public member functions
492 wxDb(HENV
&aHenv
, bool FwdOnlyCursors
=(bool)wxODBC_FWD_ONLY_CURSORS
);
493 bool Open(char *Dsn
, char *Uid
, char *AuthStr
); // Data Source Name, User ID, Password
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
);
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");
506 int TranslateSqlState(const wxChar
*SQLState
);
507 wxDbInf
*GetCatalog(char *userID
);
508 bool Catalog(const char *userID
=NULL
, const char *fileName
= SQL_CATALOG_FILENAME
);
509 int GetKeyFields(char *tableName
, wxDbColInf
* colInf
, int nocols
);
511 wxDbColInf
*GetColumns(char *tableName
[], const char *userID
=NULL
);
512 wxDbColInf
*GetColumns(char *tableName
, int *numCols
, const char *userID
=NULL
);
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
;}
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
;}
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
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
533 void LogError(const char *errMsg
, const char *SQLState
= 0) {logError(errMsg
, SQLState
);}
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
);
538 bool FwdOnlyCursors(void) {return fwdOnlyCursors
;}
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; }
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.
554 wxDbList
*PtrPrev
; // Pointer to previous item in the list
555 wxChar Dsn
[SQL_MAX_DSN_LENGTH
+1]; // Data Source Name
556 wxDb
*PtrDb
; // Pointer to the wxDb object
557 bool Free
; // Is item free or in use?
558 wxDbList
*PtrNext
; // Pointer to next item in the list
562 #include "wx/object.h"
563 class wxTablesInUse
: public wxObject
566 const char *tableName
;
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
576 wxDb WXDLLEXPORT
*wxDbGetConnection(wxDbConnectInf
*pDbConfig
, bool FwdOnlyCursors
=(bool)wxODBC_FWD_ONLY_CURSORS
);
577 bool WXDLLEXPORT
wxDbFreeConnection(wxDb
*pDb
);
578 void WXDLLEXPORT
wxDbCloseConnections(void);
579 int WXDLLEXPORT
wxDbConnectionsInUse(void);
582 // This function sets the sql log state for all open wxDb objects
583 bool wxDbSqlLog(wxDbSqlLogState state
, const wxChar
*filename
= SQL_LOG_FILENAME
);
587 // MSW/VC6 ONLY!!! Experimental
588 int WXDLLEXPORT
wxDbCreateDataSource(const char *driverName
, const char *dsn
, const char *description
="",
589 bool sysDSN
=FALSE
, const char *defDir
="", wxWindow
*parent
=NULL
);
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.
596 bool WXDLLEXPORT
wxDbGetDataSource(HENV henv
, char *Dsn
, SWORD DsnMax
, char *DsDesc
, SWORD DsDescMax
,
597 UWORD direction
= SQL_FETCH_NEXT
);
600 // Change this to 0 to remove use of all deprecated functions
601 #if wxODBC_BACKWARD_COMPATABILITY
602 //#################################################################################
603 //############### DEPRECATED functions for backward compatability #################
604 //#################################################################################
606 // Backward compability structures/classes. This will eventually go away
607 const int DB_PATH_MAX
= wxDB_PATH_MAX
;
610 typedef wxDbTableInf wxTableInf
;
611 typedef wxDbColInf wxColInf
;
612 typedef wxDbColInf CcolInf
;
613 typedef wxDbColFor wxColFor
;
614 typedef wxDbSqlTypeInfo SqlTypeInfo
;
615 typedef wxDbSqlTypeInfo wxSqlTypeInfo
;
616 typedef enum wxDbSqlLogState sqlLog
;
617 typedef enum wxDbSqlLogState wxSqlLogState
;
618 typedef enum wxDBMS dbms
;
619 typedef enum wxDBMS DBMS
;
620 typedef wxODBC_ERRORS ODBC_ERRORS
;
621 typedef wxDbConnectInf DbStuff
;
622 typedef wxDbList DbList
;
624 typedef wxTablesInUse CstructTablesInUse
;
627 // Deprecated function names that are replaced by the function names listed above
628 wxDB WXDLLEXPORT
*GetDbConnection(DbStuff
*pDbStuff
, bool FwdOnlyCursors
=(bool)wxODBC_FWD_ONLY_CURSORS
);
629 bool WXDLLEXPORT
FreeDbConnection(wxDB
*pDb
);
630 void WXDLLEXPORT
CloseDbConnections(void);
631 int WXDLLEXPORT
NumberDbConnectionsInUse(void);
633 bool SqlLog(sqlLog state
, const wxChar
*filename
= SQL_LOG_FILENAME
);
635 bool WXDLLEXPORT
GetDataSource(HENV henv
, char *Dsn
, SWORD DsnMax
, char *DsDesc
, SWORD DsDescMax
,
636 UWORD direction
= SQL_FETCH_NEXT
);
637 #endif // Deprecated structures/classes/functions