The next example uses an RWDBBinaryVector, RWDBBinaryVectorElement, and RWDBBlob with the RWDBBulkInserter and RWDBBulkReader classes. The program shows how you can get the data and the length of an RWDBBlob stored in an RWDBBinaryVector, an essential procedure when working with binary data.
#include <rw/rstream.h> #include <rw/db/db.h> int main() { RWDBDatabase db = RWDBManager::database( "SYBASE_CT", // access library type "aServer", // server name "aUser", // user name "aPassword", // password "aDB" // database name ); // get a connection RWDBConnection cn = db.connection(); // create an example table. RWDBTable tbl = db.table("binExample"); if( tbl.exists(cn) ) tbl.drop(cn); RWDBSchema sch; sch.appendColumn("cBlob", RWDBValue::Blob, 30); db.createTable(tbl.name(), sch, cn); // scope this section so that the RWDBBulkInserter // will release the connection // this is also needed for ct-lib to finish insertion { // insert some data RWDBBinaryVector binVector(30,5); RWDBBlob aBlob("hello there\0again", 17); for (size_t i = 0; i < 5; ++i) binVector[i] = aBlob; RWDBBulkInserter ins = tbl.bulkInserter(cn); ins << binVector; ins.execute(); } // scoped so that RWDBBulkReader releases the connection { // now read back the data and print it to the screen RWDBBulkReader rdr = tbl.bulkReader(cn); RWDBBinaryVector binVector(30,5); rdr << binVector; size_t rowsRead; while( rowsRead = rdr()) { for (size_t i = 0; i < rowsRead; ++i) { RWDBBinaryVectorElement element = binVector[i]; cout << "the blob's length is: " << binVector.width(i) << endl; cout << "the blob's data is: "; unsigned char* ptr = (unsigned char*) element; for (size_t j = 0; j < binVector.width(i); ++j, ++ptr) cout.put(*ptr); cout << endl; } } } tbl.drop(); return 0; }
For more information on bulk reading and writing, see the entries in the DBTools.h++ Class Reference on RWDBBulkInserter and RWDBBulkReader, and their related classes RWDBVector<T>, RWDBDateVector, RWDBStringVector, RWDBBinaryVector, and RWDBVendorDate.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.