The following example illustrates the use of RWDBBulkInserter, RWDBBulkReader, and the related vector classes RWDBVector, RWDBDateVector, and RWDBBinaryVector, to insert, read, and print out the values in the purchase table.
// Example Program 6 - Bulk reads and writes void insertPurchaseTable(const RWDBDatabase& db) { RWDBTable tab = db.table("purchase"); RWDBBulkInserter ins = tab.bulkInserter(db.connection()); int vectorLength = 10; RWDBVector<int> videoID(vectorLength); RWDBVector<int> supplierID(vectorLength); RWDBVector<int> purchaseOrderNumber(vectorLength); RWDBVector<double> pricePerUnit(vectorLength); RWDBVector<int> quantity(vectorLength); // Note that we need a database to produce a vendor-specific // date vector. RWDBDateVector dateVector = db.dateVector(vectorLength); // Bind the arrays to the inserter before execution. ins << videoID << supplierID << purchaseOrderNumber << pricePerUnit << quantity << dateVector; // Initiate data: RWDBDateTime now; for (int i = 0; i < vectorLength; i++) { videoID[i] = supplierID[i] = purchaseOrderNumber[i] = pricePerUnit[i] = quantity[i] = i; dateVector[i] = now; } ins.execute(); return; } void readPurchaseTable(const RWDBDatabase& db) { RWDBTable tab = db.table("purchase"); RWDBBulkReader rdr = tab.bulkReader(db.connection()); int vectorLength = 10; RWDBVector<int> videoID(vectorLength); RWDBVector<int> supplierID(vectorLength); RWDBVector<int> purchaseOrderNumber(vectorLength); RWDBVector<double> pricePerUnit(vectorLength); RWDBVector<int> quantity(vectorLength); // Note that we need a database to produce a vendor-specific // date vector. RWDBDateVector dateVector = db.dateVector(vectorLength); // Bind the arrays to the reader before execution. rdr << videoID << supplierID << purchaseOrderNumber << pricePerUnit << quantity << dateVector; // Fetch up to vectorLength rows at a time. int rowsRead= 0; while (rowsRead = rdr()) { for (int i = 0; i < rowsRead; i++) { cout << videoID[i] << supplierID[i] << purchaseOrderNumber[i] << pricePerUnit[i] << quantity[i] << dateVector[i].asString() << endl; } } }
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.