]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/db.cpp
Fixed doubled-up key effects in wxTextCtrl by resetting m_lastMsg to 0
[wxWidgets.git] / src / common / db.cpp
index 1c2c703f42f245972b363864f80fe6314a1a197b..0096ce8eb33735d44b8b0b665fc51e6ed4d65a3c 100644 (file)
@@ -5,6 +5,8 @@
 //              source such as opening and closing the data source.
 // Author:      Doug Card
 // Modified by:
+// Mods:        Dec, 1998: Added support for SQL statement logging and database
+//              cataloging
 // Created:     9.96
 // RCS-ID:      $Id$
 // Copyright:   (c) 1996 Remstar International, Inc.
 //                 the wxWindows GUI development toolkit.
 ///////////////////////////////////////////////////////////////////////////////
 
+#ifdef __GNUG__
+#pragma implementation "db.h"
+#endif
+
 /*
 // SYNOPSIS START
 // SYNOPSIS STOP
 */
 
-#ifdef __GNUG__
-#pragma implementation "db.h"
-#endif
-
 /*
-#ifdef _CONSOLE
+#ifdef DBDEBUG_CONSOLE
        #include <iostream.h>
 #endif
 */
 
 #if wxUSE_ODBC
 
-#include <wx/db.h>
-
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include "wx/db.h"
 
-DbList *PtrBegDbList = 0;
+DbList* WXDLLEXPORT PtrBegDbList = 0;
 
 /********** wxDB Constructor **********/
 wxDB::wxDB(HENV &aHenv)
 {
        int i;
+
+       fpSqlLog                = 0;                            // Sql Log file pointer
+       sqlLogState = sqlLogOFF;        // By default, logging is turned off
        
        strcpy(sqlState,"");
        strcpy(errorMsg,"");
@@ -112,7 +118,7 @@ wxDB::wxDB(HENV &aHenv)
 /********** wxDB::Open() **********/
 bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr)
 {
-       assert(Dsn);
+       assert(Dsn && strlen(Dsn));
        dsn             = Dsn;
        uid             = Uid;
        authStr = AuthStr;
@@ -125,7 +131,7 @@ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr)
        // specified before the connection is made.
        retcode = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_IF_NEEDED);
 
-       #ifdef _CONSOLE
+       #ifdef DBDEBUG_CONSOLE
                if (retcode == SQL_SUCCESS)
                        cout << "SQLSetConnectOption(CURSOR_LIB) successful" << endl;
                else
@@ -240,7 +246,7 @@ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr)
        else
                typeInfDate.FsqlType = SQL_TIMESTAMP;
 
-#ifdef _CONSOLE
+#ifdef DBDEBUG_CONSOLE
        cout << "VARCHAR DATA TYPE: " << typeInfVarchar.TypeName << endl;
        cout << "INTEGER DATA TYPE: " << typeInfInteger.TypeName << endl;
        cout << "FLOAT   DATA TYPE: " << typeInfFloat.TypeName << endl;
@@ -262,7 +268,7 @@ bool wxDB::setConnectionOptions(void)
        SQLSetConnectOption(hdbc, SQL_OPT_TRACE, SQL_OPT_TRACE_OFF);
 
        // Display the connection options to verify them
-#ifdef _CONSOLE
+#ifdef DBDEBUG_CONSOLE
        long l;
        cout << ">>>>> CONNECTION OPTIONS <<<<<<" << endl;
        
