- // 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;
+
+/********** wxDbTable::wxDbTable() **********/
+wxDbTable::wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
+ const char *qryTblName, bool qryOnly, const char *tblPath)
+{
+ 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 = ""; // Where clause
+ orderBy = ""; // Order By clause
+ from = ""; // From clause
+ selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase
+ queryOnly = qryOnly;
+ insertable = TRUE;
+
+ assert (tblName);
+
+ wxStrcpy(tableName, tblName); // Table Name
+ if (tblPath)
+ wxStrcpy(tablePath, tblPath); // Table Path - used for dBase files
+
+ if (qryTblName) // Name of the table/view to query
+ wxStrcpy(queryTableName, qryTblName);
+ else
+ wxStrcpy(queryTableName, tblName);
+
+ if (!pDb)
+ return;
+
+ pDb->incrementTableCount();
+
+ wxString s;
+ tableID = ++lastTableID;
+ s.sprintf("wxDbTable constructor (%-20s) tableID:[%6lu] pDb:[%p]", tblName,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.c_str());
+
+ // 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 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);
+#ifdef DBDEBUG_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;