- // The following structure contains database information gathered from the
- // datasource when the datasource is first opened.
- struct
- {
- char dbmsName[40]; // Name of the dbms product
- char dbmsVer[20]; // Version # of the dbms product
- char driverName[40]; // Driver name
- char odbcVer[20]; // ODBC version of the driver
- char drvMgrOdbcVer[20]; // ODBC version of the driver manager
- char driverVer[40]; // Driver version
- char serverName[40]; // Server Name, typically a connect string
- char databaseName[128]; // Database filename
- char outerJoins[2]; // Indicates whether the data source supports outer joins
- char procedureSupport[2]; // Indicates whether the data source supports stored procedures
- UWORD maxConnections; // Maximum # of connections the data source supports
- UWORD maxStmts; // Maximum # of HSTMTs per HDBC
- UWORD apiConfLvl; // ODBC API conformance level
- UWORD cliConfLvl; // Indicates whether the data source is SAG compliant
- UWORD sqlConfLvl; // SQL conformance level
- UWORD cursorCommitBehavior; // Indicates how cursors are affected by a db commit
- UWORD cursorRollbackBehavior; // Indicates how cursors are affected by a db rollback
- UWORD supportNotNullClause; // Indicates if data source supports NOT NULL clause
- char supportIEF[2]; // Integrity Enhancement Facility (Referential Integrity)
- UDWORD txnIsolation; // Default transaction isolation level supported by the driver
- UDWORD txnIsolationOptions; // Transaction isolation level options available
- UDWORD fetchDirections; // Fetch directions supported
- UDWORD lockTypes; // Lock types supported in SQLSetPos
- UDWORD posOperations; // Position operations supported in SQLSetPos
- UDWORD posStmts; // Position statements supported
- UDWORD scrollConcurrency; // Concurrency control options supported for scrollable cursors
- UDWORD scrollOptions; // Scroll Options supported for scrollable cursors
- UDWORD staticSensitivity; // Indicates if additions, deletions and updates can be detected
- UWORD txnCapable; // Indicates if the data source supports transactions
- UDWORD loginTimeout; // Number seconds to wait for a login request
- } dbInf;
-
- // ODBC handles
- HENV henv; // ODBC Environment handle
- HDBC hdbc; // ODBC DB Connection handle
- HSTMT hstmt; // ODBC Statement handle
-
- // ODBC Error Inf.
- char sqlState[20];
- SDWORD nativeError;
- char errorMsg[SQL_MAX_MESSAGE_LENGTH];
- SWORD cbErrorMsg;
- char errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
- int DB_STATUS;
-
- //Error reporting mode
- bool silent;
-
- // Inf. about logical data types VARCHAR, INTEGER, FLOAT and DATE.
- // This inf. is obtained from the ODBC driver by use of the
- // SQLGetTypeInfo() function. The key piece of inf. is the
- // type name the data source uses for each logical data type.
- // e.g. VARCHAR; Oracle calls it VARCHAR2.
- SqlTypeInfo typeInfVarchar, typeInfInteger, typeInfFloat, typeInfDate;
-
- // Public member functions
- wxDB(HENV &aHenv);
- bool Open(char *Dsn, char *Uid, char *AuthStr); // Data Source Name, User ID, Password
- void Close(void);
- bool CommitTrans(void);
- bool RollbackTrans(void);
- bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT);
- bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT);
- void DispNextError(void);
- bool CreateView(char *viewName, char *colList, char *pSqlStmt);
- bool ExecSql(char *pSqlStmt);
- bool Grant(int privileges, char *tableName, char *userList = "PUBLIC");
- int TranslateSqlState(char *SQLState);
- bool Catalog(char *userID, char *fileName = "Catalog.txt");
- CcolInf *GetColumns(char *tableName[]);
- char *GetDatabaseName(void) {return dbInf.dbmsName;}
- char *GetDataSource(void) {return dsn;}
- char *GetUsername(void) {return uid;}
- char *GetPassword(void) {return authStr;}
- bool IsOpen(void) {return dbIsOpen;}
- HENV GetHENV(void) {return henv;}
- HDBC GetHDBC(void) {return hdbc;}
- HSTMT GetHSTMT(void) {return hstmt;}
- bool TableExists(char *tableName); // Table name can refer to a table, view, alias or synonym
- void LogError(char *errMsg, char *SQLState = 0) {logError(errMsg, SQLState);}
- bool SqlLog(enum sqlLog state, char *filename = "sqllog.txt", bool append = FALSE);
- bool WriteSqlLog(char *logMsg);
-
-}; // wxDB
+ void setCached(bool cached) { dbIsCached = cached; }; // This function must only be called by wxDbGetConnection() and wxDbCloseConnections!!!
+ bool IsCached() { return dbIsCached; };
+
+ bool GetDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo)
+ { return getDataTypeInfo(fSqlType, structSQLTypeInfo); }
+
+#if wxODBC_BACKWARD_COMPATABILITY
+ // ODBC handles
+ HENV henv; // ODBC Environment handle
+ HDBC hdbc; // ODBC DB Connection handle
+ HSTMT hstmt; // ODBC Statement handle
+
+ //Error reporting mode
+ bool silent;
+
+ // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
+ unsigned int nTables;
+#endif
+
+ // The following structure contains database information gathered from the
+ // datasource when the datasource is first opened.
+ struct
+ {
+ wxChar dbmsName[40]; // Name of the dbms product
+ wxChar dbmsVer[64]; // Version # of the dbms product
+ wxChar driverName[40]; // Driver name
+ wxChar odbcVer[60]; // ODBC version of the driver
+ wxChar drvMgrOdbcVer[60]; // ODBC version of the driver manager
+ wxChar driverVer[60]; // Driver version
+ wxChar serverName[80]; // Server Name, typically a connect string
+ wxChar databaseName[128]; // Database filename
+ wxChar outerJoins[2]; // Indicates whether the data source supports outer joins
+ wxChar procedureSupport[2]; // Indicates whether the data source supports stored procedures
+ wxChar accessibleTables[2]; // Indicates whether the data source only reports accessible tables in SQLTables.
+ UWORD maxConnections; // Maximum # of connections the data source supports
+ UWORD maxStmts; // Maximum # of HSTMTs per HDBC
+ UWORD apiConfLvl; // ODBC API conformance level
+ UWORD cliConfLvl; // Indicates whether the data source is SAG compliant
+ UWORD sqlConfLvl; // SQL conformance level
+ UWORD cursorCommitBehavior; // Indicates how cursors are affected by a db commit
+ UWORD cursorRollbackBehavior; // Indicates how cursors are affected by a db rollback
+ UWORD supportNotNullClause; // Indicates if data source supports NOT NULL clause
+ wxChar supportIEF[2]; // Integrity Enhancement Facility (Referential Integrity)
+ UDWORD txnIsolation; // Default transaction isolation level supported by the driver
+ UDWORD txnIsolationOptions; // Transaction isolation level options available
+ UDWORD fetchDirections; // Fetch directions supported
+ UDWORD lockTypes; // Lock types supported in SQLSetPos
+ UDWORD posOperations; // Position operations supported in SQLSetPos
+ UDWORD posStmts; // Position statements supported
+ UDWORD scrollConcurrency; // Concurrency control options supported for scrollable cursors
+ UDWORD scrollOptions; // Scroll Options supported for scrollable cursors
+ UDWORD staticSensitivity; // Indicates if additions, deletions and updates can be detected
+ UWORD txnCapable; // Indicates if the data source supports transactions
+ UDWORD loginTimeout; // Number seconds to wait for a login request
+ } dbInf;
+
+ // ODBC Error Inf.
+ SWORD cbErrorMsg;
+ int DB_STATUS;
+#ifdef __VMS
+ // The DECC compiler chokes when in db.cpp the array is accessed outside
+ // its bounds. Maybe this change should also applied for other platforms.
+ wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN+1];
+#else
+ wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
+#endif
+ wxChar errorMsg[SQL_MAX_MESSAGE_LENGTH];
+ SQLINTEGER nativeError;
+ wxChar sqlState[20];
+
+#if wxODBC_BACKWARD_COMPATABILITY
+ // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
+ //
+ // This information is obtained from the ODBC driver by use of the
+ // SQLGetTypeInfo() function. The key piece of information is the
+ // type name the data source uses for each logical data type.
+ // e.g. VARCHAR; Oracle calls it VARCHAR2.
+ wxDbSqlTypeInfo typeInfVarchar;
+ wxDbSqlTypeInfo typeInfInteger;
+ wxDbSqlTypeInfo typeInfFloat;
+ wxDbSqlTypeInfo typeInfDate;
+ wxDbSqlTypeInfo typeInfBlob;
+#endif
+
+ // Public member functions
+ wxDb(const HENV &aHenv, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
+ ~wxDb();
+
+ // Data Source Name, User ID, Password and whether open should fail on data type not supported
+ bool Open(const wxString& inConnectStr, bool failOnDataTypeUnsupported=true);
+ ///This version of Open will open the odbc source selection dialog. Cast a wxWindow::GetHandle() to SQLHWND to use.
+ bool Open(const wxString& inConnectStr, SQLHWND parentWnd, bool failOnDataTypeUnsupported=true);
+ bool Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr, bool failOnDataTypeUnsupported=true);
+ bool Open(wxDbConnectInf *dbConnectInf, bool failOnDataTypeUnsupported=true);
+ bool Open(wxDb *copyDb); // pointer to a wxDb whose connection info should be copied rather than re-queried
+ void Close(void);
+ bool CommitTrans(void);
+ bool RollbackTrans(void);
+ bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT);
+ bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT);
+ void DispNextError(void);
+ bool CreateView(const wxString &viewName, const wxString &colList, const wxString &pSqlStmt, bool attemptDrop=true);
+ bool DropView(const wxString &viewName);
+ bool ExecSql(const wxString &pSqlStmt);
+ bool ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcols);
+ bool GetNext(void);
+ bool GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SQLLEN FAR *cbReturned);
+ bool Grant(int privileges, const wxString &tableName, const wxString &userList = wxT("PUBLIC"));
+ int TranslateSqlState(const wxString &SQLState);
+ wxDbInf *GetCatalog(const wxChar *userID=NULL);
+ bool Catalog(const wxChar *userID=NULL, const wxString &fileName=SQL_CATALOG_FILENAME);
+ int GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCols);
+
+ wxDbColInf *GetColumns(wxChar *tableName[], const wxChar *userID=NULL);
+ wxDbColInf *GetColumns(const wxString &tableName, UWORD *numCols, const wxChar *userID=NULL);
+
+ int GetColumnCount(const wxString &tableName, const wxChar *userID=NULL);
+ const wxChar *GetDatabaseName(void) {return dbInf.dbmsName;}
+ const wxString &GetDataSource(void) {return dsn;}
+ const wxString &GetDatasourceName(void){return dsn;}
+ const wxString &GetUsername(void) {return uid;}
+ const wxString &GetPassword(void) {return authStr;}
+ const wxString &GetConnectionInStr(void) {return inConnectionStr;}
+ const wxString &GetConnectionOutStr(void) {return outConnectionStr;}
+ bool IsOpen(void) {return dbIsOpen;}
+ bool OpenedWithConnectionString(void) {return dbOpenedWithConnectionString;}
+ HENV GetHENV(void) {return henv;}
+ HDBC GetHDBC(void) {return hdbc;}
+ HSTMT GetHSTMT(void) {return hstmt;}
+ int GetTableCount() {return nTables;} // number of tables using this connection
+ wxDbSqlTypeInfo GetTypeInfVarchar() {return typeInfVarchar;}
+ wxDbSqlTypeInfo GetTypeInfInteger() {return typeInfInteger;}
+ wxDbSqlTypeInfo GetTypeInfFloat() {return typeInfFloat;}
+ wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;}
+ wxDbSqlTypeInfo GetTypeInfBlob() {return typeInfBlob;}
+ wxDbSqlTypeInfo GetTypeInfMemo() {return typeInfMemo;}
+
+ // tableName can refer to a table, view, alias or synonym
+ bool TableExists(const wxString &tableName, const wxChar *userID=NULL,
+ const wxString &tablePath=wxEmptyString);
+ bool TablePrivileges(const wxString &tableName, const wxString &priv,
+ const wxChar *userID=NULL, const wxChar *schema=NULL,
+ const wxString &path=wxEmptyString);
+
+ // These two functions return the table name or column name in a form ready
+ // for use in SQL statements. For example, if the datasource allows spaces
+ // in the table name or column name, the returned string will have the
+ // correct enclosing marks around the name to allow it to be properly
+ // included in a SQL statement
+ const wxString SQLTableName(const wxChar *tableName);
+ const wxString SQLColumnName(const wxChar *colName);
+
+ void LogError(const wxString &errMsg, const wxString &SQLState = wxEmptyString)
+ { logError(errMsg, SQLState); }
+ void SetDebugErrorMessages(bool state) { silent = !state; }
+ bool SetSqlLogging(wxDbSqlLogState state, const wxString &filename = SQL_LOG_FILENAME,
+ bool append = false);
+ bool WriteSqlLog(const wxString &logMsg);
+
+ wxDBMS Dbms(void);
+ bool ModifyColumn(const wxString &tableName, const wxString &columnName,
+ int dataType, ULONG columnLength=0,
+ const wxString &optionalParam=wxEmptyString);
+
+ bool FwdOnlyCursors(void) {return fwdOnlyCursors;}
+
+ // These two functions are provided strictly for use by wxDbTable.
+ // DO NOT USE THESE FUNCTIONS, OR MEMORY LEAKS MAY OCCUR
+ void incrementTableCount() { nTables++; return; }
+ void decrementTableCount() { nTables--; return; }
+
+}; // wxDb
+