//#include "AnyDB.h" #include "OracleDB.h" #include "DBQueryCreator.h" int32_t writeBlobFile(string filename, const char *buffer, uint32_t filesize /*bytes*/) { // // Write a blob from the buffer to a file // ofstream *outFile = new ofstream(); outFile->open(filename.c_str(), ios::binary); if ( outFile->is_open() == false){ cout << "*Could not open File " << filename.c_str() << endl; return 0; } // Write cout << "*Writing blob to file " << filename.c_str() << endl; outFile->write((char*)buffer, filesize); outFile->close(); return 1; } uint32_t readBlobFile(string filename, char *buffer) { // // Read a blob from a file into the buffer // ifstream *inFile = new ifstream(); inFile->open(filename.c_str(), ios::binary); if ( inFile->is_open() == false){ cout << "*Could not open File " << filename.c_str() << endl; return 0; } // get size inFile->seekg(0, ios::end); uint32_t filesize = inFile->tellg(); // read char *tmpbuffer = new char[filesize]; memset(tmpbuffer, 0, filesize); inFile->seekg (0, ios::beg); cout << "*Reading blob from file " << filename.c_str() << endl; inFile->read((char*)tmpbuffer, filesize); inFile->close(); memcpy(buffer, tmpbuffer, filesize); // delete [] tmpbuffer; return filesize; // bytes } int main( int argc, char** argv ) { AnyDB *db = new OracleDB(); db->connect("alice_dcs_tpc","alice.123","devdb10"); //db->connect("tpccfg","tpc","aldcs031"); //db->connect("tpcfero","tpc1234","alice_fero"); DBQueryCreator *dbq = new DBQueryCreator("oracle" ); /* db->calcRowCount(dbq->getSelectAltroRow(0, 1, 12, 2, 1, 8, 4)); db->executeQuery(dbq->getSelectAltroRow(0, 1, 12, 2, 1, 8, 4)); db->cacheResult(); cout << "Got " << db->getRowCount() << " Rows" << endl; if ( db->getRowCount() < 1 ) return 0; db->getRow(); cout << "db->getFieldCount()=" << db->getFieldCount() << endl; for (int32_t i=0; igetFieldCount(); i++) cout << db->getRowValueAsInt(i) << endl; */ /* db->executeUpdate(dbq->getCreateTableFEE_A()); db->executeUpdate(dbq->getCreateTableFEESERVICES_A()); db->executeUpdate(dbq->getCreateTableFEE_C()); db->executeUpdate(dbq->getCreateTableFEESERVICES_C()); db->calcRowCount(dbq->getCreateViewFEESERVICES()); db->executeQuery(dbq->getCreateViewFEESERVICES()); db->cacheResult(); cout << "Got " << db->getRowCount() << " Rows" << endl; if ( db->getRowCount() < 1 ) return 0; for (int32_t j=0; jgetRowCount(); j++) { db->getRow(); for (int32_t i=0; igetFieldCount(); i++) { cout << db->getRowValueAsString(i); if (i != (db->getFieldCount()-1) ) cout << " | "; else cout << endl; } } */ /* db->createTransaction(); db->setSQL("UPDATE TPC SET TPC.\"Revision\"=:1 WHERE tpc.\"id\"=:2"); //db->setString(uint32_t paramIndex, const string val); db->setNumber(1, 7); db->setNumber(2, 1); db->executeUpdate(); db->setNumber(1, 5); db->executeUpdate(); db->deleteTransaction(); */ db->createTransaction(); db->setSQLgetRowCount(dbq->getSqlBindSelectPartitionData()); db->setNumber(0, 5); db->setNumber(1, 1); db->setNumber(2, 12); db->setNumber(3, 4); db->executeQuery(); db->getRow(); int32_t count = db->getRowValueAsInt(0); cout << "1) Got " << count << " rows" << endl; db->deleteTransaction(); db->createTransaction(); db->setSQL(dbq->getSqlBindSelectPartitionData()); db->setNumber(0, 5); db->setNumber(1, 1); db->setNumber(2, 12); db->setNumber(3, 4); db->executeQuery(); db->getRow(); int32_t rcuId = db->getRowValueAsInt(13); cout << rcuId << endl; db->deleteTransaction(); db->createTransaction(); db->setSQLgetRowCount(dbq->getSqlBindSelectPartitionConfigData()); db->setNumber(0, rcuId); db->executeQuery(); db->getRow(); count = db->getRowValueAsInt(0); cout << "2) Got " << count << " rows" << endl; db->deleteTransaction(); db->createTransaction(); db->setSQL(dbq->getSqlBindSelectPartitionConfigData()); db->setNumber(0, rcuId); db->executeQuery(); db->getRow(); cout << db->getRowValueAsInt(0) << endl; db->deleteTransaction(); db->createTransaction(); db->setSQLgetRowCount(dbq->getSqlBindSelectAllPartitionConfigData()); db->setNumber(0, 5); db->executeQuery(); db->getRow(); count = db->getRowValueAsInt(0); cout << "3) Got " << count << " rows" << endl; db->deleteTransaction(); db->createTransaction(); db->setSQL(dbq->getSqlBindSelectAllPartitionConfigData()); db->setNumber(0, 5); db->executeQuery(); db->getRow(); cout << db->getRowValueAsInt(0) << endl; db->deleteTransaction(); ///////////////////////////////////////////////////////////////// // get list of disabled FECs /* try { db->calcRowCount(dbq->getQueryInfoDisabledFECs(16)); db->executeQuery(dbq->getQueryInfoDisabledFECs(16)); db->cacheResult(); cout << "Got " << db->getRowCount() << " Rows" << endl; cout << "====================================" << endl; if ( db->getRowCount() < 1 ) return 0; for (int32_t j=0; jgetRowCount(); j++) { db->getRow(); for (int32_t i=0; igetFieldCount(); i++) { cout << db->getRowValueAsString(i); if (i != (db->getFieldCount()-1) ) cout << " "; else cout << endl; } } db->freeResult(); } catch(SQLException& ea) { cout << ea.what() << endl; } */ ///////////////////////////////////////////////////////////////// // fill PEDMEM table /* try { for(int32_t pedmemID = 1; pedmemID <= 121*8*36; pedmemID++) { if ( !((pedmemID-1)%(121*8)) ) cout << " * Inserting new sector into PEDMEM table ..." << endl; db->executeUpdate(dbq->getSqlInsertPEDMEM(pedmemID, (pedmemID-1)%8)); } } catch(SQLException& ea) { cout << ea.what() << endl; } */ // fill PEDMEM_ALTRO table /* try { for (int32_t config = 0; config<13; config++) { cout << " * Inserting config " << config << " into PEDMEM_ALTRO table ..." << endl; for(int32_t altroID = 1; altroID <= 121*8*36; altroID++) { db->executeUpdate(dbq->getSqlInsertPEDMEM_ALTRO(altroID, altroID+config*8*121*36)); } } }catch(SQLException& ea) { cout << ea.what() << endl; } */ /* try { db->calcRowCount(dbq->getSqlSelectPartitionPedmemData(16)); db->executeQuery(dbq->getSqlSelectPartitionPedmemData(16)); db->cacheResult(); cout << "Got " << db->getRowCount() << " Rows" << endl; cout << "====================================" << endl; if ( db->getRowCount() < 1 ) return 0; for (int32_t j=0; jgetRowCount(); j++) { db->getRow(); for (int32_t i=0; i<22; i++) { cout << db->getRowValueAsString(i); if (i != 21 ) cout << " "; else cout << endl; } } db->freeResult(); } catch(SQLException& ea) { cout << ea.what() << endl; } */ /* string query = dbq->getSqlUpdateAltroPedmem(5, 0, 0, 0, 0, 0, 0, 0); int32_t pMaxBufferSize = 1000000; // 1MB char* buffer = new char[pMaxBufferSize]; cout << "*Updating blob" << endl; try { db->createTransaction(); db->setSQL(query.c_str()); db->executeQuery(); db->getRow(); uint32_t bytes = readBlobFile("test.jpg", buffer); cout << "*Filesize is " << bytes << endl; if ( bytes > (uint32_t)pMaxBufferSize ) { cout << "*Error: File is bigger than 1MB (pMaxBufferSize)!" << endl; return 0; } db->setBlob(0, buffer, bytes); db->freeResult(); } catch (SQLException ea) { cout << ea.what(); } */ /* // Get PEDMEM blob string query = dbq->getSqlSelectPedmemField(5, 0, 13, 1, 1, 11, 5, "PEDMEM_CHANNEL12"); int32_t pMaxBufferSize = 1000000; // 1MB char* buffer = new char[pMaxBufferSize]; cout << "*Reading blob" << endl; try { db->calcRowCount(query.c_str()); if ( db->getRowCount() > 1 ) { cout << "*Error: More than one row to be returned!" << endl; return 0; } if ( db->getRowCount() < 1 ) { cout << "*Error: No row to be returned!" << endl; return 0; } db->createTransaction(); db->executeQuery(query.c_str()); db->getRow(); uint32_t bytes = db->getRowValueAsBlob(0, buffer); cout << "*Got Blob, size " << bytes << endl; if ( bytes > (uint32_t)pMaxBufferSize ) { cout << "*Error: Blob is bigger than 1MB (pMaxBufferSize)!" << endl; return 0; } if ( !buffer ) cout << "*Buffer is Null" << endl; else { cout.setf(ios::dec); for ( uint32_t i = 0; i < bytes/4*4; i+=4 ) { cout << i/4*3+0 << " | " << (((buffer[i ]>>0)&0xff) | ((buffer[i+1]&0x03)<<8)) << endl; cout << i/4*3+1 << " | " << (((buffer[i+1]>>2)&0x3f) | ((buffer[i+2]&0x0f)<<6)) << endl; cout << i/4*3+2 << " | " << (((buffer[i+2]>>4)&0x0f) | ((buffer[i+3]&0x3f)<<4)) << endl; } if ( bytes%4 == 1 ) { cout << bytes/4*3 << " | " << ((buffer[bytes/4*4]>>0)&0xff) << endl; } else if ( bytes%4 == 2 ) { cout << bytes/4*3 << " | " << ((((buffer[bytes/4*4 ]>>0)&0xff) | ((buffer[bytes/4*4+1]&0x03)<<8))) << endl; cout << bytes/4*3+1 << " | " << (( buffer[bytes/4*4+1]>>2)&0x3f) << endl; } else if ( bytes%4 == 3 ) { cout << bytes/4*3 << " | " << ((((buffer[bytes/4*4 ]>>0)&0xff) | ((buffer[bytes/4*4+1]&0x03)<<8))) << endl; cout << bytes/4*3+1 << " | " << ((((buffer[bytes/4*4+1]>>2)&0x3f) | ((buffer[bytes/4*4+2]&0x0f)<<6))) << endl; cout << bytes/4*3+2 << " | " << (( buffer[bytes/4*4+2]>>4)&0x0f) << endl; } writeBlobFile("01.bin", buffer, bytes); } db->freeResult(); } catch (SQLException ea) { cout << ea.what(); } try { db->disconnect(); } catch(SQLException& ea) { cout << ea.what() << endl; } */ delete db; db = 0; delete dbq; dbq = 0; return 0; }