@@ -304,97 +310,97 @@ bool wxDB::getDbInfo(void)
 {
        SWORD cb;
 
-       if (SQLGetInfo(hdbc, SQL_SERVER_NAME, dbInf.serverName, 40, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_SERVER_NAME, (UCHAR*) dbInf.serverName, 40, &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_DATABASE_NAME, dbInf.databaseName, 128, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_DATABASE_NAME, (UCHAR*) dbInf.databaseName, 128, &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_DBMS_NAME, dbInf.dbmsName, 40, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_DBMS_NAME, (UCHAR*) dbInf.dbmsName, 40, &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_DBMS_VER, dbInf.dbmsVer, 20, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_DBMS_VER, (UCHAR*) dbInf.dbmsVer, 40, &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_ACTIVE_CONNECTIONS, &dbInf.maxConnections, sizeof(dbInf.maxConnections), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_ACTIVE_CONNECTIONS, (UCHAR*) &dbInf.maxConnections, sizeof(dbInf.maxConnections), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_ACTIVE_STATEMENTS, &dbInf.maxStmts, sizeof(dbInf.maxStmts), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_ACTIVE_STATEMENTS, (UCHAR*) &dbInf.maxStmts, sizeof(dbInf.maxStmts), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_DRIVER_NAME, dbInf.driverName, 40, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_DRIVER_NAME, (UCHAR*) dbInf.driverName, 40, &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_DRIVER_ODBC_VER, dbInf.odbcVer, 20, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_DRIVER_ODBC_VER, (UCHAR*) dbInf.odbcVer, 60, &cb) == SQL_ERROR)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_ODBC_VER, dbInf.drvMgrOdbcVer, 20, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_ODBC_VER, (UCHAR*) dbInf.drvMgrOdbcVer, 60, &cb) == SQL_ERROR)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_DRIVER_VER, dbInf.driverVer, 40, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_DRIVER_VER, (UCHAR*) dbInf.driverVer, 60, &cb) == SQL_ERROR)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_ODBC_API_CONFORMANCE, &dbInf.apiConfLvl, sizeof(dbInf.apiConfLvl), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_ODBC_API_CONFORMANCE, (UCHAR*) &dbInf.apiConfLvl, sizeof(dbInf.apiConfLvl), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_ODBC_SAG_CLI_CONFORMANCE, &dbInf.cliConfLvl, sizeof(dbInf.cliConfLvl), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_ODBC_SAG_CLI_CONFORMANCE, (UCHAR*) &dbInf.cliConfLvl, sizeof(dbInf.cliConfLvl), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_ODBC_SQL_CONFORMANCE, &dbInf.sqlConfLvl, sizeof(dbInf.sqlConfLvl), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_ODBC_SQL_CONFORMANCE, (UCHAR*) &dbInf.sqlConfLvl, sizeof(dbInf.sqlConfLvl), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_OUTER_JOINS, dbInf.outerJoins, 2, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_OUTER_JOINS, (UCHAR*) dbInf.outerJoins, 2, &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_PROCEDURES, dbInf.procedureSupport, 2, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_PROCEDURES, (UCHAR*) dbInf.procedureSupport, 2, &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_CURSOR_COMMIT_BEHAVIOR, &dbInf.cursorCommitBehavior, sizeof(dbInf.cursorCommitBehavior), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_CURSOR_COMMIT_BEHAVIOR, (UCHAR*) &dbInf.cursorCommitBehavior, sizeof(dbInf.cursorCommitBehavior), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_CURSOR_ROLLBACK_BEHAVIOR, &dbInf.cursorRollbackBehavior, sizeof(dbInf.cursorRollbackBehavior), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_CURSOR_ROLLBACK_BEHAVIOR, (UCHAR*) &dbInf.cursorRollbackBehavior, sizeof(dbInf.cursorRollbackBehavior), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_NON_NULLABLE_COLUMNS, &dbInf.supportNotNullClause, sizeof(dbInf.supportNotNullClause), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_NON_NULLABLE_COLUMNS, (UCHAR*) &dbInf.supportNotNullClause, sizeof(dbInf.supportNotNullClause), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_ODBC_SQL_OPT_IEF, dbInf.supportIEF, 2, &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_ODBC_SQL_OPT_IEF, (UCHAR*) dbInf.supportIEF, 2, &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_DEFAULT_TXN_ISOLATION, &dbInf.txnIsolation, sizeof(dbInf.txnIsolation), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_DEFAULT_TXN_ISOLATION, (UCHAR*) &dbInf.txnIsolation, sizeof(dbInf.txnIsolation), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_TXN_ISOLATION_OPTION, &dbInf.txnIsolationOptions, sizeof(dbInf.txnIsolationOptions), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_TXN_ISOLATION_OPTION, (UCHAR*) &dbInf.txnIsolationOptions, sizeof(dbInf.txnIsolationOptions), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_FETCH_DIRECTION, &dbInf.fetchDirections, sizeof(dbInf.fetchDirections), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_FETCH_DIRECTION, (UCHAR*) &dbInf.fetchDirections, sizeof(dbInf.fetchDirections), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_LOCK_TYPES, &dbInf.lockTypes, sizeof(dbInf.lockTypes), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_LOCK_TYPES, (UCHAR*) &dbInf.lockTypes, sizeof(dbInf.lockTypes), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_POS_OPERATIONS, &dbInf.posOperations, sizeof(dbInf.posOperations), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_POS_OPERATIONS, (UCHAR*) &dbInf.posOperations, sizeof(dbInf.posOperations), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_POSITIONED_STATEMENTS, &dbInf.posStmts, sizeof(dbInf.posStmts), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_POSITIONED_STATEMENTS, (UCHAR*) &dbInf.posStmts, sizeof(dbInf.posStmts), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_SCROLL_CONCURRENCY, &dbInf.scrollConcurrency, sizeof(dbInf.scrollConcurrency), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_SCROLL_CONCURRENCY, (UCHAR*) &dbInf.scrollConcurrency, sizeof(dbInf.scrollConcurrency), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_SCROLL_OPTIONS, &dbInf.scrollOptions, sizeof(dbInf.scrollOptions), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_SCROLL_OPTIONS, (UCHAR*) &dbInf.scrollOptions, sizeof(dbInf.scrollOptions), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_STATIC_SENSITIVITY, &dbInf.staticSensitivity, sizeof(dbInf.staticSensitivity), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_STATIC_SENSITIVITY, (UCHAR*) &dbInf.staticSensitivity, sizeof(dbInf.staticSensitivity), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_TXN_CAPABLE, &dbInf.txnCapable, sizeof(dbInf.txnCapable), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_TXN_CAPABLE, (UCHAR*) &dbInf.txnCapable, sizeof(dbInf.txnCapable), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-       if (SQLGetInfo(hdbc, SQL_LOGIN_TIMEOUT, &dbInf.loginTimeout, sizeof(dbInf.loginTimeout), &cb) != SQL_SUCCESS)
+       if (SQLGetInfo(hdbc, SQL_LOGIN_TIMEOUT, (UCHAR*) &dbInf.loginTimeout, sizeof(dbInf.loginTimeout), &cb) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc));
 
