+ return bindParams(TRUE);
+} // wxDbTable::bindUpdateParams()
+
+
+/********** wxDbTable::bindCols() **********/
+bool wxDbTable::bindCols(HSTMT cursor)
+{
+//RG-NULL static SDWORD cb;
+
+ // Bind each column of the table to a memory address for fetching data
+ UWORD i;
+ for (i = 0; i < noCols; i++)
+ {
+ if (SQLBindCol(cursor, (UWORD)(i+1), colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
+ colDefs[i].SzDataObj, &colDefs[i].CbValue ) != SQL_SUCCESS)
+ {
+ return (pDb->DispAllErrors(henv, hdbc, cursor));
+ }
+ }
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxDbTable::bindCols()
+
+
+/********** wxDbTable::getRec() **********/
+bool wxDbTable::getRec(UWORD fetchType)
+{
+ RETCODE retcode;
+
+ if (!pDb->FwdOnlyCursors())
+ {
+ // Fetch the NEXT, PREV, FIRST or LAST record, depending on fetchType
+ UDWORD cRowsFetched;
+ UWORD rowStatus;
+
+ retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
+ {
+ if (retcode == SQL_NO_DATA_FOUND)
+ return(FALSE);
+ else
+ return(pDb->DispAllErrors(henv, hdbc, hstmt));
+ }
+ else
+ {
+ // Set the Null member variable to indicate the Null state
+ // of each column just read in.
+ int i;
+ for (i = 0; i < noCols; i++)
+ colDefs[i].Null = (colDefs[i].CbValue == SQL_NULL_DATA);
+ }
+ }
+ else
+ {
+ // Fetch the next record from the record set
+ retcode = SQLFetch(hstmt);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
+ {
+ if (retcode == SQL_NO_DATA_FOUND)
+ return(FALSE);
+ else
+ return(pDb->DispAllErrors(henv, hdbc, hstmt));
+ }
+ else
+ {
+ // Set the Null member variable to indicate the Null state
+ // of each column just read in.
+ int i;
+ for (i = 0; i < noCols; i++)
+ colDefs[i].Null = (colDefs[i].CbValue == SQL_NULL_DATA);
+ }
+ }
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxDbTable::getRec()
+
+
+/********** wxDbTable::execDelete() **********/
+bool wxDbTable::execDelete(const wxString &pSqlStmt)
+{
+ // Execute the DELETE statement
+ if (SQLExecDirect(hstmtDelete, (UCHAR FAR *) pSqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
+ return(pDb->DispAllErrors(henv, hdbc, hstmtDelete));
+
+ // Record deleted successfully
+ return(TRUE);
+
+} // wxDbTable::execDelete()
+
+
+/********** wxDbTable::execUpdate() **********/
+bool wxDbTable::execUpdate(const wxString &pSqlStmt)
+{
+ // Execute the UPDATE statement
+ if (SQLExecDirect(hstmtUpdate, (UCHAR FAR *) pSqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS)
+ return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
+
+ // Record deleted successfully
+ return(TRUE);
+
+} // wxDbTable::execUpdate()
+
+
+/********** wxDbTable::query() **********/
+bool wxDbTable::query(int queryType, bool forUpdate, bool distinct, const wxString &pSqlStmt)
+{
+ wxString sqlStmt;
+
+ if (forUpdate)
+ // The user may wish to select for update, but the DBMS may not be capable
+ selectForUpdate = CanSelectForUpdate();
+ else
+ selectForUpdate = FALSE;
+
+ // Set the SQL SELECT string
+ if (queryType != DB_SELECT_STATEMENT) // A select statement was not passed in,
+ { // so generate a select statement.
+ BuildSelectStmt(sqlStmt, queryType, distinct);
+ pDb->WriteSqlLog(sqlStmt);
+ }
+/*
+ This is the block of code that got added during the 2.2.1 merge with
+ the 2.2 main branch that somehow got added here when it should not have. - gt
+
+ else
+ wxStrcpy(sqlStmt, pSqlStmt);
+
+ SQLFreeStmt(hstmt, SQL_CLOSE);
+ if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) == SQL_SUCCESS)
+ return(TRUE);
+ else
+ {
+ pDb->DispAllErrors(henv, hdbc, hstmt);
+ return(FALSE);
+ }
+*/
+ // Make sure the cursor is closed first
+ if (!CloseCursor(hstmt))
+ return(FALSE);
+
+ // Execute the SQL SELECT statement
+ int retcode;
+ retcode = SQLExecDirect(hstmt, (UCHAR FAR *) (queryType == DB_SELECT_STATEMENT ? pSqlStmt.c_str() : sqlStmt.c_str()), SQL_NTS);
+ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
+ return(pDb->DispAllErrors(henv, hdbc, hstmt));
+
+ // Completed successfully
+ return(TRUE);
+
+} // wxDbTable::query()
+
+
+/***************************** PUBLIC FUNCTIONS *****************************/
+
+
+/********** wxDbTable::Open() **********/
+bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
+{
+ if (!pDb)
+ return FALSE;
+
+ int i;
+ wxString sqlStmt;
+ wxString s;
+
+ s.Empty();
+ // Verify that the table exists in the database
+ if (checkTableExists && !pDb->TableExists(tableName, pDb->GetUsername(), tablePath))
+ {
+ s = wxT("Table/view does not exist in the database");
+ if ( *(pDb->dbInf.accessibleTables) == wxT('Y'))
+ s += wxT(", or you have no permissions.\n");
+ else
+ s += wxT(".\n");
+ }
+ else if (checkPrivileges)
+ {
+ // Verify the user has rights to access the table.
+ // Shortcut boolean evaluation to optimize out call to
+ // TablePrivileges
+ //
+ // Unfortunately this optimization doesn't seem to be
+ // reliable!
+ if (// *(pDb->dbInf.accessibleTables) == 'N' &&
+ !pDb->TablePrivileges(tableName,wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath))
+ s = wxT("Current logged in user does not have sufficient privileges to access this table.\n");
+ }
+
+ if (!s.IsEmpty())
+ {
+ wxString p;
+
+ if (!tablePath.IsEmpty())
+ p.Printf(wxT("Error opening '%s/%s'.\n"),tablePath.c_str(),tableName.c_str());
+ else
+ p.Printf(wxT("Error opening '%s'.\n"), tableName.c_str());
+
+ p += s;
+ pDb->LogError(p.GetData());
+
+ return(FALSE);
+ }
+
+ // Bind the member variables for field exchange between
+ // the wxDbTable object and the ODBC record.
+ if (!queryOnly)
+ {
+ if (!bindInsertParams()) // Inserts
+ return(FALSE);
+
+ if (!bindUpdateParams()) // Updates
+ return(FALSE);
+ }
+
+ if (!bindCols(*hstmtDefault)) // Selects
+ return(FALSE);
+
+ if (!bindCols(hstmtInternal)) // Internal use only
+ return(FALSE);
+
+ /*
+ * Do NOT bind the hstmtCount cursor!!!
+ */
+
+ // Build an insert statement using parameter markers
+ if (!queryOnly && noCols > 0)
+ {
+ bool needComma = FALSE;
+ sqlStmt.Printf(wxT("INSERT INTO %s ("), tableName.c_str());
+ for (i = 0; i < noCols; i++)
+ {
+ if (! colDefs[i].InsertAllowed)
+ continue;
+ if (needComma)
+ sqlStmt += wxT(",");
+ sqlStmt += colDefs[i].ColName;
+ needComma = TRUE;
+ }
+ needComma = FALSE;
+ sqlStmt += wxT(") VALUES (");
+
+ int insertableCount = 0;
+
+ for (i = 0; i < noCols; i++)
+ {
+ if (! colDefs[i].InsertAllowed)
+ continue;
+ if (needComma)
+ sqlStmt += wxT(",");
+ sqlStmt += wxT("?");
+ needComma = TRUE;
+ insertableCount++;
+ }
+ sqlStmt += wxT(")");
+
+ // Prepare the insert statement for execution
+ 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
+ return(TRUE);
+
+} // wxDbTable::Open()
+
+
+/********** wxDbTable::Query() **********/
+bool wxDbTable::Query(bool forUpdate, bool distinct)
+{
+
+ return(query(DB_SELECT_WHERE, forUpdate, distinct));
+
+} // wxDbTable::Query()
+
+
+/********** wxDbTable::QueryBySqlStmt() **********/
+bool wxDbTable::QueryBySqlStmt(const wxString &pSqlStmt)
+{
+ pDb->WriteSqlLog(pSqlStmt);
+
+ return(query(DB_SELECT_STATEMENT, FALSE, FALSE, pSqlStmt));
+
+} // wxDbTable::QueryBySqlStmt()
+
+
+/********** wxDbTable::QueryMatching() **********/
+bool wxDbTable::QueryMatching(bool forUpdate, bool distinct)
+{
+
+ return(query(DB_SELECT_MATCHING, forUpdate, distinct));
+
+} // wxDbTable::QueryMatching()
+
+
+/********** wxDbTable::QueryOnKeyFields() **********/
+bool wxDbTable::QueryOnKeyFields(bool forUpdate, bool distinct)
+{
+
+ return(query(DB_SELECT_KEYFIELDS, forUpdate, distinct));
+
+} // wxDbTable::QueryOnKeyFields()
+
+
+/********** wxDbTable::GetPrev() **********/
+bool wxDbTable::GetPrev(void)