From cf5d275eb81f2bc66eff52e99b5e56100766a75c Mon Sep 17 00:00:00 2001 From: George Tasker Date: Sun, 21 May 2000 10:49:22 +0000 Subject: [PATCH] Fixed problem where if a table had no insertable columns, construction of the insertion statemtent would fail, which then would cause unstable behavior at a later time. Now if Insert() is called and there are no insertable columns, insert will return a failure. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7446 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dbtable.h | 1 + src/common/dbtable.cpp | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/wx/dbtable.h b/include/wx/dbtable.h index f239c0b11f..6f7e6866d5 100644 --- a/include/wx/dbtable.h +++ b/include/wx/dbtable.h @@ -98,6 +98,7 @@ private: // Private member variables UDWORD cursorType; + bool insertable; // Private member functions bool bindInsertParams(void); diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index e1c631deee..9ef7d550b3 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -623,7 +623,6 @@ bool wxDbTable::Open(void) return FALSE; int i; wxString sqlStmt; - // Verify that the table exists in the database if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath)) @@ -659,7 +658,6 @@ bool wxDbTable::Open(void) if (!bindCols(hstmtInternal)) // Internal use only return(FALSE); - /* * Do NOT bind the hstmtCount cursor!!! */ @@ -680,6 +678,9 @@ bool wxDbTable::Open(void) } needComma = FALSE; sqlStmt += ") VALUES ("; + + int insertableCount = 0; + for (i = 0; i < noCols; i++) { if (! colDefs[i].InsertAllowed) @@ -688,14 +689,20 @@ bool wxDbTable::Open(void) sqlStmt += ","; sqlStmt += "?"; needComma = TRUE; + insertableCount++; } sqlStmt += ")"; // pDb->WriteSqlLog(sqlStmt); // Prepare the insert statement for execution - if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS) - return(pDb->DispAllErrors(henv, hdbc, hstmtInsert)); + if (insertableCount) + { + if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS) + return(pDb->DispAllErrors(henv, hdbc, hstmtInsert)); + } + else + insertable= false; } // Completed successfully @@ -1282,7 +1289,7 @@ bool wxDbTable::DropIndex(const char * idxName) int wxDbTable::Insert(void) { assert(!queryOnly); - if (queryOnly) + if (queryOnly || !insertable) return(DB_FAILURE); bindInsertParams();