-#ifdef _CONSOLE
+#ifdef DBDEBUG_CONSOLE
        cout << ">>>>> DATA SOURCE INFORMATION <<<<<" << endl;
        cout << "SERVER Name: " << dbInf.serverName << endl;
        cout << "DBMS Name: " << dbInf.dbmsName << "; DBMS Version: " << dbInf.dbmsVer << endl;
@@ -612,7 +618,7 @@ bool wxDB::getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo)
        // Fetch the record
        if ((retcode = SQLFetch(hstmt)) != SQL_SUCCESS)
        {
-#ifdef _CONSOLE
+#ifdef DBDEBUG_CONSOLE
                if (retcode == SQL_NO_DATA_FOUND)
                        cout << "SQL_NO_DATA_FOUND fetching inf. about data type." << endl;
 #endif
@@ -621,15 +627,15 @@ bool wxDB::getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo)
                return(FALSE);
        }
        // Obtain columns from the record
-       if (SQLGetData(hstmt, 1, SQL_C_CHAR, structSQLTypeInfo.TypeName, DB_TYPE_NAME_LEN, &cbRet) != SQL_SUCCESS)
+       if (SQLGetData(hstmt, 1, SQL_C_CHAR, (UCHAR*) structSQLTypeInfo.TypeName, DB_TYPE_NAME_LEN, &cbRet) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc, hstmt));
-       if (SQLGetData(hstmt, 3, SQL_C_LONG, &structSQLTypeInfo.Precision, 0, &cbRet) != SQL_SUCCESS)
+       if (SQLGetData(hstmt, 3, SQL_C_LONG, (UCHAR*) &structSQLTypeInfo.Precision, 0, &cbRet) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc, hstmt));
-       if (SQLGetData(hstmt, 8, SQL_C_SHORT, &structSQLTypeInfo.CaseSensitive, 0, &cbRet) != SQL_SUCCESS)
+       if (SQLGetData(hstmt, 8, SQL_C_SHORT, (UCHAR*) &structSQLTypeInfo.CaseSensitive, 0, &cbRet) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc, hstmt));
-//     if (SQLGetData(hstmt, 14, SQL_C_SHORT, &structSQLTypeInfo.MinimumScale, 0, &cbRet) != SQL_SUCCESS)
+//     if (SQLGetData(hstmt, 14, SQL_C_SHORT, (UCHAR*) &structSQLTypeInfo.MinimumScale, 0, &cbRet) != SQL_SUCCESS)
 //             return(DispAllErrors(henv, hdbc, hstmt));
