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
This commit is contained in:
@@ -98,6 +98,7 @@ private:
|
|||||||
|
|
||||||
// Private member variables
|
// Private member variables
|
||||||
UDWORD cursorType;
|
UDWORD cursorType;
|
||||||
|
bool insertable;
|
||||||
|
|
||||||
// Private member functions
|
// Private member functions
|
||||||
bool bindInsertParams(void);
|
bool bindInsertParams(void);
|
||||||
|
@@ -623,7 +623,6 @@ bool wxDbTable::Open(void)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
int i;
|
int i;
|
||||||
wxString sqlStmt;
|
wxString sqlStmt;
|
||||||
|
|
||||||
|
|
||||||
// Verify that the table exists in the database
|
// Verify that the table exists in the database
|
||||||
if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath))
|
if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath))
|
||||||
@@ -659,7 +658,6 @@ bool wxDbTable::Open(void)
|
|||||||
if (!bindCols(hstmtInternal)) // Internal use only
|
if (!bindCols(hstmtInternal)) // Internal use only
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do NOT bind the hstmtCount cursor!!!
|
* Do NOT bind the hstmtCount cursor!!!
|
||||||
*/
|
*/
|
||||||
@@ -680,6 +678,9 @@ bool wxDbTable::Open(void)
|
|||||||
}
|
}
|
||||||
needComma = FALSE;
|
needComma = FALSE;
|
||||||
sqlStmt += ") VALUES (";
|
sqlStmt += ") VALUES (";
|
||||||
|
|
||||||
|
int insertableCount = 0;
|
||||||
|
|
||||||
for (i = 0; i < noCols; i++)
|
for (i = 0; i < noCols; i++)
|
||||||
{
|
{
|
||||||
if (! colDefs[i].InsertAllowed)
|
if (! colDefs[i].InsertAllowed)
|
||||||
@@ -688,14 +689,20 @@ bool wxDbTable::Open(void)
|
|||||||
sqlStmt += ",";
|
sqlStmt += ",";
|
||||||
sqlStmt += "?";
|
sqlStmt += "?";
|
||||||
needComma = TRUE;
|
needComma = TRUE;
|
||||||
|
insertableCount++;
|
||||||
}
|
}
|
||||||
sqlStmt += ")";
|
sqlStmt += ")";
|
||||||
|
|
||||||
// pDb->WriteSqlLog(sqlStmt);
|
// pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
// Prepare the insert statement for execution
|
// Prepare the insert statement for execution
|
||||||
if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
|
if (insertableCount)
|
||||||
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
|
{
|
||||||
|
if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
|
||||||
|
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
insertable= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Completed successfully
|
// Completed successfully
|
||||||
@@ -1282,7 +1289,7 @@ bool wxDbTable::DropIndex(const char * idxName)
|
|||||||
int wxDbTable::Insert(void)
|
int wxDbTable::Insert(void)
|
||||||
{
|
{
|
||||||
assert(!queryOnly);
|
assert(!queryOnly);
|
||||||
if (queryOnly)
|
if (queryOnly || !insertable)
|
||||||
return(DB_FAILURE);
|
return(DB_FAILURE);
|
||||||
|
|
||||||
bindInsertParams();
|
bindInsertParams();
|
||||||
|
Reference in New Issue
Block a user