]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dbtable.cpp
include wx/utils.h in PCH-less build to ensure that we get the correct (DLL-exported...
[wxWidgets.git] / src / common / dbtable.cpp
index 54637134197428520161af9e2d0c4887bd01b059..fff7942cae7de1ab242c92abedf73ae823359e52 100644 (file)
 #endif
 
 #ifdef DBDEBUG_CONSOLE
-#if wxUSE_IOSTREAMH
-    #include <iostream.h>
-#else
-    #include <iostream>
-#endif
     #include "wx/ioswrap.h"
 #endif
 
 
 #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
-#endif
-
 ULONG lastTableID = 0;
 
 
 #ifdef __WXDEBUG__
+    #include "wx/thread.h"
+
     wxList TablesInUse;
+    wxCriticalSection csTablesInUse;
 #endif
 
 
@@ -107,19 +94,6 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumn
 }  // 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()
 {
@@ -195,7 +169,10 @@ bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD num
     tableInUse->tableName = tblName;
     tableInUse->tableID   = tableID;
     tableInUse->pDb       = pDb;
-    TablesInUse.Append(tableInUse);
+    {
+        wxCriticalSectionLocker lock(csTablesInUse);
+        TablesInUse.Append(tableInUse);
+    }
 #endif
 
     pDb->WriteSqlLog(s);
@@ -321,17 +298,20 @@ void wxDbTable::cleanup()
         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)
         {
@@ -560,21 +540,17 @@ bool wxDbTable::bindUpdateParams(void)
 /********** wxDbTable::bindCols() **********/
 bool wxDbTable::bindCols(HSTMT cursor)
 {
-    static SQLLEN cb;
-
     // 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,
-                       colDefs[i].SzDataObj, &cb ) != SQL_SUCCESS)
+                       colDefs[i].SzDataObj, &colDefs[i].CbValue ) != SQL_SUCCESS)
           return (pDb->DispAllErrors(henv, hdbc, cursor));
     }
 
     // Completed successfully
     return true;
-
 }  // wxDbTable::bindCols()
 
 
@@ -1312,7 +1288,7 @@ void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
                 case SQL_C_WCHAR:
 #endif
                 //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: