X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1d6f23483a9d5e800c4b7cd2e994f9b9f026a84b..20ea6894a2660c453c3255a66aa9f7e24cf97ec8:/src/common/dbtable.cpp?ds=inline diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index 8a67be2311..49e2c2348d 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -35,7 +35,11 @@ #endif #ifdef DBDEBUG_CONSOLE - #include "iostream.h" +#if wxUSE_IOSTREAMH + #include +#else + #include +#endif #include "wx/ioswrap.h" #endif @@ -524,15 +528,16 @@ bool wxDbTable::bindUpdateParams(void) /********** 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 < noCols; i++) { + cb = colDefs[i].CbValue; if (SQLBindCol(cursor, (UWORD)(i+1), colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj, - colDefs[i].SzDataObj, &colDefs[i].CbValue ) != SQL_SUCCESS) - { + colDefs[i].SzDataObj, &cb ) != SQL_SUCCESS) return (pDb->DispAllErrors(henv, hdbc, cursor)); - } } // Completed successfully @@ -1121,7 +1126,7 @@ void wxDbTable::BuildUpdateStmt(wxString &pSqlStmt, int typeOfUpd, const wxStrin bool firstColumn = TRUE; pSqlStmt.Printf(wxT("UPDATE %s SET "), - pDb->SQLTableName(tableName.Upper().c_str()).c_str()); + pDb->SQLTableName(tableName.c_str()).c_str()); // Append a list of columns to be updated int i; @@ -1380,7 +1385,8 @@ bool wxDbTable::CreateTable(bool attemptDrop) break; } // For varchars, append the size of the string - if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)// || + if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR && + (pDb->Dbms() != dbmsMY_SQL || pDb->GetTypeInfVarchar().TypeName != "text"))// || // colDefs[i].DbDataType == DB_DATA_TYPE_BLOB) { wxString s; @@ -1452,7 +1458,14 @@ bool wxDbTable::CreateTable(bool attemptDrop) if (j++) // Multi part key, comma separate names sqlStmt += wxT(","); sqlStmt += pDb->SQLColumnName(colDefs[i].ColName); -// sqlStmt += colDefs[i].ColName; + + if (pDb->Dbms() == dbmsMY_SQL && + colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR) + { + wxString s; + s.Printf(wxT("(%d)"), colDefs[i].SzDataObj); + sqlStmt += s; + } } } sqlStmt += wxT(")"); @@ -1696,7 +1709,7 @@ bool wxDbTable::DropIndex(const wxString &idxName) pDb->Dbms() == dbmsDBASE /*|| Paradox needs this syntax too when we add support*/) sqlStmt.Printf(wxT("DROP INDEX %s ON %s"), pDb->SQLTableName(idxName.c_str()).c_str(), - pDb->SQLTableName(tableName.c_str().c_str())); + pDb->SQLTableName(tableName.c_str()).c_str()); else if ((pDb->Dbms() == dbmsMS_SQL_SERVER) || (pDb->Dbms() == dbmsSYBASE_ASE)) sqlStmt.Printf(wxT("DROP INDEX %s.%s"), @@ -2106,6 +2119,9 @@ void wxDbTable::SetColDefs(UWORD index, const wxString &fieldName, int dataType, SWORD cType, int size, bool keyField, bool upd, bool insAllow, bool derivedCol) { + wxASSERT_MSG( index < noCols, + _T("Specified column index exceeds the maximum number of columns for this table.") ); + if (!colDefs) // May happen if the database connection fails return;