]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dbtable.cpp
X property data is long for format 32
[wxWidgets.git] / src / common / dbtable.cpp
index 65e863bcc031e4671ef3789f3bbc9f3fa9052f2f..ac9981425e04ce32a4ce0a5abb091628d593f85b 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        dbtable.cpp
+// Name:        src/common/dbtable.cpp
 // Purpose:     Implementation of the wxDbTable class.
 // Author:      Doug Card
 // Modified by: George Tasker
 // Purpose:     Implementation of the wxDbTable class.
 // Author:      Doug Card
 // Modified by: George Tasker
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
-/*
-// SYNOPSIS START
-// SYNOPSIS STOP
-*/
-
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-    #pragma implementation "dbtable.h"
-#endif
-
 #include  "wx/wxprec.h"
 
 #ifdef __BORLANDC__
     #pragma hdrstop
 #endif
 
 #include  "wx/wxprec.h"
 
 #ifdef __BORLANDC__
     #pragma hdrstop
 #endif
 
-#ifdef DBDEBUG_CONSOLE
-#if wxUSE_IOSTREAMH
-    #include <iostream.h>
-#else
-    #include <iostream>
-#endif
-    #include "wx/ioswrap.h"
-#endif
+#if wxUSE_ODBC
 
 #ifndef WX_PRECOMP
 
 #ifndef WX_PRECOMP
-    #include "wx/string.h"
     #include "wx/object.h"
     #include "wx/list.h"
     #include "wx/object.h"
     #include "wx/list.h"
+    #include "wx/string.h"
     #include "wx/utils.h"
     #include "wx/log.h"
     #include "wx/utils.h"
     #include "wx/log.h"
+    #include "wx/crt.h"
 #endif
 #endif
-#include "wx/filefn.h"
 
 
-#if wxUSE_ODBC
+#ifdef DBDEBUG_CONSOLE
+    #include "wx/ioswrap.h"
+#endif
+
+#include "wx/filefn.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include "wx/dbtable.h"
 
 
 #include "wx/dbtable.h"
 
-#ifdef __UNIX__
-// The HPUX preprocessor lines below were commented out on 8/20/97
-// because macros.h currently redefines DEBUG and is unneeded.
-// #  ifdef HPUX
-// #    include <macros.h>
-// #  endif
-#  ifdef LINUX
-#    include <sys/minmax.h>
-#  endif
+// FIXME-UTF8: get rid of this after switching to Unicode-only builds:
+#if wxUSE_UNICODE
+    #define WXSQLCAST(s) ((SQLTCHAR FAR *)(wchar_t*)(s).wchar_str())
+#else
+    #define WXSQLCAST(s) ((SQLTCHAR FAR *)(char*)(s).char_str())
 #endif
 
 ULONG lastTableID = 0;
 
 
 #ifdef __WXDEBUG__
 #endif
 
 ULONG lastTableID = 0;
 
 
 #ifdef __WXDEBUG__
+    #include "wx/thread.h"
+
     wxList TablesInUse;
     wxList TablesInUse;
+    wxCriticalSection csTablesInUse;
 #endif
 
 
 void csstrncpyt(wxChar *target, const wxChar *source, int n)
 {
 #endif
 
 
 void csstrncpyt(wxChar *target, const wxChar *source, int n)
 {
-    while ( (*target++ = *source++) != '\0' && --n )
+    while ( (*target++ = *source++) != '\0' && --n != 0 )
         ;
 
     *target = '\0';
         ;
 
     *target = '\0';
@@ -101,6 +88,7 @@ bool wxDbColDef::Initialize()
     DerivedCol      = false;
     CbValue         = 0;
     Null            = false;
     DerivedCol      = false;
     CbValue         = 0;
     Null            = false;
+    CbValueCol      = 0;
 
     return true;
 }  // wxDbColDef::Initialize()
 
     return true;
 }  // wxDbColDef::Initialize()
@@ -115,19 +103,6 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumn
 }  // wxDbTable::wxDbTable()
 
 
 }  // wxDbTable::wxDbTable()
 
 
-/***** DEPRECATED: use wxDbTable::wxDbTable() format above *****/
-#if WXWIN_COMPATIBILITY_2_4
-wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
-                    const wxChar *qryTblName, bool qryOnly, const wxString &tblPath)
-{
-    wxString tempQryTblName;
-    tempQryTblName = qryTblName;
-    if (!initialize(pwxDb, tblName, numColumns, tempQryTblName, qryOnly, tblPath))
-        cleanup();
-}  // wxDbTable::wxDbTable()
-#endif // WXWIN_COMPATIBILITY_2_4
-
-
 /********** wxDbTable::~wxDbTable() **********/
 wxDbTable::~wxDbTable()
 {
 /********** wxDbTable::~wxDbTable() **********/
 wxDbTable::~wxDbTable()
 {
@@ -163,7 +138,7 @@ bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD num
     tableName.Empty();
     queryTableName.Empty();
 
     tableName.Empty();
     queryTableName.Empty();
 
-    wxASSERT(tblName.Length());
+    wxASSERT(tblName.length());
     wxASSERT(pDb);
 
     if (!pDb)
     wxASSERT(pDb);
 
     if (!pDb)
@@ -175,12 +150,12 @@ bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD num
         (pDb->Dbms() == dbmsINTERBASE))
         tableName = tableName.Upper();
 
         (pDb->Dbms() == dbmsINTERBASE))
         tableName = tableName.Upper();
 
