- assert(!queryOnly);
- if (queryOnly)
- return;
-
- char whereClause[DB_MAX_WHERE_CLAUSE_LEN];
- bool firstColumn = TRUE;
-
- whereClause[0] = 0;
- sprintf(pSqlStmt, "UPDATE %s SET ", tableName);
-
- // Append a list of columns to be updated
- int i;
- for (i = 0; i < noCols; i++)
- {
- // Only append Updateable columns
- if (colDefs[i].Updateable)
- {
- if (! firstColumn)
- wxStrcat(pSqlStmt, ",");
- else
- firstColumn = FALSE;
- wxStrcat(pSqlStmt, colDefs[i].ColName);
- wxStrcat(pSqlStmt, " = ?");
- }
- }
-
- // Append the WHERE clause to the SQL UPDATE statement
- wxStrcat(pSqlStmt, " WHERE ");
- switch(typeOfUpd)
- {
- case DB_UPD_KEYFIELDS:
- // If the datasource supports the ROWID column, build
- // the where on ROWID for efficiency purposes.
- // e.g. UPDATE PARTS SET Col1 = ?, Col2 = ? WHERE ROWID = '111.222.333'
- if (CanUpdByROWID())
- {
- SDWORD cb;
- char rowid[ROWID_LEN];
-
- // Get the ROWID value. If not successful retreiving the ROWID,
- // simply fall down through the code and build the WHERE clause
- // based on the key fields.
- if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, (UCHAR*) rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
- {
- wxStrcat(pSqlStmt, "ROWID = '");
- wxStrcat(pSqlStmt, rowid);
- wxStrcat(pSqlStmt, "'");
- break;
- }
- }
- // Unable to delete by ROWID, so build a WHERE
- // clause based on the keyfields.
- GetWhereClause(whereClause, DB_WHERE_KEYFIELDS);
- wxStrcat(pSqlStmt, whereClause);
- break;
- case DB_UPD_WHERE:
- wxStrcat(pSqlStmt, pWhereClause);
- break;
- }
-} // GetUpdateStmt()
-
-
-/********** wxTable::GetDeleteStmt() **********/
-void wxTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, const char *pWhereClause)
-{
- assert(!queryOnly);
- if (queryOnly)
- return;
-
- char whereClause[DB_MAX_WHERE_CLAUSE_LEN];
-
- whereClause[0] = 0;
-
- // Handle the case of DeleteWhere() and the where clause is blank. It should
- // delete all records from the database in this case.
- if (typeOfDel == DB_DEL_WHERE && (pWhereClause == 0 || wxStrlen(pWhereClause) == 0))
- {
- sprintf(pSqlStmt, "DELETE FROM %s", tableName);
- return;
- }
-
- sprintf(pSqlStmt, "DELETE FROM %s WHERE ", tableName);
-
- // Append the WHERE clause to the SQL DELETE statement
- switch(typeOfDel)
- {
- case DB_DEL_KEYFIELDS:
- // If the datasource supports the ROWID column, build
- // the where on ROWID for efficiency purposes.
- // e.g. DELETE FROM PARTS WHERE ROWID = '111.222.333'
- if (CanUpdByROWID())
- {
- SDWORD cb;
- char rowid[ROWID_LEN];
-
- // Get the ROWID value. If not successful retreiving the ROWID,
- // simply fall down through the code and build the WHERE clause
- // based on the key fields.
- if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, (UCHAR*) rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
- {
- wxStrcat(pSqlStmt, "ROWID = '");
- wxStrcat(pSqlStmt, rowid);
- wxStrcat(pSqlStmt, "'");
- break;
- }
- }
- // Unable to delete by ROWID, so build a WHERE
- // clause based on the keyfields.
- GetWhereClause(whereClause, DB_WHERE_KEYFIELDS);
- wxStrcat(pSqlStmt, whereClause);
- break;
- case DB_DEL_WHERE:
- wxStrcat(pSqlStmt, pWhereClause);
- break;
- case DB_DEL_MATCHING:
- GetWhereClause(whereClause, DB_WHERE_MATCHING);
- wxStrcat(pSqlStmt, whereClause);
- break;
- }
-
-} // GetDeleteStmt()
-
-
-/********** wxTable::GetWhereClause() **********/
-void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere,
- const char *qualTableName, bool useLikeComparison)