+ // Only append Updateable columns
+ if (colDefs[i].Updateable)
+ {
+ if (!firstColumn)
+ pSqlStmt += wxT(",");
+ else
+ firstColumn = FALSE;
+
+ pSqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
+// pSqlStmt += colDefs[i].ColName;
+ pSqlStmt += wxT(" = ?");
+ }
+ }
+
+ // Append the WHERE clause to the SQL UPDATE statement
+ pSqlStmt += wxT(" 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;
+ wxChar rowid[wxDB_ROWID_LEN+1];
+
+ // 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, (UWORD)(noCols+1), SQL_C_CHAR, (UCHAR*) rowid, wxDB_ROWID_LEN, &cb) == SQL_SUCCESS)
+ {
+ pSqlStmt += wxT("ROWID = '");
+ pSqlStmt += rowid;
+ pSqlStmt += wxT("'");
+ break;
+ }
+ }
+ // Unable to delete by ROWID, so build a WHERE
+ // clause based on the keyfields.
+ BuildWhereClause(whereClause, DB_WHERE_KEYFIELDS);
+ pSqlStmt += whereClause;
+ break;
+ case DB_UPD_WHERE:
+ pSqlStmt += pWhereClause;
+ break;
+ }
+} // BuildUpdateStmt()
+
+
+/***** DEPRECATED: use wxDbTable::BuildUpdateStmt(wxString &....) form *****/
+void wxDbTable::BuildUpdateStmt(wxChar *pSqlStmt, int typeOfUpd, const wxString &pWhereClause)
+{
+ wxString tempSqlStmt;
+ BuildUpdateStmt(tempSqlStmt, typeOfUpd, pWhereClause);
+ wxStrcpy(pSqlStmt, tempSqlStmt);
+} // BuildUpdateStmt()
+
+
+/********** wxDbTable::BuildWhereClause() **********/
+void wxDbTable::BuildWhereClause(wxString &pWhereClause, int typeOfWhere,
+ const wxString &qualTableName, bool useLikeComparison)
+/*
+ * Note: BuildWhereClause() currently ignores timestamp columns.
+ * They are not included as part of the where clause.
+ */
+{
+ bool moreThanOneColumn = FALSE;
+ wxString colValue;
+
+ // Loop through the columns building a where clause as you go
+ int i;
+ for (i = 0; i < noCols; i++)
+ {
+ // Determine if this column should be included in the WHERE clause
+ if ((typeOfWhere == DB_WHERE_KEYFIELDS && colDefs[i].KeyField) ||
+ (typeOfWhere == DB_WHERE_MATCHING && (!IsColNull(i))))
+ {
+ // Skip over timestamp columns
+ if (colDefs[i].SqlCtype == SQL_C_TIMESTAMP)
+ continue;
+ // If there is more than 1 column, join them with the keyword "AND"
+ if (moreThanOneColumn)
+ pWhereClause += wxT(" AND ");
+ else
+ moreThanOneColumn = TRUE;
+ // Concatenate where phrase for the column
+ if (qualTableName.Length())
+ {
+ pWhereClause += pDb->SQLTableName(qualTableName);
+// pWhereClause += qualTableName;
+ pWhereClause += wxT(".");
+ }
+ pWhereClause += pDb->SQLColumnName(colDefs[i].ColName);
+// pWhereClause += colDefs[i].ColName;
+ if (useLikeComparison && (colDefs[i].SqlCtype == SQL_C_CHAR))
+ pWhereClause += wxT(" LIKE ");
+ else
+ pWhereClause += wxT(" = ");
+ switch(colDefs[i].SqlCtype)
+ {
+ case SQL_C_CHAR:
+ colValue.Printf(wxT("'%s'"), (UCHAR FAR *) colDefs[i].PtrDataObj);
+ break;
+ case SQL_C_SSHORT:
+ colValue.Printf(wxT("%hi"), *((SWORD *) colDefs[i].PtrDataObj));
+ break;
+ case SQL_C_USHORT:
+ colValue.Printf(wxT("%hu"), *((UWORD *) colDefs[i].PtrDataObj));
+ break;
+ case SQL_C_SLONG:
+ colValue.Printf(wxT("%li"), *((SDWORD *) colDefs[i].PtrDataObj));
+ break;
+ case SQL_C_ULONG:
+ colValue.Printf(wxT("%lu"), *((UDWORD *) colDefs[i].PtrDataObj));
+ break;
+ case SQL_C_FLOAT:
+ colValue.Printf(wxT("%.6f"), *((SFLOAT *) colDefs[i].PtrDataObj));
+ break;
+ case SQL_C_DOUBLE:
+ colValue.Printf(wxT("%.6f"), *((SDOUBLE *) colDefs[i].PtrDataObj));
+ break;
+ }
+ pWhereClause += colValue;
+ }
+ }
+} // wxDbTable::BuildWhereClause()
+
+
+/***** DEPRECATED: use wxDbTable::BuildWhereClause(wxString &....) form *****/
+void wxDbTable::BuildWhereClause(wxChar *pWhereClause, int typeOfWhere,
+ const wxString &qualTableName, bool useLikeComparison)
+{
+ wxString tempSqlStmt;
+ BuildWhereClause(tempSqlStmt, typeOfWhere, qualTableName, useLikeComparison);
+ wxStrcpy(pWhereClause, tempSqlStmt);
+} // wxDbTable::BuildWhereClause()
+
+
+/********** wxDbTable::GetRowNum() **********/
+UWORD wxDbTable::GetRowNum(void)
+{
+ UDWORD rowNum;
+
+ if (SQLGetStmtOption(hstmt, SQL_ROW_NUMBER, (UCHAR*) &rowNum) != SQL_SUCCESS)
+ {
+ pDb->DispAllErrors(henv, hdbc, hstmt);
+ return(0);
+ }
+
+ // Completed successfully
+ return((UWORD) rowNum);
+
+} // wxDbTable::GetRowNum()
+
+
+/********** wxDbTable::CloseCursor() **********/
+bool wxDbTable::CloseCursor(HSTMT cursor)
+{
+ if (SQLFreeStmt(cursor, SQL_CLOSE) != SQL_SUCCESS)
+ return(pDb->DispAllErrors(henv, hdbc, cursor));
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxDbTable::CloseCursor()
+
+
+/********** wxDbTable::CreateTable() **********/
+bool wxDbTable::CreateTable(bool attemptDrop)
+{
+ if (!pDb)
+ return FALSE;
+
+ int i, j;
+ wxString sqlStmt;
+
+#ifdef DBDEBUG_CONSOLE
+ cout << wxT("Creating Table ") << tableName << wxT("...") << endl;
+#endif
+
+ // Drop table first
+ if (attemptDrop && !DropTable())
+ return FALSE;
+
+ // Create the table
+#ifdef DBDEBUG_CONSOLE
+ for (i = 0; i < noCols; i++)
+ {
+ // Exclude derived columns since they are NOT part of the base table
+ if (colDefs[i].DerivedCol)