- pDb->WriteSqlLog(s);
-
- // Grab the HENV and HDBC from the wxDB object
- henv = pDb->henv;
- hdbc = pDb->hdbc;
-
- // Allocate space for column definitions
- if (noCols)
- colDefs = new CcolDef[noCols]; // Points to the first column defintion
-
- // Allocate statement handles for the table
- if (!queryOnly)
- {
- // Allocate a separate statement handle for performing inserts
- if (SQLAllocStmt(hdbc, &hstmtInsert) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- // Allocate a separate statement handle for performing deletes
- if (SQLAllocStmt(hdbc, &hstmtDelete) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- // Allocate a separate statement handle for performing updates
- if (SQLAllocStmt(hdbc, &hstmtUpdate) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- }
- // Allocate a separate statement handle for internal use
- if (SQLAllocStmt(hdbc, &hstmtInternal) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
-
- // Set the cursor type for the statement handles
- cursorType = SQL_CURSOR_STATIC;
- if (SQLSetStmtOption(hstmtInternal, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
- {
- // Check to see if cursor type is supported
- pDb->GetNextError(henv, hdbc, hstmtInternal);
- if (! wxStrcmp(pDb->sqlState, "01S02")) // Option Value Changed
- {
- // Datasource does not support static cursors. Driver
- // will substitute a cursor type. Call SQLGetStmtOption()
- // to determine which cursor type was selected.
- if (SQLGetStmtOption(hstmtInternal, SQL_CURSOR_TYPE, &cursorType) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, hstmtInternal);
+
+/***** DEPRECATED: use wxDbTable::wxDbTable() format above *****/
+wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const int nCols,
+ const wxChar *qryTblName, bool qryOnly, const wxString &tblPath)
+{
+ wxString tempQryTblName;
+ tempQryTblName = qryTblName;
+ if (!initialize(pwxDb, tblName, nCols, tempQryTblName, qryOnly, tblPath))
+ cleanup();
+} // wxDbTable::wxDbTable()
+
+
+/********** wxDbTable::~wxDbTable() **********/
+wxDbTable::~wxDbTable()
+{
+ this->cleanup();
+} // wxDbTable::~wxDbTable()
+
+
+bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const int nCols,
+ const wxString &qryTblName, bool qryOnly, const wxString &tblPath)
+{
+ // Initializing member variables
+ pDb = pwxDb; // Pointer to the wxDb object
+ henv = 0;
+ hdbc = 0;
+ hstmt = 0;
+ hstmtDefault = 0; // Initialized below
+ hstmtCount = 0; // Initialized first time it is needed
+ hstmtInsert = 0;
+ hstmtDelete = 0;
+ hstmtUpdate = 0;
+ hstmtInternal = 0;
+ colDefs = 0;
+ tableID = 0;
+ noCols = nCols; // No. of cols in the table
+ where.Empty(); // Where clause
+ orderBy.Empty(); // Order By clause
+ from.Empty(); // From clause
+ selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase
+ queryOnly = qryOnly;
+ insertable = TRUE;
+ tablePath.Empty();
+ tableName.Empty();
+ queryTableName.Empty();
+
+ wxASSERT(tblName.Length());
+ wxASSERT(pDb);
+
+ if (!pDb)
+ return FALSE;
+
+ tableName = tblName; // Table Name
+ if (tblPath.Length())
+ tablePath = tblPath; // Table Path - used for dBase files
+ else
+ tablePath.Empty();
+
+ if (qryTblName.Length()) // Name of the table/view to query
+ queryTableName = qryTblName;
+ else
+ queryTableName = tblName;
+
+ pDb->incrementTableCount();
+
+ wxString s;
+ tableID = ++lastTableID;
+ s.Printf(wxT("wxDbTable constructor (%-20s) tableID:[%6lu] pDb:[%p]"), tblName.c_str(), tableID, pDb);
+
+#ifdef __WXDEBUG__
+ wxTablesInUse *tableInUse;
+ tableInUse = new wxTablesInUse();
+ tableInUse->tableName = tblName;
+ tableInUse->tableID = tableID;
+ tableInUse->pDb = pDb;
+ TablesInUse.Append(tableInUse);
+#endif
+
+ pDb->WriteSqlLog(s);
+
+ // Grab the HENV and HDBC from the wxDb object
+ henv = pDb->GetHENV();
+ hdbc = pDb->GetHDBC();
+
+ // Allocate space for column definitions
+ if (noCols)
+ colDefs = new wxDbColDef[noCols]; // Points to the first column definition
+
+ // Allocate statement handles for the table
+ if (!queryOnly)
+ {
+ // Allocate a separate statement handle for performing inserts
+ if (SQLAllocStmt(hdbc, &hstmtInsert) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ // Allocate a separate statement handle for performing deletes
+ if (SQLAllocStmt(hdbc, &hstmtDelete) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ // Allocate a separate statement handle for performing updates
+ if (SQLAllocStmt(hdbc, &hstmtUpdate) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+ }
+ // Allocate a separate statement handle for internal use
+ if (SQLAllocStmt(hdbc, &hstmtInternal) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc);
+
+ // Set the cursor type for the statement handles
+ cursorType = SQL_CURSOR_STATIC;
+
+ if (SQLSetStmtOption(hstmtInternal, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
+ {
+ // Check to see if cursor type is supported
+ pDb->GetNextError(henv, hdbc, hstmtInternal);
+ if (! wxStrcmp(pDb->sqlState, wxT("01S02"))) // Option Value Changed
+ {
+ // Datasource does not support static cursors. Driver
+ // will substitute a cursor type. Call SQLGetStmtOption()
+ // to determine which cursor type was selected.
+ if (SQLGetStmtOption(hstmtInternal, SQL_CURSOR_TYPE, &cursorType) != SQL_SUCCESS)
+ pDb->DispAllErrors(henv, hdbc, hstmtInternal);