Logo

Code Generation for Tables in an MS Access Database

An MS Access (aka Access) database is composed of tables. Each table contains records. Records are composed of Fields. Fields may be one of many types. One field type is an identifier which is just a simple integer (probably unsigned but it doesn't really matter). The identifier is defined to be unique.

CodeGen purpose is to provide a couple of modules per table and one overall class the allow all the selected table in an Access database to be loaded. The strategy is to read a table into a c++ object, allow it to be manipulated in the c++ application and if records are modified they may be written back to the Access database.

When you pick a table in the application it requests that you supply an abbreviation of prefix all the classes (and the module file names). CodeGen
Then choose the "S" toolbar button to produce the Record Set module. The icon to the right of "S" is the table command and it will produce the "table module". The icon to the right of the table icon is the database command.

Access Record Set Class Module

This class provides an interface between the c++ application and a record in a table in the Access Database. There are two classes in the Module that work together to allow reading and writing to one or more records in an Access database:

  • class <Table Abreviation>Set -- provides direct read/write/delete operations on database
  • class <Table Abreviation>SetIter -- provides an iterator to travers a table in the database

Essentially, this class is used to read all entries in a database table and storing them in a table class that is defined specifically for this Access Table. The table class below then is used in the program and when all changes have been made, this module is used to update the Access database table. Let me say it another way:

  • Copy all records of an Access Table into a c++ class vector object

  • Read/Write the records in the c++ class vector object

  • Copy all modified records from the c++ class vector object to the Access database file

Table Module

Provides an in-application copy of an Access Database table. The module has two classes and an a typedef:

  • class <Table Abreviation>Rcd -- contains all the fields present in the Access database table from which this module was derived. After the copy from the Access database there will be one of these nodes for each record in the Access table.

  • class <Table Abreviation>Tbl -- Contains an expandable vector that contains a <Table Abreviation>Rcd object for every record in the Access database table.

  • typedef <Table Abreviation>Iter -- defines an iterator which will allow a simple for loop to touch every entry in the table.

There are various operations defined for the table and record node that are useful in the c++ application.

Database Module

When the codegen Database Command is executed a dialog box is presented with the list of tables to include in the database module. The module contains one class which "includes" all the table modules selected in the dialog box. Furthermore it defines one object called "database". The class has one operation which is "load" and its job is to load all the tables.

There is no assistance for copying data from the application back into the Access database in the Database Module. But the table modules provide that capability.