The Main Routine
This code sample shows the main routine for the tutorial. The line numbers correspond to the comments that follow the code.
 
#include <rw/db/db.h> //1
 
#include "conrep.h" //2
#include "rentrep.h" //3
#include "tututil.h" //4
 
int main(int argc, char** argv) //5
{
associateStreams("", "t2out.txt", "t2err.txt");
RWDBManager::setErrorHandler (outputStatus);
 
RWCString serverType, serverName, userName,
password, databaseName, pstring;
initializeDatabaseArguments(argc, argv, serverType,
serverName, userName, password,
databaseName, pstring); //5
 
RWDBDatabase aDB = RWDBManager::database
(serverType, serverName, userName, password,
databaseName, pstring); //6
 
 
VVContactRepository customerPool (aDB,
customerTableName); //7
VVRentalTransactionRepository rentalTransactions
(aDB, rentalTableName); //8
 
RWDBColumn customerID = customerPool.idColumn(); //9
RWDBColumn rentalCustomerID =
rentalTransactions.customeridColumn(); //10
RWDBColumn dueDate =
rentalTransactions.dueDateColumn(); //11
RWDateTime aWeekAgo(9,6,2000); //12
aWeekAgo = aWeekAgo - (7 * RWDateTime::millisecsInDay); //13
 
customerPool.mailingLabels (outStream,
customerID == rentalCustomerID &&
dueDate < aWeekAgo); //14
 
closeStreams ("", "t2out.txt", "t2err.txt");
return 0;
} //15
 
Here is a line-by-line description of the program:
//1 Include the declarations for the DB Interface Module classes used here.
//2 Include the declaration of the class VVContactRepository.
//3 Include the declaration of the class VVRentalTransactionRepository.
//4 Include the declarations for the utility routines used by all the tutorials.
//5 The code block at //5 is for initialization. These lines are common to all the tutorials and are explained in the comments in The Main Routine.
//6 Here an actual connection to a database server is established. The variable aDB will serve as a means to access the database defined by arguments to the RWDBManager::database() function.
//7 An instance of the class VVContactRepository is created on this line. The first argument, aDB, identifies the database in which the instance’s data resides. The second argument identifies the name of the specific table that holds the customer information. This constructor was explained in detail in Tutorial One.
//8 An instance of the class VVRentalTransactionRepository is created on this line. The first argument, aDB, identifies the database in which instance’s data resides. The second argument identifies the specific table that holds the rental transaction information. The constructor invoked here is quite simple and parallels the VVContactRepository constructor.
//9 Here an instance of RWDBColumn that represents the ID column of the customer table is created. This instance will be used in creating a predicate to be used in a criterion for the selection. The idColumn() member function of the class VVContactRepository returns the column instance created in the VVContactRepository constructor.
//10 Here an instance of RWDBColumn representing the customerID column of the rental transaction table is created. The customerIDColumn() member function of the class VVRentalTransactionRepository returns the column instance created in the VVRentalTransactionRepository constructor.
//11 Here an instance of RWDBColumn representing the dueDate column of the rental transaction table is created.
//12 This instance of RWDateTime is initialized to June 9th, 2000.
//13 Subtracting seven days yields the date a week ago.
//14 Here the mailingLabels() member function of VVContactRepository is executed. It accepts a reference to an output stream and an RWDBCriterion. The criterion is created anonymously by using overloaded relational operators on RWDBColumn instances. The result is the predicate that will be used in selecting the appropriate data from the customer table.
//15 Destructors for all the objects are called here. The database closes automatically when its destructor is called.