+/********** 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, (SQLTCHAR 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)
+{
+    if (pDb->FwdOnlyCursors())
+    {
+        wxFAIL_MSG(wxT("GetPrev()::Backward scrolling cursors are not enabled for this instance of wxDbTable"));
+        return false;
+    }
+    else
+        return(getRec(SQL_FETCH_PRIOR));
+
+}  // wxDbTable::GetPrev()
+
+
+/********** wxDbTable::operator-- **********/
+bool wxDbTable::operator--(int)
+{
+    if (pDb->FwdOnlyCursors())
+    {
+        wxFAIL_MSG(wxT("operator--:Backward scrolling cursors are not enabled for this instance of wxDbTable"));
+        return false;
+    }
+    else
+        return(getRec(SQL_FETCH_PRIOR));
+
+}  // wxDbTable::operator--
+
+
+/********** wxDbTable::GetFirst() **********/
+bool wxDbTable::GetFirst(void)
+{
+    if (pDb->FwdOnlyCursors())
+    {
+        wxFAIL_MSG(wxT("GetFirst():Backward scrolling cursors are not enabled for this instance of wxDbTable"));
+        return false;
+    }
+    else
+        return(getRec(SQL_FETCH_FIRST));
+
+}  // wxDbTable::GetFirst()
+
+
+/********** wxDbTable::GetLast() **********/
+bool wxDbTable::GetLast(void)
+{
+    if (pDb->FwdOnlyCursors())
+    {
+        wxFAIL_MSG(wxT("GetLast()::Backward scrolling cursors are not enabled for this instance of wxDbTable"));
+        return false;
+    }
+    else
+        return(getRec(SQL_FETCH_LAST));
+
+}  // wxDbTable::GetLast()
+
+
+/********** wxDbTable::BuildDeleteStmt() **********/
+void wxDbTable::BuildDeleteStmt(wxString &pSqlStmt, int typeOfDel, const wxString &pWhereClause)
+{
+    wxASSERT(!queryOnly);
+    if (queryOnly)
+        return;
+
+    wxString whereClause;
+
+    whereClause.Empty();
+
+    // 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.length() == 0))
+    {
+        pSqlStmt.Printf(wxT("DELETE FROM %s"),
+                        pDb->SQLTableName(tableName.c_str()).c_str());
+        return;
+    }
+
+    pSqlStmt.Printf(wxT("DELETE FROM %s WHERE "),
+                    pDb->SQLTableName(tableName.c_str()).c_str());
+
+    // 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 (CanUpdateByROWID())
+            {
+                SQLLEN 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)(m_numCols+1), SQL_C_WXCHAR, (UCHAR*) rowid, sizeof(rowid), &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_DEL_WHERE:
+            pSqlStmt += pWhereClause;
+            break;
+        case DB_DEL_MATCHING:
+            BuildWhereClause(whereClause, DB_WHERE_MATCHING);
+            pSqlStmt += whereClause;
+            break;
+    }
+
+}  // BuildDeleteStmt()
+
+
+/***** DEPRECATED: use wxDbTable::BuildDeleteStmt(wxString &....) form *****/
+void wxDbTable::BuildDeleteStmt(wxChar *pSqlStmt, int typeOfDel, const wxString &pWhereClause)
+{
+    wxString tempSqlStmt;
+    BuildDeleteStmt(tempSqlStmt, typeOfDel, pWhereClause);
+    wxStrcpy(pSqlStmt, tempSqlStmt);
+}  // wxDbTable::BuildDeleteStmt()
+
+
+/********** wxDbTable::BuildSelectStmt() **********/
+void wxDbTable::BuildSelectStmt(wxString &pSqlStmt, int typeOfSelect, bool distinct)
+{
+    wxString whereClause;
+    whereClause.Empty();
+
+    // Build a select statement to query the database
+    pSqlStmt = wxT("SELECT ");
+
+    // SELECT DISTINCT values only?
+    if (distinct)
+        pSqlStmt += wxT("DISTINCT ");
+
+    // Was a FROM clause specified to join tables to the base table?
+    // Available for ::Query() only!!!
+    bool appendFromClause = false;
+#if wxODBC_BACKWARD_COMPATABILITY
+    if (typeOfSelect == DB_SELECT_WHERE && from && wxStrlen(from))
+        appendFromClause = true;
+#else
+    if (typeOfSelect == DB_SELECT_WHERE && from.length())
+        appendFromClause = true;
+#endif
+
+    // Add the column list
+    int i;
+    wxString tStr;
+    for (i = 0; i < m_numCols; i++)
+    {
+        tStr = colDefs[i].ColName;
+        // If joining tables, the base table column names must be qualified to avoid ambiguity
+        if ((appendFromClause || pDb->Dbms() == dbmsACCESS) && tStr.Find(wxT('.')) == wxNOT_FOUND)
+        {
+            pSqlStmt += pDb->SQLTableName(queryTableName.c_str());
+            pSqlStmt += wxT(".");
+        }
+        pSqlStmt += pDb->SQLColumnName(colDefs[i].ColName);
+        if (i + 1 < m_numCols)
+            pSqlStmt += wxT(",");
+    }
+
+    // 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 && CanUpdateByROWID())
+    {
+        // If joining tables, the base table column names must be qualified to avoid ambiguity
+        if (appendFromClause || pDb->Dbms() == dbmsACCESS)
+        {
+            pSqlStmt += wxT(",");
+            pSqlStmt += pDb->SQLTableName(queryTableName);
+            pSqlStmt += wxT(".ROWID");
+        }
+        else
+            pSqlStmt += wxT(",ROWID");
+    }
+
+    // Append the FROM tablename portion
+    pSqlStmt += wxT(" FROM ");
+    pSqlStmt += pDb->SQLTableName(queryTableName);
+//    pSqlStmt += queryTableName;
+
+    // Sybase uses the HOLDLOCK keyword to lock a record during query.
+    // The HOLDLOCK keyword follows the table name in the from clause.
+    // Each table in the from clause must specify HOLDLOCK or
+    // NOHOLDLOCK (the default).  Note: The "FOR UPDATE" clause
+    // is parsed but ignored in SYBASE Transact-SQL.
+    if (selectForUpdate && (pDb->Dbms() == dbmsSYBASE_ASA || pDb->Dbms() == dbmsSYBASE_ASE))
+        pSqlStmt += wxT(" HOLDLOCK");
+
+    if (appendFromClause)
+        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 wxODBC_BACKWARD_COMPATABILITY
+            if (where && wxStrlen(where))   // May not want a where clause!!!
+#else
+            if (where.length())   // May not want a where clause!!!
+#endif
+            {
+                pSqlStmt += wxT(" WHERE ");
+                pSqlStmt += where;
+            }
+            break;
+        case DB_SELECT_KEYFIELDS:
+            BuildWhereClause(whereClause, DB_WHERE_KEYFIELDS);
+            if (whereClause.length())
+            {
+                pSqlStmt += wxT(" WHERE ");
+                pSqlStmt += whereClause;
+            }
+            break;
+        case DB_SELECT_MATCHING:
+            BuildWhereClause(whereClause, DB_WHERE_MATCHING);
+            if (whereClause.length())
+            {
+                pSqlStmt += wxT(" WHERE ");
+                pSqlStmt += whereClause;
+            }
+            break;
+    }
+
+    // Append the ORDER BY clause
+#if wxODBC_BACKWARD_COMPATABILITY
+    if (orderBy && wxStrlen(orderBy))
+#else
+    if (orderBy.length())
+#endif
+    {
+        pSqlStmt += wxT(" ORDER BY ");
+        pSqlStmt += orderBy;
+    }