- // Assign member variables
- pDb = pwxDB; // Pointer to the wxDB object
- strcpy(tableName, tblName); // Table Name
- if (qryTblName) // Name of the table/view to query
- strcpy(queryTableName, qryTblName);
- else
- strcpy(queryTableName, tblName);
-
- noCols = nCols; // No. of cols in the table
- where = 0; // Where clause
- orderBy = 0; // Order By clause
- selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase
-
- // 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
- else
- colDefs = 0;
-
- // Allocate statement handles for the table
- if (SQLAllocStmt(hdbc, &c0) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (SQLAllocStmt(hdbc, &c1) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
- if (SQLAllocStmt(hdbc, &c2) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
-// if (SQLAllocStmt(hdbc, &c3) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc);
-// if (SQLAllocStmt(hdbc, &c4) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc);
-// if (SQLAllocStmt(hdbc, &c5) != SQL_SUCCESS)
-// pDb->DispAllErrors(henv, hdbc);
- // 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 performing count(*) function
- if (SQLAllocStmt(hdbc, &hstmtCount) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc);
-
- // Set the cursor type for the statement handles
- UDWORD cursorType = SQL_CURSOR_STATIC;
- if (SQLSetStmtOption(c1, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
- {
- // Check to see if cursor type is supported
- pDb->GetNextError(henv, hdbc, c1);
- if (! strcmp(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(c1, SQL_CURSOR_TYPE, &cursorType) != SQL_SUCCESS)
- pDb->DispAllErrors(henv, hdbc, c1);
-#ifdef _CONSOLE
- cout << "Static cursor changed to: ";
- switch(cursorType)
- {
- case SQL_CURSOR_FORWARD_ONLY:
- cout << "Forward Only"; break;
- case SQL_CURSOR_STATIC:
- cout << "Static"; break;
- case SQL_CURSOR_KEYSET_DRIVEN:
- cout << "Keyset Driven"; break;
- case SQL_CURSOR_DYNAMIC:
- cout << "Dynamic"; break;
- }
- cout << endl << endl;
+ Initialize();
+} // Constructor
+
+
+bool wxDbColDef::Initialize()
+{
+ ColName[0] = 0;
+ DbDataType = DB_DATA_TYPE_INTEGER;
+ SqlCtype = SQL_C_LONG;
+ PtrDataObj = NULL;
+ SzDataObj = 0;
+ KeyField = FALSE;
+ Updateable = FALSE;
+ InsertAllowed = FALSE;
+ DerivedCol = FALSE;
+ CbValue = 0;
+ Null = FALSE;
+
+ return TRUE;
+} // wxDbColDef::Initialize()
+
+
+/********** wxDbTable::wxDbTable() Constructor **********/
+wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
+ const wxString &qryTblName, bool qryOnly, const wxString &tblPath)
+{
+ if (!initialize(pwxDb, tblName, numColumns, qryTblName, qryOnly, tblPath))
+ cleanup();
+} // wxDbTable::wxDbTable()
+
+
+/***** DEPRECATED: use wxDbTable::wxDbTable() format above *****/
+wxDbTable::wxDbTable(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
+ const wxChar *qryTblName, bool qryOnly, const wxString &tblPath)
+{
+ wxString tempQryTblName;
+ tempQryTblName = qryTblName;
+ if (!initialize(pwxDb, tblName, numColumns, tempQryTblName, qryOnly, tblPath))
+ cleanup();
+} // wxDbTable::wxDbTable()
+
+
+/********** wxDbTable::~wxDbTable() **********/
+wxDbTable::~wxDbTable()
+{
+ this->cleanup();
+} // wxDbTable::~wxDbTable()
+
+
+bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD numColumns,
+ 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 = numColumns; // Number 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);
+#ifdef DBDEBUG_CONSOLE
+ cout << wxT("Static cursor changed to: ");
+ switch(cursorType)
+ {
+ case SQL_CURSOR_FORWARD_ONLY:
+ cout << wxT("Forward Only");
+ break;
+ case SQL_CURSOR_STATIC:
+ cout << wxT("Static");
+ break;
+ case SQL_CURSOR_KEYSET_DRIVEN:
+ cout << wxT("Keyset Driven");
+ break;
+ case SQL_CURSOR_DYNAMIC:
+ cout << wxT("Dynamic");
+ break;
+ }
+ cout << endl << endl;
+#endif
+ // BJO20000425
+ if (pDb->FwdOnlyCursors() && cursorType != SQL_CURSOR_FORWARD_ONLY)
+ {
+ // Force the use of a forward only cursor...
+ cursorType = SQL_CURSOR_FORWARD_ONLY;
+ if (SQLSetStmtOption(hstmtInternal, SQL_CURSOR_TYPE, cursorType) != SQL_SUCCESS)
+ {
+ // Should never happen
+ pDb->GetNextError(henv, hdbc, hstmtInternal);
+ return FALSE;
+ }
+ }
+ }
+ else
+ {
+ pDb->DispNextError();
+ pDb->DispAllErrors(henv, hdbc, hstmtInternal);
+ }
+ }
+#ifdef DBDEBUG_CONSOLE
+ else
+ cout << wxT("Cursor Type set to STATIC") << endl << endl;