/** * * This example creates insert (replace) statements. * There particularity is to insert several objects at the same time in a single statement : * REPLACE INTO test (moname, updatetime, data) VALUES (?, ?, ?), (?, ?, ?), (? ,?, ?)..... * * These inserts succeed but if we attempt to insert more than 10 objects, then the blobs are empty. * * To test you need a table 'test' as this : +------------+-----------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-----------+------+-----+-------------------+-------+ | moname | char(64) | NO | PRI | | | | updatetime | timestamp | NO | | CURRENT_TIMESTAMP | | | data | longblob | YES | | NULL | | +------------+-----------+------+-----+-------------------+-------+ CREATE TABLE IF NOT EXISTS test (moname CHAR(64),updatetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,data LONGBLOB, PRIMARY KEY(moname)); */ // Create mysql server TMySQLServer* fMySQLServer = new TMySQLServer("mysql://localhost/AMORE", "daq", "daq"); TMySQLStatement* fStatement = 0; // To see the problem, have at least 1 block of more than 10 objects. // varying size doesn't help // only the blob is empty int nbObjPerBlock = 50; int nbBlocks = 5; int sizeOfData = 1; // in kB void testMysql() { // Iterate over the blocks for(int i = 0 ; i < nbBlocks ; i++) { // blocks // Prepare the statement Prepare(i); // Set data into the statement AssignData(i); // Execute the statement fStatement->Process(); } } void Prepare(int block) { // Prepare fStatement if (fStatement) { delete fStatement; fStatement = 0; } ostringstream strInsert; strInsert << "REPLACE INTO `test` (moname, updatetime, data) values "; for (int object = block*nbObjPerBlock ; object < block *nbObjPerBlock + nbObjPerBlock ; object++) { if(object != block*nbObjPerBlock) { strInsert << ","; } strInsert << "(?,?,?)"; } cout << "Prepare : " << strInsert.str() << endl; fStatement = (TMySQLStatement*) fMySQLServer->Statement(strInsert.str().c_str()); if (!fStatement) throw(std::runtime_error("Failed to prepare Publication statement in Prepare(...)\n")); } void AssignData(int block) { // Set the data into fStatement // prepare the bunch of data ostringstream stream; for (int k = 0 ; k < sizeOfData * 20 ; k++) {stream << "123456789 123456789 123456789 123456789 123456789" << endl;} TObjString mo(stream.str().c_str()); int index = 0; fStatement->NextIteration(); TMessage mess(kMESS_OBJECT); // for each object to be inserted for (int object = block*nbObjPerBlock; object < block * nbObjPerBlock + nbObjPerBlock ; object++) { ostringstream s; s << "test" << object; cout << "obj " << s.str() << endl; fStatement->SetString(index+0, s.str().c_str()); fStatement->SetTimestamp(index+1, 2009, 1, 1, 1, 1, 1); mess.Reset(); mess.WriteObjectAny(&mo, mo.IsA()); fStatement->SetBinary(index+2, mess.Buffer(), mess.Length() + sizeof(UInt_t), 0x2fffff6); index += 3; } }