-    if (tblPath.Length())
+    if (tblPath.length())
         tablePath = tblPath;                    // Table Path - used for dBase files
     else
         tablePath.Empty();
 
         tablePath = tblPath;                    // Table Path - used for dBase files
     else
         tablePath.Empty();
 
-    if (qryTblName.Length())                    // Name of the table/view to query
+    if (qryTblName.length())                    // Name of the table/view to query
         queryTableName = qryTblName;
     else
         queryTableName = tblName;
         queryTableName = qryTblName;
     else
         queryTableName = tblName;
@@ -194,7 +169,8 @@ bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD num
 
     wxString s;
     tableID = ++lastTableID;
 
     wxString s;
     tableID = ++lastTableID;
-    s.Printf(wxT("wxDbTable constructor (%-20s) tableID:[%6lu] pDb:[%p]"), tblName.c_str(), tableID, pDb);
+    s.Printf(wxT("wxDbTable constructor (%-20s) tableID:[%6lu] pDb:[%p]"),
+             tblName.c_str(), tableID, wx_static_cast(void*, pDb));
 
 #ifdef __WXDEBUG__
     wxTablesInUse *tableInUse;
 
 #ifdef __WXDEBUG__
     wxTablesInUse *tableInUse;
@@ -202,7 +178,10 @@ bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD num
     tableInUse->tableName = tblName;
     tableInUse->tableID   = tableID;
     tableInUse->pDb       = pDb;
     tableInUse->tableName = tblName;
     tableInUse->tableID   = tableID;
     tableInUse->pDb       = pDb;
-    TablesInUse.Append(tableInUse);
+    {
+        wxCriticalSectionLocker lock(csTablesInUse);
+        TablesInUse.Append(tableInUse);
+    }
 #endif
 
     pDb->WriteSqlLog(s);
 #endif
 
     pDb->WriteSqlLog(s);
@@ -317,7 +296,8 @@ void wxDbTable::cleanup()
     wxString s;
     if (pDb)
     {
     wxString s;
     if (pDb)
     {
-        s.Printf(wxT("wxDbTable destructor (%-20s) tableID:[%6lu] pDb:[%p]"), tableName.c_str(), tableID, pDb);
+        s.Printf(wxT("wxDbTable destructor (%-20s) tableID:[%6lu] pDb:[%p]"),
+                 tableName.c_str(), tableID, wx_static_cast(void*, pDb));
         pDb->WriteSqlLog(s);
     }
 
         pDb->WriteSqlLog(s);
     }
 
@@ -327,17 +307,20 @@ void wxDbTable::cleanup()
         bool found = false;
 
         wxList::compatibility_iterator pNode;
         bool found = false;
 
         wxList::compatibility_iterator pNode;
