VVVideoRepository::update
The update() member function of VVVideoRepository accepts three parameters, first two of which are instances of VVVideo. The first instance identifies the record to be changed, while the second instance is used as new information. The third parameter is an instance of RWDBConnection which is used to execute the update.
 
VVVideoRepository&
VVVideoRepository::update(const VVVideo& originalVideo,
const VVVideo& newVideo,
const RWDBConnection& aConnection) //1
{
RWDBUpdater anUpdater = table_.updater(); //2
anUpdater.where(idColumn_ == originalVideo.id()); //3
 
anUpdater << titleColumn_.assign(newVideo.title())
<< idColumn_.assign(newVideo.id())
<< yearColumn_.assign(newVideo.year())
<< categoryColumn_.assign(newVideo.category())
<< quantityColumn_.assign(newVideo.quantity())
<< numOnHandColumn_.assign(newVideo.numOnHand())
<< synopsisColumn_.assign(newVideo.synopsis()); //4
 
anUpdater.execute(aConnection); //5
 
return *this;
}
 
//1 This is the definition of the update() member function for the VVVideoRepository class. It accepts three parameters, first two of which are instances of VVVideo. The first represents the original video to update, the second represents the new values. Only the ID field of the original record is used to identify the record to be changed. The third parameter is an instance of RWDBConnection which is used to execute the update.
//2 An RWDBUpdater instance associated with the videos table is created here.
//3 A condition is created here that identifies the row in the videos table to be updated. The condition takes the form of an RWDBCriterion that is created by applying the operator== to the RWDBColumn instance idColumn_. Assuming that the original ID was 34, this predicate will be the equivalent of videos.ID = 34.
//4 A series of RWDBAssignment instances are created on this line and shifted in the RWDBUpdater defining the SET clause of the UPDATE statement. Each RWDBAssignment instance is created using the RWDBColumn::assign() method. Each column of the videos table is assigned the corresponding value from the newVideo object, thus updating the row selected by the condition on //3 to match the values in newVideo.
//5 The RWDBUpdater is executed using the supplied RWDBConnection.