The Program
This section examines the t3 program you just ran. Its purpose is to write a list of the new customers who were successfully added to the database to a file called t3out.txt.
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 "conrep.h" //2
#include "tututil.h" //3
int main(int argc, char** argv) //4
{
associateStreams("t3in.dat", "t3out.txt",
"t3err.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 customerPool(aDB, customerTable); //10
VVContact aCustomer; //11
while (aCustomer.read(inStream)) { //12
customerPool.insert(aCustomer); //13
outStream << aCustomer.name()
<< " has been added to the customer table."
<< endl; //14
}
closeStreams("t3in.dat", "t3out.txt", "t3err.txt");
return 0;
} //15
VVContactRepository::insert
The insert member function of VVContactRepository takes an instance of VVContact and inserts it into the table associated with this instance of VVContactRepository.
VVContactRepository&
VVContactRepository::insert(const VVContact& aContact) //1
{
RWDBInserter anInserter = table_.inserter(); //2
anInserter << aContact; //3
return *this;
}
operator<<() for VVContact
The purpose of this overloaded function is to ease the insertion of a
VVContact instance into an
RWDBInserter instance. The function combines the shifting of the individual components of a
VVContact into a single function.
RWDBInserter&
operator<< (RWDBInserter& aInserter,
const VVContact& aContact) //1
{
aInserter << aContact.name() << aContact.id()
<< aContact.address() << aContact.city()
<< aContact.state() << aContact.zip()
<< aContact.phone(); //2
aInserter.execute(); //3
return aInserter;
}