-       if (SQLGetData(hstmt, 15, SQL_C_SHORT, &structSQLTypeInfo.MaximumScale, 0, &cbRet) != SQL_SUCCESS)
+       if (SQLGetData(hstmt, 15, SQL_C_SHORT, (UCHAR*) &structSQLTypeInfo.MaximumScale, 0, &cbRet) != SQL_SUCCESS)
                return(DispAllErrors(henv, hdbc, hstmt));
 
        if (structSQLTypeInfo.MaximumScale < 0)
@@ -647,6 +653,13 @@ bool wxDB::getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo)
 /********** wxDB::Close() **********/
 void wxDB::Close(void)
 {
+       // Close the Sql Log file
+       if (fpSqlLog)
+       {
+               fclose(fpSqlLog);
+               fpSqlLog = 0;  //glt
+       }
+
        // Free statement handle
        if (dbIsOpen)
        {
@@ -699,7 +712,7 @@ bool wxDB::DispAllErrors(HENV aHenv, HDBC aHdbc, HSTMT aHstmt)
                logError(odbcErrMsg, sqlState);
                if (!silent)
                {
-#ifdef _CONSOLE
+#ifdef DBDEBUG_CONSOLE
                        // When run in console mode, use standard out to display errors.
                        cout << odbcErrMsg << endl;
                        cout << "Press any key to continue..." << endl;
@@ -733,7 +746,7 @@ void wxDB::DispNextError(void)
        if (silent)
                return;
 
-#ifdef _CONSOLE
+#ifdef DBDEBUG_CONSOLE
        // When run in console mode, use standard out to display errors.
        cout << odbcErrMsg << endl;
        cout << "Press any key to continue..."  << endl;
@@ -994,10 +1007,12 @@ bool wxDB::Grant(int privileges, char *tableName, char *userList)
        strcat(sqlStmt, " TO ");
        strcat(sqlStmt, userList);
 
-#ifdef _CONSOLE
+#ifdef DBDEBUG_CONSOLE
        cout << endl << sqlStmt << endl;
 #endif
 
+       WriteSqlLog(sqlStmt);
+
        return(ExecSql(sqlStmt));
 
 }  // wxDB::Grant()
@@ -1025,7 +1040,9 @@ bool wxDB::CreateView(char *viewName, char *colList, char *pSqlStmt)
                }
        }
 
-#ifdef _CONSOLE
+       WriteSqlLog(sqlStmt);
+
+#ifdef DBDEBUG_CONSOLE
        cout << endl << sqlStmt << endl;
 #endif
 
@@ -1043,7 +1060,9 @@ bool wxDB::CreateView(char *viewName, char *colList, char *pSqlStmt)
        strcat(sqlStmt, " AS ");
        strcat(sqlStmt, pSqlStmt);
 
-#ifdef _CONSOLE
+       WriteSqlLog(sqlStmt);
+
+#ifdef DBDEBUG_CONSOLE
        cout << sqlStmt << endl;
 #endif
 
@@ -1127,9 +1146,9 @@ CcolInf *wxDB::GetColumns(char *tableName[])
                                        delete [] colInf;
                                return(0);
                        }