-        pNode = TablesInUse.GetFirst();
-        while (pNode && !found)
         {
         {
-            if (((wxTablesInUse *)pNode->GetData())->tableID == tableID)
+            wxCriticalSectionLocker lock(csTablesInUse);
+            pNode = TablesInUse.GetFirst();
+            while (!found && pNode)
             {
             {
-                found = true;
-                delete (wxTablesInUse *)pNode->GetData();
-                TablesInUse.Erase(pNode);
+                if (((wxTablesInUse *)pNode->GetData())->tableID == tableID)
+                {
+                    found = true;
+                    delete (wxTablesInUse *)pNode->GetData();
+                    TablesInUse.Erase(pNode);
+                }
+                else
+                    pNode = pNode->GetNext();
             }
             }
-            else
-                pNode = pNode->GetNext();
         }
         if (!found)
         {
         }
         if (!found)
         {
@@ -417,6 +400,7 @@ void wxDbTable::setCbValueForColumn(int columnIndex)
     switch(colDefs[columnIndex].DbDataType)
     {
         case DB_DATA_TYPE_VARCHAR:
     switch(colDefs[columnIndex].DbDataType)
     {
         case DB_DATA_TYPE_VARCHAR:
+        case DB_DATA_TYPE_MEMO:
             if (colDefs[columnIndex].Null)
                 colDefs[columnIndex].CbValue = SQL_NULL_DATA;
             else
             if (colDefs[columnIndex].Null)
                 colDefs[columnIndex].CbValue = SQL_NULL_DATA;
             else
@@ -488,6 +472,11 @@ bool wxDbTable::bindParams(bool forUpdate)
                 precision = colDefs[i].SzDataObj;
                 scale = 0;
                 break;
                 precision = colDefs[i].SzDataObj;
                 scale = 0;
                 break;
+            case DB_DATA_TYPE_MEMO:
+                fSqlType = pDb->GetTypeInfMemo().FsqlType;
+                precision = colDefs[i].SzDataObj;
+                scale = 0;
+                break;
             case DB_DATA_TYPE_INTEGER:
                 fSqlType = pDb->GetTypeInfInteger().FsqlType;
                 precision = pDb->GetTypeInfInteger().Precision;
             case DB_DATA_TYPE_INTEGER:
                 fSqlType = pDb->GetTypeInfInteger().FsqlType;
                 precision = pDb->GetTypeInfInteger().Precision;
@@ -560,21 +549,17 @@ bool wxDbTable::bindUpdateParams(void)
 /********** wxDbTable::bindCols() **********/
 bool wxDbTable::bindCols(HSTMT cursor)
 {
 /********** wxDbTable::bindCols() **********/
 bool wxDbTable::bindCols(HSTMT cursor)
 {
-    static SDWORD cb;
-
     // Bind each column of the table to a memory address for fetching data
     UWORD i;
     for (i = 0; i < m_numCols; i++)
     {
     // Bind each column of the table to a memory address for fetching data
     UWORD i;
     for (i = 0; i < m_numCols; i++)
     {
-        cb = colDefs[i].CbValue;
         if (SQLBindCol(cursor, (UWORD)(i+1), colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
         if (SQLBindCol(cursor, (UWORD)(i+1), colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
-                       colDefs[i].SzDataObj, &cb ) != SQL_SUCCESS)
+                       colDefs[i].SzDataObj, &colDefs[i].CbValueCol ) != SQL_SUCCESS)
           return (pDb->DispAllErrors(henv, hdbc, cursor));
     }
 
     // Completed successfully
     return true;
           return (pDb->DispAllErrors(henv, hdbc, cursor));
     }
 
     // Completed successfully
     return true;
-
 }  // wxDbTable::bindCols()
 
 
 }  // wxDbTable::bindCols()
 
 
@@ -586,7 +571,7 @@ bool wxDbTable::getRec(UWORD fetchType)
     if (!pDb->FwdOnlyCursors())
     {
         // Fetch the NEXT, PREV, FIRST or LAST record, depending on fetchType
     if (!pDb->FwdOnlyCursors())
     {
         // Fetch the NEXT, PREV, FIRST or LAST record, depending on fetchType
-        UDWORD  cRowsFetched;
+        SQLULEN cRowsFetched;
         UWORD   rowStatus;
 
         retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus);
         UWORD   rowStatus;
 
         retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus);
@@ -603,7 +588,7 @@ bool wxDbTable::getRec(UWORD fetchType)
             // of each column just read in.
             int i;
             for (i = 0; i < m_numCols; i++)
             // of each column just read in.
             int i;
             for (i = 0; i < m_numCols; i++)
-                colDefs[i].Null = (colDefs[i].CbValue == SQL_NULL_DATA);
+                colDefs[i].Null = (colDefs[i].CbValueCol == SQL_NULL_DATA);
         }
     }
     else
         }
     }
     else
@@ -623,7 +608,7 @@ bool wxDbTable::getRec(UWORD fetchType)
             // of each column just read in.
             int i;
             for (i = 0; i < m_numCols; i++)
             // of each column just read in.
             int i;
             for (i = 0; i < m_numCols; i++)
-                colDefs[i].Null = (colDefs[i].CbValue == SQL_NULL_DATA);
+                colDefs[i].Null = (colDefs[i].CbValueCol == SQL_NULL_DATA);
         }
     }
 
         }
     }
 
@@ -639,7 +624,7 @@ bool wxDbTable::execDelete(const wxString &pSqlStmt)
     RETCODE retcode;
 
     // Execute the DELETE statement
     RETCODE retcode;
 
     // Execute the DELETE statement
