Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
DB Interface Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

21.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.

21.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-8

These lines are for initialization. They are common to all the tutorials and are explained in the comments in Section 17.5.1, "The Main Routine."

//9

Here 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.

//10

An 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.

//11

The while loop cycles through the input file. The loop terminates at the end-of-file or when something untoward happens.

//12

Customer ID numbers are fetched one at a time from the input stream. This variable holds the ID number read from the stream.

//13

Fetches an ID number from the stream.

//14-15

If an attempt to read past the end-of-file is made, breaks out of the while loop.

//16

After successfully reading in the customer ID, the remove() member function of the VVContactRepository class is invoked. This function deletes the customer record from the customer table. The remove() routine is explained in Section 21.5.2.

//17

Once a customer has been removed from the database, a log message is created about the deletion.

//18

Destructors for all the objects are called here. The database closes automatically when its destructor is called.

21.5.2 VVContactRepository::remove

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

//1

This is the definition of the remove() member function of the VVContactRepository class. It accepts one argument, the ID of the customer to be terminated.

//2

Here a deleter object is produced from the table associated with this instance of VVContactRepository. Through this instance of RWDBDeleter, rows that match a certain criterion can be removed from the table. An RWDBDeleter object encapsulates the SQL DELETE statement.

//3

On this line, a condition is formed to limit the deletion to a specific row. This condition takes the form of an RWDBCriterion instance created when applying the operator== to an RWDBColumn instance and a number. For example, this would create a condition equivalent to customer.ID = 69, if customer number 69 were to be deleted.

//4

Once the deleter is given its condition, calling the execute() member function submits the DELETE statement to the database for execution.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.