-                       SQLBindCol(hstmt, 3, SQL_C_CHAR,   tblName,      DB_MAX_TABLE_NAME_LEN+1,  &cb);
-                       SQLBindCol(hstmt, 4, SQL_C_CHAR,   colName,      DB_MAX_COLUMN_NAME_LEN+1, &cb);
-                       SQLBindCol(hstmt, 5, SQL_C_SSHORT, &sqlDataType, 0,                        &cb);
+                       SQLBindCol(hstmt, 3, SQL_C_CHAR,   (UCHAR*) tblName,      DB_MAX_TABLE_NAME_LEN+1,  &cb);
+                       SQLBindCol(hstmt, 4, SQL_C_CHAR,   (UCHAR*) colName,      DB_MAX_COLUMN_NAME_LEN+1, &cb);
+                       SQLBindCol(hstmt, 5, SQL_C_SSHORT, (UCHAR*) &sqlDataType, 0,                        &cb);
                        while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
                        {
                                if (pass == 1)  // First pass, just add up the number of columns
@@ -1161,6 +1180,101 @@ CcolInf *wxDB::GetColumns(char *tableName[])
 }  // wxDB::GetColumns()
 
 
+/********** wxDB::Catalog() **********/
+bool wxDB::Catalog(char *userID, char *fileName)
+{
+       assert(userID && strlen(userID));
+       assert(fileName && strlen(fileName));
+
+       RETCODE retcode;
+       SDWORD  cb;
+       char            tblName[DB_MAX_TABLE_NAME_LEN+1];
+       char            tblNameSave[DB_MAX_TABLE_NAME_LEN+1];
+       char            colName[DB_MAX_COLUMN_NAME_LEN+1];
+       SWORD           sqlDataType;
+       char            typeName[16];
+       SWORD           precision, length;
+
+       FILE *fp = fopen(fileName,"wt");
+       if (fp == NULL)
+               return(FALSE);
+
+       SQLFreeStmt(hstmt, SQL_CLOSE);
+
+       int i = 0;
+       char userIdUC[81];
+       for (char *p = userID; *p; p++)
+               userIdUC[i++] = toupper(*p);
+       userIdUC[i] = 0;
+
+       retcode = SQLColumns(hstmt,
+                                                               NULL, 0,                                                                                        // All qualifiers
+                                                               (UCHAR *) userIdUC, SQL_NTS,                            // User specified
+                                                               NULL, 0,                                                                                        // All tables
+                                                               NULL, 0);                                                                               // All columns
+       if (retcode != SQL_SUCCESS)
+       {
+               DispAllErrors(henv, hdbc, hstmt);
+               fclose(fp);
+               return(FALSE);
+       }
+
+       SQLBindCol(hstmt, 3, SQL_C_CHAR,   (UCHAR*) tblName,      DB_MAX_TABLE_NAME_LEN+1,  &cb);
+       SQLBindCol(hstmt, 4, SQL_C_CHAR,   (UCHAR*) colName,      DB_MAX_COLUMN_NAME_LEN+1, &cb);
+       SQLBindCol(hstmt, 5, SQL_C_SSHORT, (UCHAR*) &sqlDataType, 0,                        &cb);
+       SQLBindCol(hstmt, 6, SQL_C_CHAR,   (UCHAR*) typeName,            16,                       &cb);
+       SQLBindCol(hstmt, 7, SQL_C_SSHORT, (UCHAR*) &precision,  0,                        &cb);
+       SQLBindCol(hstmt, 8, SQL_C_SSHORT, (UCHAR*) &length,     0,                        &cb);
+
+       char outStr[256];
+       strcpy(tblNameSave,"");
+       int cnt = 0;
+
+       while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
+       {
+               if (strcmp(tblName,tblNameSave))
+               {
+                       if (cnt)
+                               fputs("\n", fp);
+                       fputs("================================ ", fp);
+                       fputs("================================ ", fp);
+                       fputs("===================== ", fp);
+                       fputs("========= ", fp);
+                       fputs("=========\n", fp);
+                       sprintf(outStr, "%-32s %-32s %-21s %9s %9s\n",
+                               "TABLE NAME", "COLUMN NAME", "DATA TYPE", "PRECISION", "LENGTH");
+                       fputs(outStr, fp);
+                       fputs("================================ ", fp);
+                       fputs("================================ ", fp);
+                       fputs("===================== ", fp);
+                       fputs("========= ", fp);
+                       fputs("=========\n", fp);
+                       strcpy(tblNameSave,tblName);
+               }
+               sprintf(outStr, "%-32s %-32s (%04d)%-15s %9d %9d\n",
+                       tblName, colName, sqlDataType, typeName, precision, length);
+               if (fputs(outStr, fp) == EOF)
+               {
+                       fclose(fp);
+                       return(FALSE);
+               }
+               cnt++;
+       }
+
+       if (retcode != SQL_NO_DATA_FOUND)
+       {
+               DispAllErrors(henv, hdbc, hstmt);
+               fclose(fp);
+               return(FALSE);
+       }
+
+       SQLFreeStmt(hstmt, SQL_CLOSE);
+       fclose(fp);
+       return(TRUE);
+
+}  // wxDB::Catalog()
+
+
 // Table name can refer to a table, view, alias or synonym.  Returns true
 // if the object exists in the database.  This function does not indicate
 // whether or not the user has privleges to query or perform other functions
