Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

19.5 The Program

This section examines the program you just ran, which writes a list of the customer IDs that were successfully deleted from the database. The file called t5out.txt contains a log of the customer IDs that were processed.

19.5.1 The Main Routine

The following is the main routine for the tutorial. The line numbers correspond to the comments that follow the code.

//1-9These lines are for initialization and multiplatform portability. They are common to all the tutorials and are explained in Section 15.5.1.
//10Here a connection to a database server is established. The variable aDB serves as a handle to the database defined by arguments to the RWDBManager::database function.
//11An instance of the class VVContactRepository representing the customer table is created on this line. The first argument, aDB, identifies the database in which the instance's data resides. The second argument identifies the specific table name that holds the customer information.
//12The while loop here cycles through the input file. The loop should terminate at the end-of-file or when something untoward happens.
//13Customer ID numbers are fetched one at a time from the input stream. This variable holds the ID number read from the stream.
//14Fetches an ID number from the stream.
//15-16If an attempt to read past the end-of-file is made, breaks out of the while loop.
//17After successfully reading in the customer ID, invoke the remove() member function of the VVContactRepository class. This function deletes the customer record from the customer table. The remove() routine is explained in Section 19.5.2.
//18Once a customer has been removed from the database, a log message is created about the deletion.
//19Destructors for all the objects are called here. The database closes automatically along with the output and input streams.

19.5.2 VVContactRepository::remove

The remove() member function of VVContactRepository takes a customer ID and removes the associated customer from the customer list.

//1This is the definition of the remove() member function of the VVContactRepository class. It accepts one argument, the ID of the customer to be terminated.
//2Here a deleter object is fetched from the table associated with this instance of VVContactRepository. Through this new instance of RWDBDeleter, rows that match a certain criterion can be removed from the table. An RWDBDeleter object encapsulates the SQL DELETE statement.
//3On this line, a predicate is formed to limit the deletion to a specific row. This predicate takes the form of an RWDBCriterion instance created when applying the operator== to an RWDBColumn instance and a number. For example, this might create a predicate equivalent to customer.ID = 69, if customer number 69 were to be deleted.
//4Once the deleter is given its predicate, calling the execute() member function submits the DELETE statement to the database.

Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.