- if (SQLSetStmtOption(c0, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, c0);
- if (SQLSetStmtOption(c2, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, c2);
-// if (SQLSetStmtOption(c3, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc, c3);
-// if (SQLSetStmtOption(c4, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc, c4);
-// if (SQLSetStmtOption(c5, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc, c5);
-
- // Set the cursor type for the INSERT statement handle
- if (SQLSetStmtOption(hstmtInsert, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtInsert);
- // Set the cursor type for the DELETE statement handle
- if (SQLSetStmtOption(hstmtDelete, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtDelete);
- // Set the cursor type for the UPDATE statement handle
- if (SQLSetStmtOption(hstmtUpdate, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtUpdate);
- // Set the cursor type for the COUNT(*) statement handle
- if (SQLSetStmtOption(hstmtCount, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtCount);
-
- // Copy cursor 1 to the default cursor
- hstmt = c1;
- currCursorNo = DB_CURSOR1;
-
-} // wxTable::wxTable()
-
-/********** wxTable::~wxTable() **********/
-wxTable::~wxTable()
-{
- // Delete memory allocated for column definitions
- if (colDefs)
- delete [] colDefs;
-
- // Free statement handles
- if (SQLFreeStmt(c0, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (SQLFreeStmt(c1, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (SQLFreeStmt(c2, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
-// if (SQLFreeStmt(c3, SQL_DROP) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc);
-// if (SQLFreeStmt(c4, SQL_DROP) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc);
-// if (SQLFreeStmt(c5, SQL_DROP) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc);
- if (SQLFreeStmt(hstmtInsert, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (SQLFreeStmt(hstmtDelete, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (SQLFreeStmt(hstmtCount, SQL_DROP) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
-
-} // wxTable::~wxTable()
-
-/********** wxTable::Open() **********/
-bool wxTable::Open(void)
-{
- int i;
- char sqlStmt[DB_MAX_STATEMENT_LEN];
-
- // Verify that the table exists in the database
- if (!pDb->TableExists(tableName))
- {
- char s[128];
- sprintf(s, "Error opening '%s', table/view does not exist in the database.", tableName);
- pDb->LogError(s);
- return(FALSE);
- }
-
- // Bind the member variables for field exchange between
- // the wxTable object and the ODBC record.
- if(! bindInsertParams()) // Inserts
- return(FALSE);
- if(! bindUpdateParams()) // Updates
- return(FALSE);
- if(! bindCols(c0)) // Selects
- return(FALSE);
- if(! bindCols(c1))
- return(FALSE);
- if(! bindCols(c2))
- return(FALSE);
-// if(! bindCols(c3))
-// return(FALSE);
-// if(! bindCols(c4))
-// return(FALSE);
-// if(! bindCols(c5))
-// return(FALSE);
-
- // Build an insert statement using parameter markers
- if (noCols > 0)
- {
- bool needComma = FALSE;
- sprintf(sqlStmt, "INSERT INTO %s (", tableName);
- for (i = 0; i < noCols; i++)
- {
- if (! colDefs[i].InsertAllowed)
- continue;
- if (needComma)
- strcat(sqlStmt, ",");
- strcat(sqlStmt, colDefs[i].ColName);
- needComma = TRUE;
- }
- needComma = FALSE;
- strcat(sqlStmt, ") VALUES (");
- for (i = 0; i < noCols; i++)
- {
- if (! colDefs[i].InsertAllowed)
- continue;
- if (needComma)
- strcat(sqlStmt, ",");
- strcat(sqlStmt, "?");
- needComma = TRUE;
- }
- strcat(sqlStmt, ")");
-
- // Prepare the insert statement for execution
- if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
- return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
- }
-
- // Completed successfully
- return(TRUE);
-
-} // wxTable::Open()
-
-/********** wxTable::Query() **********/
-bool wxTable::Query(bool forUpdate, bool distinct)
-{
-
- return(query(DB_SELECT_WHERE, forUpdate, distinct));
-
-} // wxTable::Query()
-
-/********** wxTable::QueryBySqlStmt() **********/
-bool wxTable::QueryBySqlStmt(char *pSqlStmt)
-{
-
- return(query(DB_SELECT_STATEMENT, FALSE, FALSE, pSqlStmt));
-
-} // wxTable::QueryBySqlStmt()
-
-/********** wxTable::QueryMatching() **********/
-bool wxTable::QueryMatching(bool forUpdate, bool distinct)
-{
-
- return(query(DB_SELECT_MATCHING, forUpdate, distinct));
-
-} // wxTable::QueryMatching()
-
-/********** wxTable::QueryOnKeyFields() **********/
-bool wxTable::QueryOnKeyFields(bool forUpdate, bool distinct)
-{
-
- return(query(DB_SELECT_KEYFIELDS, forUpdate, distinct));
-
-} // wxTable::QueryOnKeyFields()
-
-/********** 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,
- GetSelectStmt(sqlStmt, queryType, distinct); // so generate a select statement.
-
- // 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 ");
-
- // Add the column list
- for (int i = 0; i < noCols; i++)
- {
- strcat(pSqlStmt, colDefs[i].ColName);
- if (i + 1 < noCols)
- strcat(pSqlStmt, ",");
- }
+ // Decrement the wxDb table count
+ if (pDb)
+ pDb->decrementTableCount();
+
+ // Delete memory allocated for column definitions
+ if (colDefs)
+ delete [] colDefs;
+
+ // Free statement handles
+ if (!queryOnly)
+ {
+ if (hstmtInsert)
+ {
+/*
+ODBC 3.0 says to use this form
+ if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
+*/
+ if (SQLFreeStmt(hstmtInsert, SQL_DROP) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ }
+
+ if (hstmtDelete)
+ {
+/*
+ODBC 3.0 says to use this form
+ if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
+*/
+ if (SQLFreeStmt(hstmtDelete, SQL_DROP) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ }
+
+ if (hstmtUpdate)
+ {
+/*
+ODBC 3.0 says to use this form
+ if (SQLFreeHandle(*hstmtDel, SQL_DROP) != SQL_SUCCESS)
+*/
+ if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ }
+ }
+
+ if (hstmtInternal)
+ {
+ if (SQLFreeStmt(hstmtInternal, SQL_DROP) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ }
+
+ // Delete dynamically allocated cursors
+ if (hstmtDefault)
+ DeleteCursor(hstmtDefault);
+
+ if (hstmtCount)
+ DeleteCursor(hstmtCount);
+
+ if (m_hstmtGridQuery)
+ DeleteCursor(m_hstmtGridQuery);
+
+} // wxDbTable::cleanup()
+
+
+/***************************** PRIVATE FUNCTIONS *****************************/
+
+
+void wxDbTable::setCbValueForColumn(int columnIndex)
+{
+ switch(colDefs[columnIndex].DbDataType)
+ {
+ case DB_DATA_TYPE_VARCHAR:
+ case DB_DATA_TYPE_MEMO:
+ if (colDefs[columnIndex].Null)
+ colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[columnIndex].CbValue = SQL_NTS;
+ break;
+ case DB_DATA_TYPE_INTEGER:
+ if (colDefs[columnIndex].Null)
+ colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[columnIndex].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_FLOAT:
+ if (colDefs[columnIndex].Null)
+ colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[columnIndex].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_DATE:
+ if (colDefs[columnIndex].Null)
+ colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+ else
+ colDefs[columnIndex].CbValue = 0;
+ break;
+ case DB_DATA_TYPE_BLOB:
+ if (colDefs[columnIndex].Null)
+ colDefs[columnIndex].CbValue = SQL_NULL_DATA;
+ else
+ if (colDefs[columnIndex].SqlCtype == SQL_C_WXCHAR)
+ colDefs[columnIndex].CbValue = SQL_NTS;
+ else
+ colDefs[columnIndex].CbValue = SQL_LEN_DATA_AT_EXEC(colDefs[columnIndex].SzDataObj);
+ break;
+ }
+}
+
+/********** wxDbTable::bindParams() **********/
+bool wxDbTable::bindParams(bool forUpdate)
+{
+ wxASSERT(!queryOnly);
+ if (queryOnly)
+ return false;
+
+ SWORD fSqlType = 0;
+ SDWORD precision = 0;
+ SWORD scale = 0;
+
+ // Bind each column of the table that should be bound
+ // to a parameter marker
+ int i;
+ UWORD colNumber;
+
+ for (i=0, colNumber=1; i < m_numCols; i++)
+ {
+ if (forUpdate)
+ {
+ if (!colDefs[i].Updateable)
+ continue;
+ }
+ else
+ {
+ if (!colDefs[i].InsertAllowed)
+ continue;
+ }
+
+ switch(colDefs[i].DbDataType)
+ {
+ case DB_DATA_TYPE_VARCHAR:
+ fSqlType = pDb->GetTypeInfVarchar().FsqlType;
+ precision = colDefs[i].SzDataObj;
+ scale = 0;
+ break;
+ case DB_DATA_TYPE_MEMO:
+ fSqlType = pDb->GetTypeInfMemo().FsqlType;
+ precision = colDefs[i].SzDataObj;
+ scale = 0;
+ break;
+ case DB_DATA_TYPE_INTEGER:
+ fSqlType = pDb->GetTypeInfInteger().FsqlType;
+ precision = pDb->GetTypeInfInteger().Precision;
+ scale = 0;
+ break;
+ case DB_DATA_TYPE_FLOAT:
+ fSqlType = pDb->GetTypeInfFloat().FsqlType;
+ precision = pDb->GetTypeInfFloat().Precision;
+ scale = pDb->GetTypeInfFloat().MaximumScale;
+ // SQL Sybase Anywhere v5.5 returned a negative number for the
+ // MaxScale. This caused ODBC to kick out an error on ibscale.
+ // I check for this here and set the scale = precision.
+ //if (scale < 0)
+ // scale = (short) precision;
+ break;
+ case DB_DATA_TYPE_DATE:
+ fSqlType = pDb->GetTypeInfDate().FsqlType;
+ precision = pDb->GetTypeInfDate().Precision;
+ scale = 0;
+ break;
+ case DB_DATA_TYPE_BLOB:
+ fSqlType = pDb->GetTypeInfBlob().FsqlType;
+ precision = colDefs[i].SzDataObj;
+ scale = 0;
+ break;
+ }
+
+ setCbValueForColumn(i);
+
+ if (forUpdate)
+ {
+ if (SQLBindParameter(hstmtUpdate, colNumber++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
+ fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
+ precision+1, &colDefs[i].CbValue) != SQL_SUCCESS)
+ {
+ return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
+ }
+ }
+ else
+ {
+ if (SQLBindParameter(hstmtInsert, colNumber++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
+ fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
+ precision+1, &colDefs[i].CbValue) != SQL_SUCCESS)
+ {
+ return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
+ }
+ }
+ }
+
+ // Completed successfully
+ return true;
+
+} // wxDbTable::bindParams()
+
+
+/********** wxDbTable::bindInsertParams() **********/
+bool wxDbTable::bindInsertParams(void)
+{
+ return bindParams(false);
+} // wxDbTable::bindInsertParams()
+
+
+/********** wxDbTable::bindUpdateParams() **********/
+bool wxDbTable::bindUpdateParams(void)
+{
+ return bindParams(true);
+} // wxDbTable::bindUpdateParams()
+
+
+/********** wxDbTable::bindCols() **********/
+bool wxDbTable::bindCols(HSTMT cursor)
+{
+ // Bind each column of the table to a memory address for fetching data
+ UWORD i;
+ for (i = 0; i < m_numCols; i++)
+ {
+ if (SQLBindCol(cursor, (UWORD)(i+1), colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
+ colDefs[i].SzDataObj, &colDefs[i].CbValueCol ) != 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
+ SQLULEN 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 < m_numCols; i++)
+ colDefs[i].Null = (colDefs[i].CbValueCol == 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 < m_numCols; i++)
+ colDefs[i].Null = (colDefs[i].CbValueCol == SQL_NULL_DATA);
+ }
+ }
+
+ // Completed successfully
+ return true;
+
+} // wxDbTable::getRec()
+
+
+/********** wxDbTable::execDelete() **********/
+bool wxDbTable::execDelete(const wxString &pSqlStmt)
+{
+ RETCODE retcode;
+
+ // Execute the DELETE statement
+ retcode = SQLExecDirect(hstmtDelete, WXSQLCAST(pSqlStmt), SQL_NTS);
+
+ if (retcode == SQL_SUCCESS ||
+ retcode == SQL_NO_DATA_FOUND ||
+ retcode == SQL_SUCCESS_WITH_INFO)
+ {
+ // Record deleted successfully
+ return true;
+ }
+
+ // Problem deleting record
+ return(pDb->DispAllErrors(henv, hdbc, hstmtDelete));
+
+} // wxDbTable::execDelete()
+
+
+/********** wxDbTable::execUpdate() **********/
+bool wxDbTable::execUpdate(const wxString &pSqlStmt)
+{
+ RETCODE retcode;
+
+ // Execute the UPDATE statement
+ retcode = SQLExecDirect(hstmtUpdate, WXSQLCAST(pSqlStmt), SQL_NTS);
+
+ if (retcode == SQL_SUCCESS ||
+ retcode == SQL_NO_DATA_FOUND ||
+ retcode == SQL_SUCCESS_WITH_INFO)
+ {
+ // Record updated successfully
+ return true;
+ }
+ else if (retcode == SQL_NEED_DATA)
+ {
+ PTR pParmID;
+ retcode = SQLParamData(hstmtUpdate, &pParmID);
+ while (retcode == SQL_NEED_DATA)
+ {
+ // Find the parameter
+ int i;
+ for (i=0; i < m_numCols; i++)
+ {
+ if (colDefs[i].PtrDataObj == pParmID)
+ {
+ // We found it. Store the parameter.
+ retcode = SQLPutData(hstmtUpdate, pParmID, colDefs[i].SzDataObj);
+ if (retcode != SQL_SUCCESS)
+ {
+ pDb->DispNextError();
+ return pDb->DispAllErrors(henv, hdbc, hstmtUpdate);
+ }
+ break;
+ }
+ }
+ retcode = SQLParamData(hstmtUpdate, &pParmID);
+ }
+ if (retcode == SQL_SUCCESS ||
+ retcode == SQL_NO_DATA_FOUND ||
+ retcode == SQL_SUCCESS_WITH_INFO)
+ {
+ // Record updated successfully
+ return true;
+ }
+ }
+
+ // Problem updating record
+ return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
+
+} // 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);
+ }
+
+ // Make sure the cursor is closed first
+ if (!CloseCursor(hstmt))
+ return false;
+
+ // Execute the SQL SELECT statement
+ int retcode;
+ retcode = SQLExecDirect(hstmt, (queryType == DB_SELECT_STATEMENT ? WXSQLCAST(pSqlStmt) : WXSQLCAST(sqlStmt)), 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;
+
+ // Calculate the maximum size of the concatenated
+ // keys for use with wxDbGrid
+ m_keysize = 0;
+ for (i=0; i < m_numCols; i++)
+ {
+ if (colDefs[i].KeyField)
+ {
+ m_keysize += colDefs[i].SzDataObj;
+ }
+ }
+
+ s.Empty();
+
+ bool exists = true;
+ if (checkTableExists)
+ {
+ if (pDb->Dbms() == dbmsPOSTGRES)
+ exists = pDb->TableExists(tableName, NULL, tablePath);
+ else
+ exists = pDb->TableExists(tableName, pDb->GetUsername(), tablePath);
+ }
+
+ // Verify that the table exists in the database
+ if (!exists)
+ {
+ 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.
+ bool hasPrivs wxDUMMY_INITIALIZE(true);
+
+ if (pDb->Dbms() == dbmsPOSTGRES)
+ hasPrivs = pDb->TablePrivileges(tableName, wxT("SELECT"), pDb->GetUsername(), NULL, tablePath);
+ else
+ hasPrivs = pDb->TablePrivileges(tableName, wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath);
+
+ if (!hasPrivs)
+ s = wxT("Connecting user does not have sufficient privileges to access this table.\n");
+ }
+
+ if (!s.empty())
+ {
+ wxString p;
+
+ if (!tablePath.empty())
+ 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 && m_numCols > 0)
+ {
+ bool needComma = false;
+ sqlStmt.Printf(wxT("INSERT INTO %s ("),
+ pDb->SQLTableName(tableName.c_str()).c_str());
+ for (i = 0; i < m_numCols; i++)
+ {
+ if (! colDefs[i].InsertAllowed)
+ continue;
+ if (needComma)
+ sqlStmt += wxT(",");
+ sqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
+ needComma = true;
+ }
+ needComma = false;
+ sqlStmt += wxT(") VALUES (");
+
+ int insertableCount = 0;
+
+ for (i = 0; i < m_numCols; 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, WXSQLCAST(sqlStmt), 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()
+