<< Return to Main Index

< Return to Class Index

class CGXDBToolsEngine

This is an implementation of CGXDBEngine that is bound to DBTools.

Besides implementing the interfaces exposed by CGXDBEngine this class also gives you three different ways to initialize the grid. As explained in the above section, it's mandatory for the implementation class to expose an initialization API. There are 3 different types of query results got via DBTools that could be used to initialize the engine.

Case 1:A complete database table with no selection criterion:

CGXDBToolsEngine(RWDBTable table, RWDBSchema updateCols, RWDBConnection conn);

Case 2:A table with a selection criterion:

CGXDBToolsEngine(RWDBTable table, RWDBSelector selector, RWDBSchema visibleCols, RWDBSchema updateCols,  RWDBConnection conn);

Case 3: A read only join:

CGXDBToolsEngine(RWDBSelector selector, RWDBConnection conn);

There are also member-function variants for these constructors which you can use to initialize an engine created with the default constructor or re-initialize the engine at a later time:

void Init(RWDBTable table, RWDBSchema updateCols, RWDBConnection conn);

void Init(RWDBTable table, RWDBSelector selector, RWDBSchema visibleCols, RWDBSchema updateCols,  RWDBConnection conn);

void Init(RWDBSelector selector, RWDBConnection conn);

Note that if any of these re-initializing calls will change the schema of the result set then you will have to re-initialize the grid to reflect this new schema with a call to InitFromEngine.

Basically, the engine gets a RWDBReader from the RWDBTable (case 1) or from RWDBSelector (case 2, case 3), parses through each record getting an RWDBRow and uses it to fill an internal pointer list of type RWTPtrSlist<RWDBRow>. It latter gets data from this list as and when the layout manager asks for it through GetValue. It converts the data in any type to a string before passing it on to the GetValue.

When storing updates and new records, it creates a RWDBUpdater or a RWDBInserter, prepares it with the appropriate parameters and executes it.

Here is some example code as to how to create and initialize a CGXDBToolsEngine and bind it to the grid.

CMyDBToolsGridView::OnInitialUpdate()
{
………
RWDBDatabase::connect(false);
RWDBManager::setErrorHandler(myErrorHandler);
RWDBDatabase aDB = RWDBManager::database("ODBC", x_lpcszSource, "", "", "");
ASSERT(aDB.isValid());
aDB.setErrorHandler(myErrorHandler);   // custom error handler
RWDBConnection conn = aDB.connection();
// Case 1: Bind the engine to a plain database table
RWDBTable aTable = aDB.table(x_lpcszTable);// a valid table name
ASSERT(aTable.isValid());
RWDBSchema updateCols; // Pass an empty udpateCols
CGXDBToolsEngine* engine = new CGXDBToolsEngine(aTable, updateCols, conn);
SetEngine(GetDocument()->m_pDBEngine);
// Implementation(DBTools) specific initailization function.
// Always call this after SetEngine.
m_pLayoutManager->m_pfInitFunction = GXInitDBToolsGridFromDBToolsEngine;
CMyDBEGridView::OnInitialUpdate();
………
}

For more information take a look at the "Database Engine User's guide" in dbguide.doc.

#include <dbe\dbteng.h>

See Also

CGXDBEngine CGXBrowserLayoutManager CGXDBEGrid

CGXDBToolsEngine

Class Members