-/********** wxTable::query() **********/
-bool wxTable::query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt)
-{
- char sqlStmt[DB_MAX_STATEMENT_LEN];
-
- // Set the selectForUpdate member variable
- 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.
- GetSelectStmt(sqlStmt, queryType, distinct);
- pDb->WriteSqlLog(sqlStmt);
- }
-
- // Make sure the cursor is closed first
- if (! CloseCursor(hstmt))
- return(FALSE);
-
- // Execute the SQL SELECT statement
- if (SQLExecDirect(hstmt, (UCHAR FAR *) (queryType == DB_SELECT_STATEMENT ? pSqlStmt : sqlStmt),
- SQL_NTS) != SQL_SUCCESS)
- return(pDb->DispAllErrors(henv, hdbc, hstmt));
-
- // Completed successfully
- return(TRUE);
-
-} // wxTable::query()
-
-/********** wxTable::GetSelectStmt() **********/
-void wxTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
-{
- char whereClause[DB_MAX_WHERE_CLAUSE_LEN];
-
- whereClause[0] = 0;
-
- // Build a select statement to query the database
- strcpy(pSqlStmt, "SELECT ");
-
- // SELECT DISTINCT values only?
- if (distinct)
- strcat(pSqlStmt, "DISTINCT ");
-
- // Was a FROM clause specified to join tables to the base table?
- // Available for ::Query() only!!!
- bool appendFromClause = FALSE;
- if (typeOfSelect == DB_SELECT_WHERE && from && strlen(from))
- appendFromClause = TRUE;
-
- // Add the column list
- for (int i = 0; i < noCols; i++)
- {
- // If joining tables, the base table column names must be qualified to avoid ambiguity
- if (appendFromClause)
- {
- strcat(pSqlStmt, queryTableName);
- strcat(pSqlStmt, ".");
- }
- strcat(pSqlStmt, colDefs[i].ColName);
- if (i + 1 < noCols)
- strcat(pSqlStmt, ",");
- }
-
- // If the datasource supports ROWID, get this column as well. Exception: Don't retrieve
- // the ROWID if querying distinct records. The rowid will always be unique.
- if (!distinct && CanUpdByROWID())
- {
- // If joining tables, the base table column names must be qualified to avoid ambiguity
- if (appendFromClause)
- {
- strcat(pSqlStmt, ",");
- strcat(pSqlStmt, queryTableName);
- strcat(pSqlStmt, ".ROWID");
- }
- else
- strcat(pSqlStmt, ",ROWID");
- }
-
- // Append the FROM tablename portion
- strcat(pSqlStmt, " FROM ");
- strcat(pSqlStmt, queryTableName);
- if (appendFromClause)
- strcat(pSqlStmt, from);
-
- // Append the WHERE clause. Either append the where clause for the class
- // or build a where clause. The typeOfSelect determines this.
- switch(typeOfSelect)
- {
- case DB_SELECT_WHERE:
- if (where && strlen(where)) // May not want a where clause!!!
- {
- strcat(pSqlStmt, " WHERE ");
- strcat(pSqlStmt, where);
- }
- break;
- case DB_SELECT_KEYFIELDS:
- GetWhereClause(whereClause, DB_WHERE_KEYFIELDS);
- if (strlen(whereClause))
- {
- strcat(pSqlStmt, " WHERE ");
- strcat(pSqlStmt, whereClause);
- }
- break;
- case DB_SELECT_MATCHING:
- GetWhereClause(whereClause, DB_WHERE_MATCHING);
- if (strlen(whereClause))
- {
- strcat(pSqlStmt, " WHERE ");
- strcat(pSqlStmt, whereClause);
- }
- break;
- }
-
- // Append the ORDER BY clause
- if (orderBy && strlen(orderBy))
- {
- strcat(pSqlStmt, " ORDER BY ");
- strcat(pSqlStmt, orderBy);
- }
-
- // SELECT FOR UPDATE if told to do so and the datasource is capable
- if (selectForUpdate && CanSelectForUpdate())
- strcat(pSqlStmt, " FOR UPDATE");
-
-} // wxTable::GetSelectStmt()
-
-/********** wxTable::getRec() **********/
-bool wxTable::getRec(UWORD fetchType)