X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/06322acab7b6253ea3e8a0d5c82bc4c45f210157..209ce629ac70e21ba2239c36a9c2ad7571964ce2:/src/common/dbtable.cpp diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index 5463713419..e51af36535 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -28,11 +28,6 @@ #endif #ifdef DBDEBUG_CONSOLE -#if wxUSE_IOSTREAMH - #include -#else - #include -#endif #include "wx/ioswrap.h" #endif @@ -44,22 +39,21 @@ #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 -// # endif -# ifdef LINUX -# include -# 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__ + #include "wx/thread.h" + wxList TablesInUse; + wxCriticalSection csTablesInUse; #endif @@ -107,19 +101,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 +176,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 +305,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 +547,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() @@ -639,7 +622,7 @@ bool wxDbTable::execDelete(const wxString &pSqlStmt) 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 || @@ -661,7 +644,7 @@ bool wxDbTable::execUpdate(const wxString &pSqlStmt) 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 || @@ -733,7 +716,7 @@ bool wxDbTable::query(int queryType, bool forUpdate, bool distinct, const wxStri // 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)); @@ -872,7 +855,7 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists) // 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 @@ -1312,7 +1295,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: @@ -1534,7 +1517,7 @@ bool wxDbTable::CreateTable(bool attemptDrop) // 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); } @@ -1587,7 +1570,7 @@ bool wxDbTable::CreateTable(bool attemptDrop) #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); @@ -1627,7 +1610,7 @@ bool wxDbTable::DropTable() 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 @@ -1796,7 +1779,7 @@ bool wxDbTable::CreateIndex(const wxString &indexName, bool unique, UWORD numInd #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); @@ -1847,7 +1830,7 @@ bool wxDbTable::DropIndex(const wxString &indexName) #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 @@ -2494,7 +2477,7 @@ ULONG wxDbTable::Count(const wxString &args) } // 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);