-    retcode = SQLExecDirect(hstmtDelete, (SQLTCHAR FAR *) pSqlStmt.c_str(), SQL_NTS);
+    retcode = SQLExecDirect(hstmtDelete, WXSQLCAST(pSqlStmt), SQL_NTS);
 
     if (retcode == SQL_SUCCESS ||
         retcode == SQL_NO_DATA_FOUND ||
 
     if (retcode == SQL_SUCCESS ||
         retcode == SQL_NO_DATA_FOUND ||
@@ -661,7 +646,7 @@ bool wxDbTable::execUpdate(const wxString &pSqlStmt)
     RETCODE retcode;
 
     // Execute the UPDATE statement
     RETCODE retcode;
 
     // Execute the UPDATE statement
-    retcode = SQLExecDirect(hstmtUpdate, (SQLTCHAR FAR *) pSqlStmt.c_str(), SQL_NTS);
+    retcode = SQLExecDirect(hstmtUpdate, WXSQLCAST(pSqlStmt), SQL_NTS);
 
     if (retcode == SQL_SUCCESS ||
         retcode == SQL_NO_DATA_FOUND ||
 
     if (retcode == SQL_SUCCESS ||
         retcode == SQL_NO_DATA_FOUND ||
@@ -733,7 +718,7 @@ bool wxDbTable::query(int queryType, bool forUpdate, bool distinct, const wxStri
 
     // Execute the SQL SELECT statement
     int retcode;
 
     // Execute the SQL SELECT statement
     int retcode;
-    retcode = SQLExecDirect(hstmt, (SQLTCHAR FAR *) (queryType == DB_SELECT_STATEMENT ? pSqlStmt.c_str() : sqlStmt.c_str()), SQL_NTS);
+    retcode = SQLExecDirect(hstmt, (queryType == DB_SELECT_STATEMENT ? WXSQLCAST(pSqlStmt) : WXSQLCAST(sqlStmt)), SQL_NTS);
     if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
         return(pDb->DispAllErrors(henv, hdbc, hstmt));
 
     if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
         return(pDb->DispAllErrors(henv, hdbc, hstmt));
 
@@ -755,7 +740,6 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
     int i;
     wxString sqlStmt;
     wxString s;
     int i;
     wxString sqlStmt;
     wxString s;
-//    int NumKeyCols=0;
 
     // Calculate the maximum size of the concatenated
     // keys for use with wxDbGrid
 
     // Calculate the maximum size of the concatenated
     // keys for use with wxDbGrid
@@ -764,7 +748,6 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
     {
         if (colDefs[i].KeyField)
         {
     {
         if (colDefs[i].KeyField)
         {
-//            NumKeyCols++;
             m_keysize += colDefs[i].SzDataObj;
         }
     }
             m_keysize += colDefs[i].SzDataObj;
         }
     }
@@ -792,7 +775,8 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
     else if (checkPrivileges)
     {
         // Verify the user has rights to access the table.
     else if (checkPrivileges)
     {
         // Verify the user has rights to access the table.
-        bool hasPrivs = true;
+        bool hasPrivs wxDUMMY_INITIALIZE(true);
+
         if (pDb->Dbms() == dbmsPOSTGRES)
             hasPrivs = pDb->TablePrivileges(tableName, wxT("SELECT"), pDb->GetUsername(), NULL, tablePath);
         else
         if (pDb->Dbms() == dbmsPOSTGRES)
             hasPrivs = pDb->TablePrivileges(tableName, wxT("SELECT"), pDb->GetUsername(), NULL, tablePath);
         else
@@ -802,11 +786,11 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
             s = wxT("Connecting user does not have sufficient privileges to access this table.\n");
     }
 
             s = wxT("Connecting user does not have sufficient privileges to access this table.\n");
     }
 
-    if (!s.IsEmpty())
+    if (!s.empty())
     {
         wxString p;
 
     {
         wxString p;
 
-        if (!tablePath.IsEmpty())
+        if (!tablePath.empty())
             p.Printf(wxT("Error opening '%s/%s'.\n"),tablePath.c_str(),tableName.c_str());
         else
             p.Printf(wxT("Error opening '%s'.\n"), tableName.c_str());
             p.Printf(wxT("Error opening '%s/%s'.\n"),tablePath.c_str(),tableName.c_str());
         else
             p.Printf(wxT("Error opening '%s'.\n"), tableName.c_str());
@@ -851,7 +835,6 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
             if (needComma)
                 sqlStmt += wxT(",");
             sqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
             if (needComma)
                 sqlStmt += wxT(",");
             sqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
-//            sqlStmt += colDefs[i].ColName;
             needComma = true;
         }
         needComma = false;
             needComma = true;
         }
         needComma = false;
@@ -874,7 +857,7 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
         // Prepare the insert statement for execution
         if (insertableCount)
         {
         // Prepare the insert statement for execution
         if (insertableCount)
         {
-            if (SQLPrepare(hstmtInsert, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
+            if (SQLPrepare(hstmtInsert, WXSQLCAST(sqlStmt), SQL_NTS) != SQL_SUCCESS)
                 return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
         }
         else
                 return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
         }
         else
@@ -993,7 +976,7 @@ void wxDbTable::BuildDeleteStmt(wxString &pSqlStmt, int typeOfDel, const wxStrin
 
     // Handle the case of DeleteWhere() and the where clause is blank.  It should
     // delete all records from the database in this case.
 
     // Handle the case of DeleteWhere() and the where clause is blank.  It should
     // delete all records from the database in this case.
-    if (typeOfDel == DB_DEL_WHERE && (pWhereClause.Length() == 0))
+    if (typeOfDel == DB_DEL_WHERE && (pWhereClause.length() == 0))
     {
         pSqlStmt.Printf(wxT("DELETE FROM %s"),
                         pDb->SQLTableName(tableName.c_str()).c_str());
     {
         pSqlStmt.Printf(wxT("DELETE FROM %s"),
                         pDb->SQLTableName(tableName.c_str()).c_str());
@@ -1012,7 +995,7 @@ void wxDbTable::BuildDeleteStmt(wxString &pSqlStmt, int typeOfDel, const wxStrin
             // e.g. DELETE FROM PARTS WHERE ROWID = '111.222.333'
             if (CanUpdateByROWID())
             {
             // e.g. DELETE FROM PARTS WHERE ROWID = '111.222.333'
             if (CanUpdateByROWID())
             {
-                SDWORD cb;
+                SQLLEN cb;
                 wxChar   rowid[wxDB_ROWID_LEN+1];
 
                 // Get the ROWID value.  If not successful retreiving the ROWID,
                 wxChar   rowid[wxDB_ROWID_LEN+1];
 
                 // Get the ROWID value.  If not successful retreiving the ROWID,
@@ -1072,7 +1055,7 @@ void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool disti
     if (typeOfSelect == DB_SELECT_WHERE && from && wxStrlen(from))
         appendFromClause = true;
 #else
     if (typeOfSelect == DB_SELECT_WHERE && from && wxStrlen(from))
         appendFromClause = true;
 #else
-    if (typeOfSelect == DB_SELECT_WHERE && from.Length())
+    if (typeOfSelect == DB_SELECT_WHERE && from.length())
         appendFromClause = true;
 #endif
 
         appendFromClause = true;
 #endif
 
@@ -1102,7 +1085,6 @@ void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool disti
         {
             pSqlStmt += wxT(",");
             pSqlStmt += pDb->SQLTableName(queryTableName);
         {
             pSqlStmt += wxT(",");
             pSqlStmt += pDb->SQLTableName(queryTableName);
-//            pSqlStmt += queryTableName;
             pSqlStmt += wxT(".ROWID");
         }
         else
             pSqlStmt += wxT(".ROWID");
         }
         else
@@ -1133,7 +1115,7 @@ void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool disti
 #if wxODBC_BACKWARD_COMPATABILITY
             if (where && wxStrlen(where))   // May not want a where clause!!!
 #else
 #if wxODBC_BACKWARD_COMPATABILITY
             if (where && wxStrlen(where))   // May not want a where clause!!!
 #else
-            if (where.Length())   // May not want a where clause!!!
+            if (where.length())   // May not want a where clause!!!
 #endif
             {
                 pSqlStmt += wxT(" WHERE ");
 #endif
             {
                 pSqlStmt += wxT(" WHERE ");
@@ -1142,7 +1124,7 @@ void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool disti
             break;
         case DB_SELECT_KEYFIELDS:
             BuildWhereClause(whereClause, DB_WHERE_KEYFIELDS);
             break;
         case DB_SELECT_KEYFIELDS:
             BuildWhereClause(whereClause, DB_WHERE_KEYFIELDS);
-            if (whereClause.Length())
+            if (whereClause.length())
             {
                 pSqlStmt += wxT(" WHERE ");
                 pSqlStmt += whereClause;
             {
                 pSqlStmt += wxT(" WHERE ");
                 pSqlStmt += whereClause;
@@ -1150,7 +1132,7 @@ void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool disti
             break;
         case DB_SELECT_MATCHING:
             BuildWhereClause(whereClause, DB_WHERE_MATCHING);
             break;
         case DB_SELECT_MATCHING:
             BuildWhereClause(whereClause, DB_WHERE_MATCHING);
-            if (whereClause.Length())
+            if (whereClause.length())
             {
                 pSqlStmt += wxT(" WHERE ");
                 pSqlStmt += whereClause;
             {
                 pSqlStmt += wxT(" WHERE ");
                 pSqlStmt += whereClause;
@@ -1162,7 +1144,7 @@ void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool disti
 #if wxODBC_BACKWARD_COMPATABILITY
     if (orderBy && wxStrlen(orderBy))
 #else
 #if wxODBC_BACKWARD_COMPATABILITY
     if (orderBy && wxStrlen(orderBy))
 #else
-    if (orderBy.Length())
+    if (orderBy.length())
 #endif
     {
         pSqlStmt += wxT(" ORDER BY ");
 #endif
     {
         pSqlStmt += wxT(" ORDER BY ");
@@ -1230,7 +1212,7 @@ void wxDbTable::BuildUpdateStmt(wxString &pSqlStmt, int typeOfUpdate, const wxSt
             // e.g. UPDATE PARTS SET Col1 = ?, Col2 = ? WHERE ROWID = '111.222.333'
             if (CanUpdateByROWID())
             {
             // e.g. UPDATE PARTS SET Col1 = ?, Col2 = ? WHERE ROWID = '111.222.333'
             if (CanUpdateByROWID())
             {
-                SDWORD cb;
+                SQLLEN cb;
                 wxChar rowid[wxDB_ROWID_LEN+1];
 
                 // Get the ROWID value.  If not successful retreiving the ROWID,
                 wxChar rowid[wxDB_ROWID_LEN+1];
 
                 // Get the ROWID value.  If not successful retreiving the ROWID,
@@ -1296,7 +1278,7 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
             // Concatenate where phrase for the column
             wxString tStr = colDefs[colNumber].ColName;
 
             // Concatenate where phrase for the column
             wxString tStr = colDefs[colNumber].ColName;
 
-            if (qualTableName.Length() && tStr.Find(wxT('.')) == wxNOT_FOUND)
+            if (qualTableName.length() && tStr.Find(wxT('.')) == wxNOT_FOUND)
             {
                 pWhereClause += pDb->SQLTableName(qualTableName);
                 pWhereClause += wxT(".");
             {
                 pWhereClause += pDb->SQLTableName(qualTableName);
                 pWhereClause += wxT(".");
@@ -1311,11 +1293,11 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
             switch(colDefs[colNumber].SqlCtype)
             {
                 case SQL_C_CHAR:
             switch(colDefs[colNumber].SqlCtype)
             {
                 case SQL_C_CHAR:
-#ifndef __UNIX__
+#ifdef SQL_C_WCHAR
                 case SQL_C_WCHAR:
                 case SQL_C_WCHAR:
-#endif                 
+#endif
                 //case SQL_C_WXCHAR:  SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
                 //case SQL_C_WXCHAR:  SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
-                    colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[colNumber].PtrDataObj);
+                    colValue.Printf(wxT("'%s'"), GetDb()->EscapeSqlChars((wxChar *)colDefs[colNumber].PtrDataObj).c_str());
                     break;
                 case SQL_C_SHORT:
                 case SQL_C_SSHORT:
                     break;
                 case SQL_C_SHORT:
                 case SQL_C_SSHORT:
@@ -1421,6 +1403,9 @@ bool wxDbTable::CreateTable(bool attemptDrop)
             case DB_DATA_TYPE_VARCHAR:
                 cout << pDb->GetTypeInfVarchar().TypeName << wxT("(") << (int)(colDefs[i].SzDataObj / sizeof(wxChar)) << wxT(")");
                 break;
             case DB_DATA_TYPE_VARCHAR:
                 cout << pDb->GetTypeInfVarchar().TypeName << wxT("(") << (int)(colDefs[i].SzDataObj / sizeof(wxChar)) << wxT(")");
                 break;
+            case DB_DATA_TYPE_MEMO:
+                cout << pDb->GetTypeInfMemo().TypeName;
+                break;
             case DB_DATA_TYPE_INTEGER:
                 cout << pDb->GetTypeInfInteger().TypeName;
                 break;
             case DB_DATA_TYPE_INTEGER:
                 cout << pDb->GetTypeInfInteger().TypeName;
                 break;
@@ -1462,6 +1447,9 @@ bool wxDbTable::CreateTable(bool attemptDrop)
             case DB_DATA_TYPE_VARCHAR:
                 sqlStmt += pDb->GetTypeInfVarchar().TypeName;
                 break;
             case DB_DATA_TYPE_VARCHAR:
                 sqlStmt += pDb->GetTypeInfVarchar().TypeName;
                 break;
+            case DB_DATA_TYPE_MEMO:
+                sqlStmt += pDb->GetTypeInfMemo().TypeName;
+                break;
             case DB_DATA_TYPE_INTEGER:
                 sqlStmt += pDb->GetTypeInfInteger().TypeName;
                 break;
             case DB_DATA_TYPE_INTEGER:
                 sqlStmt += pDb->GetTypeInfInteger().TypeName;
                 break;
@@ -1531,7 +1519,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
                 //  DB2 is limited to 18 characters for index names
                 if (pDb->Dbms() == dbmsDB2)
                 {
                 //  DB2 is limited to 18 characters for index names
                 if (pDb->Dbms() == dbmsDB2)
                 {
-                    wxASSERT_MSG((tableName && wxStrlen(tableName) <= 13), wxT("DB2 table/index names must be no longer than 13 characters in length.\n\nTruncating table name to 13 characters."));
+                    wxASSERT_MSG(!tableName.empty() && tableName.length() <= 13, wxT("DB2 table/index names must be no longer than 13 characters in length.\n\nTruncating table name to 13 characters."));
                     sqlStmt += pDb->SQLTableName(tableName.substr(0, 13).c_str());
 //                    sqlStmt += tableName.substr(0, 13);
                 }
                     sqlStmt += pDb->SQLTableName(tableName.substr(0, 13).c_str());
 //                    sqlStmt += tableName.substr(0, 13);
                 }
@@ -1584,7 +1572,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
 #endif
 
     // Execute the CREATE TABLE statement
 #endif
 
     // Execute the CREATE TABLE statement
-    RETCODE retcode = SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS);
+    RETCODE retcode = SQLExecDirect(hstmt, WXSQLCAST(sqlStmt), SQL_NTS);
     if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
     {
         pDb->DispAllErrors(henv, hdbc, hstmt);
     if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
     {
         pDb->DispAllErrors(henv, hdbc, hstmt);
@@ -1624,7 +1612,7 @@ bool wxDbTable::DropTable()
     cout << endl << sqlStmt.c_str() << endl;
 #endif
 
     cout << endl << sqlStmt.c_str() << endl;
 #endif
 
-    RETCODE retcode = SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS);
+    RETCODE retcode = SQLExecDirect(hstmt, WXSQLCAST(sqlStmt), SQL_NTS);
     if (retcode != SQL_SUCCESS)
     {
         // Check for "Base table not found" error and ignore
     if (retcode != SQL_SUCCESS)
     {
         // Check for "Base table not found" error and ignore
@@ -1793,7 +1781,7 @@ bool wxDbTable::CreateIndex(const wxString &indexName, bool unique, UWORD numInd
 #endif
 
     // Execute the CREATE INDEX statement
 #endif
 
     // Execute the CREATE INDEX statement
-    RETCODE retcode = SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS);
+    RETCODE retcode = SQLExecDirect(hstmt, WXSQLCAST(sqlStmt), SQL_NTS);
     if (retcode != SQL_SUCCESS)
     {
         pDb->DispAllErrors(henv, hdbc, hstmt);
     if (retcode != SQL_SUCCESS)
     {
         pDb->DispAllErrors(henv, hdbc, hstmt);
@@ -1844,7 +1832,7 @@ bool wxDbTable::DropIndex(const wxString &indexName)
 #ifdef DBDEBUG_CONSOLE
     cout << endl << sqlStmt.c_str() << endl;
 #endif
 #ifdef DBDEBUG_CONSOLE
     cout << endl << sqlStmt.c_str() << endl;
 #endif
-    RETCODE retcode = SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS);
+    RETCODE retcode = SQLExecDirect(hstmt, WXSQLCAST(sqlStmt), SQL_NTS);
     if (retcode != SQL_SUCCESS)
     {
         // Check for "Index not found" error and ignore
     if (retcode != SQL_SUCCESS)
     {
         // Check for "Index not found" error and ignore
@@ -1856,6 +1844,7 @@ bool wxDbTable::DropIndex(const wxString &indexName)
                   (pDb->Dbms() == dbmsSYBASE_ASE    && !wxStrcmp(pDb->sqlState,wxT("37000"))) ||
                   (pDb->Dbms() == dbmsMS_SQL_SERVER && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
                   (pDb->Dbms() == dbmsINTERBASE     && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
                   (pDb->Dbms() == dbmsSYBASE_ASE    && !wxStrcmp(pDb->sqlState,wxT("37000"))) ||
                   (pDb->Dbms() == dbmsMS_SQL_SERVER && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
                   (pDb->Dbms() == dbmsINTERBASE     && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
+                  (pDb->Dbms() == dbmsMAXDB         && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
                   (pDb->Dbms() == dbmsFIREBIRD      && !wxStrcmp(pDb->sqlState,wxT("HY000"))) ||
                   (pDb->Dbms() == dbmsSYBASE_ASE    && !wxStrcmp(pDb->sqlState,wxT("S0002"))) ||  // Base table not found
                   (pDb->Dbms() == dbmsMY_SQL        && !wxStrcmp(pDb->sqlState,wxT("42S12"))) ||  // tested by Christopher Ludwik Marino-Cebulski using v3.23.21beta
                   (pDb->Dbms() == dbmsFIREBIRD      && !wxStrcmp(pDb->sqlState,wxT("HY000"))) ||
                   (pDb->Dbms() == dbmsSYBASE_ASE    && !wxStrcmp(pDb->sqlState,wxT("S0002"))) ||  // Base table not found
                   (pDb->Dbms() == dbmsMY_SQL        && !wxStrcmp(pDb->sqlState,wxT("42S12"))) ||  // tested by Christopher Ludwik Marino-Cebulski using v3.23.21beta
@@ -2204,7 +2193,7 @@ void wxDbTable::ClearMemberVar(UWORD colNumber, bool setToNull)
     switch(colDefs[colNumber].SqlCtype)
     {
         case SQL_C_CHAR:
     switch(colDefs[colNumber].SqlCtype)
     {
         case SQL_C_CHAR:
-#ifndef __UNIX__
+#ifdef SQL_C_WCHAR
         case SQL_C_WCHAR:
 #endif
         //case SQL_C_WXCHAR:  SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
         case SQL_C_WCHAR:
 #endif
         //case SQL_C_WXCHAR:  SQL_C_WXCHAR is covered by either SQL_C_CHAR or SQL_C_WCHAR
@@ -2240,6 +2229,20 @@ void wxDbTable::ClearMemberVar(UWORD colNumber, bool setToNull)
             pDt->second = 0;
             pDt->fraction = 0;
             break;
             pDt->second = 0;
             pDt->fraction = 0;
             break;
+        case SQL_C_DATE:
+            DATE_STRUCT *pDtd;
+            pDtd = (DATE_STRUCT *) colDefs[colNumber].PtrDataObj;
+            pDtd->year = 0;
+            pDtd->month = 0;
+            pDtd->day = 0;
+            break;
+        case SQL_C_TIME:
+            TIME_STRUCT *pDtt;
+            pDtt = (TIME_STRUCT *) colDefs[colNumber].PtrDataObj;
+            pDtt->hour = 0;
+            pDtt->minute = 0;
+            pDtt->second = 0;
+            break;
     }
 
     if (setToNull)
     }
 
     if (setToNull)
@@ -2295,7 +2298,7 @@ bool wxDbTable::SetColDefs(UWORD index, const wxString &fieldName, int dataType,
     if (!colDefs)  // May happen if the database connection fails
         return false;
 
     if (!colDefs)  // May happen if the database connection fails
         return false;
 
-    if (fieldName.Length() > (unsigned int) DB_MAX_COLUMN_NAME_LEN)
+    if (fieldName.length() > (unsigned int) DB_MAX_COLUMN_NAME_LEN)
     {
         wxStrncpy(colDefs[index].ColName, fieldName, DB_MAX_COLUMN_NAME_LEN);
         colDefs[index].ColName[DB_MAX_COLUMN_NAME_LEN] = 0;  // Prevent buffer overrun
     {
         wxStrncpy(colDefs[index].ColName, fieldName, DB_MAX_COLUMN_NAME_LEN);
         colDefs[index].ColName[DB_MAX_COLUMN_NAME_LEN] = 0;  // Prevent buffer overrun
@@ -2355,6 +2358,11 @@ wxDbColDataPtr* wxDbTable::SetColDefs(wxDbColInf *pColInfs, UWORD numCols)
                    pColDataPtrs[index].SzDataObj  = pColInfs[index].bufferSize+(1*sizeof(wxChar));
                    pColDataPtrs[index].SqlCtype   = SQL_C_WXCHAR;
                    break;
                    pColDataPtrs[index].SzDataObj  = pColInfs[index].bufferSize+(1*sizeof(wxChar));
                    pColDataPtrs[index].SqlCtype   = SQL_C_WXCHAR;
                    break;
+                case DB_DATA_TYPE_MEMO:
+                   pColDataPtrs[index].PtrDataObj = new wxChar[pColInfs[index].bufferSize+(1*sizeof(wxChar))];
+                   pColDataPtrs[index].SzDataObj  = pColInfs[index].bufferSize+(1*sizeof(wxChar));
+                   pColDataPtrs[index].SqlCtype   = SQL_C_WXCHAR;
+                   break;
                 case DB_DATA_TYPE_INTEGER:
                     // Can be long or short
                     if (pColInfs[index].bufferSize == sizeof(long))
                 case DB_DATA_TYPE_INTEGER:
                     // Can be long or short
                     if (pColInfs[index].bufferSize == sizeof(long))
@@ -2433,7 +2441,7 @@ ULONG wxDbTable::Count(const wxString &args)
 {
     ULONG count;
     wxString sqlStmt;
 {
     ULONG count;
     wxString sqlStmt;
-    SDWORD cb;
+    SQLLEN cb;
 
     // Build a "SELECT COUNT(*) FROM queryTableName [WHERE whereClause]" SQL Statement
     sqlStmt  = wxT("SELECT COUNT(");
 
     // Build a "SELECT COUNT(*) FROM queryTableName [WHERE whereClause]" SQL Statement
     sqlStmt  = wxT("SELECT COUNT(");
@@ -2444,7 +2452,7 @@ ULONG wxDbTable::Count(const wxString &args)
 #if wxODBC_BACKWARD_COMPATABILITY
     if (from && wxStrlen(from))
 #else
 #if wxODBC_BACKWARD_COMPATABILITY
     if (from && wxStrlen(from))
 #else
-    if (from.Length())
+    if (from.length())
 #endif
         sqlStmt += from;
 
 #endif
         sqlStmt += from;
 
@@ -2452,7 +2460,7 @@ ULONG wxDbTable::Count(const wxString &args)
 #if wxODBC_BACKWARD_COMPATABILITY
     if (where && wxStrlen(where))
 #else
 #if wxODBC_BACKWARD_COMPATABILITY
     if (where && wxStrlen(where))
 #else
-    if (where.Length())
+    if (where.length())
 #endif
     {
         sqlStmt += wxT(" WHERE ");
 #endif
     {
         sqlStmt += wxT(" WHERE ");
@@ -2471,7 +2479,7 @@ ULONG wxDbTable::Count(const wxString &args)
     }
 
     // Execute the SQL statement
     }
 
     // Execute the SQL statement
-    if (SQLExecDirect(*hstmtCount, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
+    if (SQLExecDirect(*hstmtCount, WXSQLCAST(sqlStmt), SQL_NTS) != SQL_SUCCESS)
     {
         pDb->DispAllErrors(henv, hdbc, *hstmtCount);
         return(0);
     {
         pDb->DispAllErrors(henv, hdbc, *hstmtCount);
         return(0);
@@ -2524,7 +2532,7 @@ bool wxDbTable::Refresh(void)
 
     if (CanUpdateByROWID())
     {
 
     if (CanUpdateByROWID())
     {
-        SDWORD cb;
+        SQLLEN cb;
         wxChar rowid[wxDB_ROWID_LEN+1];
 
         // Get the ROWID value.  If not successful retreiving the ROWID,
         wxChar rowid[wxDB_ROWID_LEN+1];
 
         // Get the ROWID value.  If not successful retreiving the ROWID,
@@ -2713,8 +2721,14 @@ wxVariant wxDbTable::GetColumn(const int colNumber) const
     {
         switch (colDefs[colNumber].SqlCtype)
         {
     {
         switch (colDefs[colNumber].SqlCtype)
         {
+#if wxUSE_UNICODE
+    #if defined(SQL_WCHAR)
             case SQL_WCHAR:
             case SQL_WCHAR:
+    #endif
+    #if defined(SQL_WVARCHAR)
             case SQL_WVARCHAR:
             case SQL_WVARCHAR:
+    #endif
+#endif
             case SQL_CHAR:
             case SQL_VARCHAR:
                 val = (wxChar *)(colDefs[colNumber].PtrDataObj);
             case SQL_CHAR:
             case SQL_VARCHAR:
                 val = (wxChar *)(colDefs[colNumber].PtrDataObj);
@@ -2779,8 +2793,14 @@ void wxDbTable::SetColumn(const int colNumber, const wxVariant val)
 
         switch (colDefs[colNumber].SqlCtype)
         {
 
         switch (colDefs[colNumber].SqlCtype)
         {
+#if wxUSE_UNICODE
+    #if defined(SQL_WCHAR)
             case SQL_WCHAR:
             case SQL_WCHAR:
+    #endif
+    #if defined(SQL_WVARCHAR)
             case SQL_WVARCHAR:
             case SQL_WVARCHAR:
+    #endif
+#endif
             case SQL_CHAR:
             case SQL_VARCHAR:
                 csstrncpyt((wxChar *)(colDefs[colNumber].PtrDataObj),
             case SQL_CHAR:
             case SQL_VARCHAR:
                 csstrncpyt((wxChar *)(colDefs[colNumber].PtrDataObj),
@@ -2898,4 +2918,3 @@ void wxDbTable::SetKey(const GenericKey& k)
 
 
 #endif  // wxUSE_ODBC
 
 
 #endif  // wxUSE_ODBC
-