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.
The Main Routine
The following is the main routine for the tutorial. The line numbers correspond to the comments that follow the code.
#include <rw/db/db.h> //1
#include "tututil.h" //2
#include "conrep.h" //3
int main(int argc, char** argv) //4
{
associateStreams("t5in.dat", "t5out.txt", "t5err.txt"); //5
RWDBManager::setErrorHandler(outputStatus); //6
RWCString serverType, serverName, userName,
password, databaseName, pstring; //7
initializeDatabaseArguments(argc, argv, serverType,
serverName, userName, password,
databaseName, pstring); //8
RWDBDatabase aDB = RWDBManager::database
(serverType, serverName, userName, password,
databaseName, pstring); //9
VVContactRepository customerRep(aDB, customerTable); //10
while (!inStream.eof()
&& !inStream.bad() && !inStream.fail()) { //11
unsigned long id; //12
inStream >> id; //13
if (inStream.eof()) //14
break; //15
customerRep.remove( id ); //16
outStream << "Removed customer with ID = "
<< id << " from the database." << endl; //17
}
closeStreams("t5in.dat", "t5out.txt", "t5err.txt");
return 0;
} //18
VVContactRepository::remove
The remove() member function of VVContactRepository takes a customer ID and removes the associated customer from the customer list.
VVContactRepository&
VVContactRepository::remove(unsigned long id) //1
{
RWDBDeleter aDeleter = table_.deleter(); //2
aDeleter.where(idColumn_ == id); //3
aDeleter.execute(); //4
return *this;
}