@@ -1190,8 +1304,56 @@ bool wxDB::TableExists(char *tableName)
 }  // wxDB::TableExists()
 
 
+/********** wxDB::SqlLog() **********/
+bool wxDB::SqlLog(enum sqlLog state, char *filename, bool append)
+{
+       assert(state == sqlLogON  || state == sqlLogOFF);
+       assert(state == sqlLogOFF || filename);
+
+       if (state == sqlLogON)
+       {
+               if (fpSqlLog == 0)
+               {
+                       fpSqlLog = fopen(filename, (append ? "at" : "wt"));
+                       if (fpSqlLog == NULL)
+                               return(FALSE);
+               }
+       }
+       else  // sqlLogOFF
+       {
+               if (fpSqlLog)
+               {
+                       if (fclose(fpSqlLog))
+                               return(FALSE);
+                       fpSqlLog = 0;
+               }
+       }
+
+       sqlLogState = state;
+       return(TRUE);
+
+}  // wxDB::SqlLog()
+
+
+/********** wxDB::WriteSqlLog() **********/
+bool wxDB::WriteSqlLog(char *logMsg)
+{
+       assert(logMsg);
+
+       if (fpSqlLog == 0 || sqlLogState == sqlLogOFF)
+               return(FALSE);
+
+       if (fputs("\n",   fpSqlLog) == EOF) return(FALSE);
+       if (fputs(logMsg, fpSqlLog) == EOF) return(FALSE);
+       if (fputs("\n",   fpSqlLog) == EOF) return(FALSE);
+
+       return(TRUE);
+
+}  // wxDB::WriteSqlLog()
+
+
 /********** GetDbConnection() **********/
-wxDB *GetDbConnection(DbStuff *pDbStuff)
+wxDB* WXDLLEXPORT GetDbConnection(DbStuff *pDbStuff)
 {
        DbList *pList;
 
@@ -1251,7 +1413,7 @@ wxDB *GetDbConnection(DbStuff *pDbStuff)
 }  // GetDbConnection()
 
 /********** FreeDbConnection() **********/
-bool FreeDbConnection(wxDB *pDb)
+bool WXDLLEXPORT FreeDbConnection(wxDB *pDb)
 {
        DbList *pList;
 
@@ -1268,7 +1430,7 @@ bool FreeDbConnection(wxDB *pDb)
 }  // FreeDbConnection()
 
 /********** CloseDbConnections() **********/
-void CloseDbConnections(void)
+void WXDLLEXPORT CloseDbConnections(void)
 {
        DbList *pList, *pNext;
        
@@ -1288,7 +1450,7 @@ void CloseDbConnections(void)
 }  // CloseDbConnections()
 
 /********** NumberDbConnectionsInUse() **********/
-int NumberDbConnectionsInUse(void)
+int WXDLLEXPORT NumberDbConnectionsInUse(void)
 {
        DbList *pList;
        int cnt = 0;
@@ -1319,4 +1481,5 @@ bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDes
 }  // GetDataSource()
 
 #endif
-    // wxUSE_ODBC
+ // wxUSE_ODBC
+