Overloading the Extraction Operator

The extraction operator is defined for all the C++ and DB Interface Module data types. Naturally, it is easy to define it for your own classes. For example:

 

struct Purchase {

int videoID;

int supplierID;

int purchaseOrderNumber;

RWDecimalPortable pricePerUnit;

int quantity;

RWDateTime date;

};

RWDBReader&

operator>>(RWDBReader& rdr, Purchase& p) {

rdr >> p.videoID >> p.supplierID

>> p.purchaseOrderNumber

>> p.pricePerUnit >> p.quantity >> p.date;

return rdr;

}

Now we can read from the purchase table directly into Purchase instances:

 

Purchase p;

 

while (rdr()) {

rdr >> p;

// process p;

}

This is an important technique, and it is explained more thoroughly in Retrieving Data from a Table the first advanced tutorial.