Contents Up Previous Next

wxDB

A wxDB instance is a connection to an ODBC data source which may be opened, closed, and re-opened an unlimited number of times. A database connection allows function to be performed directly on the data source, as well as allowing access to any tables/views defined in the data source to which the user has sufficient privileges.

Include files

<wx/version.h> <wx/iodbc.h> <wx/isqlext.h> <wx/db.h>

Remarks

By default, cursor directional scrolling is defined by wxODBC_FWD_ONLY_CURSORS when the wxWindows library is built. This behavior can be overridden when an instance of a wxDB is created (see wxDB constructor

See also

wxTable

Members

wxDB::wxDB
wxDB::Catalog
wxDB::Close


wxDB::wxDB

wxDB()

Default constructor.

wxDB(HENV& aHenv)

Constructor, used to create an ODBC connection to a data source.

Parameters

aHenv

Remarks

This is the constructor for the wxDB class. The wxDB object must be created and opened before any database activity can occur.

Example

   HENV Db;
   ....Set values for member variables here

   wxDB sampleDB(Db.Henv);
   if (!sampleDB.Open(Db.Dsn, Db.Uid, Db.AuthStr))
   {
      // Error opening data source
   }

wxDB::Catalog

bool Catalog(char * userID, char *fileName = SQL_CATALOG_FILENAME)

Parameters

userID

fileName

Remarks

Allows a data "dictionary" of the data source to be created, dumping pertinent information about all data tables to which the user specified in userID has access.

Example

============== ============== ================ ========= =======
TABLE NAME     COLUMN NAME    DATA TYPE        PRECISION  LENGTH
============== ============== ================ ========= =======
EMPLOYEE       RECID          (0008)NUMBER            15       8
EMPLOYEE       USER_ID        (0012)VARCHAR2          13      13
EMPLOYEE       FULL_NAME      (0012)VARCHAR2          26      26
EMPLOYEE       PASSWORD       (0012)VARCHAR2          26      26
EMPLOYEE       START_DATE     (0011)DATE              19      16

wxDB::Close

void Close()

Remarks

At the end of your program, when you have finished all of your database work, you must close the ODBC connection to the data source. There are actually four steps involved in doing this as illustrated in the example.

Example

   // Commit any open transactions on the data source
   sampleDB.CommitTrans();

   // Delete any remaining wxTable objects allocated with new
   delete parts;

   // Close the wxDB connection when finished with it
   sampleDB.Close();

   // Free Environment Handle that ODBC uses
   if (SQLFreeEnv(Db.Henv) != SQL_SUCCESS)
   {
      // Error freeing environment handle
   }