#include <fstream>#include <iostream>#include <memory>#include <string>#include "TApplication.h"#include "TROOT.h"#include "TSystem.h"#include "TSQLStatement.h"#include "MessageService/MsgService.h"#include "DatabaseInterface/Dbi.h"#include "DatabaseInterface/DbiDBProxy.h"#include "DatabaseInterface/DbiCache.h"#include "DatabaseInterface/DbiConfigSet.h"#include "DatabaseInterface/test/DbiDemoData3.h"#include "DatabaseInterface/DbiCascader.h"#include "DatabaseInterface/DbiResultPtr.h"#include "DatabaseInterface/DbiSqlValPacket.h"#include "DatabaseInterface/DbiStatement.h"#include "DatabaseInterface/DbiTimerManager.h"#include "DatabaseInterface/DbiTableProxy.h"#include "DatabaseInterface/DbiWriter.h"#include "DatabaseInterface/test/DbiValidate.hh"#include "Validity/VldContext.h"#include "Validity/VldRange.h"#include "Validity/VldTimeStamp.h"Go to the source code of this file.
Functions | |
| TROOT | root ("TestDbi","MINOS Database Interface Package Test") |
| bool | DTFtest (const char *inFileName) |
| void | do_command (DbiStatement *&stmtDB, Int_t db, TString sql) |
| int | main () |
|
||||||||||||||||
|
Definition at line 131 of file TestDbi.cc. References DbiStatement::ExecuteQuery(), and DbiStatement::ExecuteUpdate(). 00131 {
00132 cout << "Db " << db << " " << sql << endl;
00133 if ( sql.BeginsWith("select",TString::kIgnoreCase) ) {
00134 TSQLStatement* stmt = stmtDB->ExecuteQuery(sql);
00135 delete stmt;
00136 }
00137 else {
00138 stmtDB->ExecuteUpdate(sql);
00139 }
00140 }
|
|
|
Definition at line 146 of file TestDbi.cc. References DbiDemoData3::Compare(), DbiCascader::CreateStatement(), DbiSqlValPacket::CreateTable(), DbiTableRow::GetAggregateNo(), DbiTableProxy::GetCache(), DbiTableProxyRegistry::GetCascader(), DbiCascader::GetConnection(), DbiConnection::GetDbType(), DbiResultPtr< T >::GetRow(), DbiDemoData3::GetTableDescr(), DbiResultPtr< T >::GetTableProxy(), DbiResultPtr< T >::GetValidityRec(), Dbi::GetVldDescr(), DbiTableProxyRegistry::Instance(), DbiCache::Purge(), DbiConnection::SetTableExists(), and DbiSqlValPacket::Store(). Referenced by main(). 00146 {
00147
00148 cout << "\n\nEnvironment ENV_DTF_TEST detected, running Data Transmission Fidelity Tests\n\n" << endl;
00149
00150 // Establish objects to access DbiDemoData3 data.
00151 DbiCascader& cascader = DbiTableProxyRegistry::Instance().GetCascader();
00152 auto_ptr<DbiStatement> stmtDbn(cascader.CreateStatement(0));
00153 if ( ! stmtDbn.get() ) {
00154 cout << " Test cannot proceed; cannot get a DbiStatement.\n" << endl;
00155 exit(1);
00156 }
00157
00158 bool testOK = true;
00159
00160 // The reference object, used to compare with others.
00161 DbiDemoData3 refDd3;
00162
00163 // Remove any existing data.
00164
00165 cout << "\nRemoving any existing DbiDemoData3 data ..." << endl;
00166 stmtDbn->ExecuteUpdate("DROP TABLE IF EXISTS DBIDEMODATA3");
00167 stmtDbn->PrintExceptions();
00168 stmtDbn->ExecuteUpdate("DROP TABLE IF EXISTS DBIDEMODATA3VLD");
00169 stmtDbn->PrintExceptions();
00170
00171 // Import test
00172
00173 cout << "\nImport test ... ";
00174 bool importTestDone = false;
00175 if ( ! strlen(inFileName) ) cout << "skipped - no import file specified.\n" << endl;
00176 else {
00177 ifstream importFile(inFileName);
00178 if ( ! importFile.good() ) {
00179 cout << "skipped - cannot read from: " << inFileName << "\n" << endl;
00180 testOK = false;
00181 }
00182 else {
00183 DbiSqlValPacket importPacket(importFile);
00184 if ( ! importPacket.CreateTable(0)
00185 || ! importPacket.Store(0)
00186 ) {
00187 cout << "skipped - import failed for file: " << inFileName << "\n" <<endl;
00188 testOK = false;
00189 }
00190 else {
00191 // Refresh list of tables in connected database
00192 cascader.GetConnection(0)->SetTableExists();
00193 DbiResultPtr<DbiDemoData3> rp_dd3(DbiDemoData3::GetContextDTF());
00194 const DbiDemoData3* pDd3 = rp_dd3.GetRow(0);
00195 if ( ! refDd3.Compare(pDd3) ) testOK = false;
00196 pDd3 = rp_dd3.GetRow(1);
00197 if ( ! refDd3.Compare(pDd3) ) testOK = false;
00198 importTestDone = true;
00199 cout << "complete, read from import file: " << inFileName << "\n" << endl;
00200 }
00201 }
00202 }
00203
00204
00205 if ( ! importTestDone ) {
00206 cout << "As import test not done, must create DbiDemoData3 table ..." << endl;
00207 std::string sql = Dbi::GetVldDescr("DBIDEMODATA3");
00208 stmtDbn->ExecuteUpdate(sql.c_str());
00209 if ( stmtDbn->PrintExceptions() ) testOK = false;
00210 sql = DbiDemoData3::GetTableDescr();
00211 stmtDbn->ExecuteUpdate(sql.c_str());
00212 if ( stmtDbn->PrintExceptions() ) testOK = false;
00213 // Refresh list of tables in connected database
00214 cascader.GetConnection(0)->SetTableExists();
00215 }
00216
00217
00218 // Internal tests. Write and read 2 rows as DbiResultSet::operator>>
00219 // reads first row using AsString to do type checking, but may use
00220 // a specfic TSqlResultSet getter for subsequent rows for speed.
00221 // Writing always does type checking.
00222
00223 cout << "Internal tests: Clearing out any existing data ..." << endl;
00224 stmtDbn->ExecuteUpdate("delete from DBIDEMODATA3");
00225 stmtDbn->PrintExceptions();
00226 stmtDbn->ExecuteUpdate("delete from DBIDEMODATA3VLD");
00227 stmtDbn->PrintExceptions();
00228 DbiResultPtr<DbiDemoData3>::GetTableProxy().GetCache()->Purge();
00229
00230 cout << " Writing new data ..." << endl;
00231 DbiWriter<DbiDemoData3> w_Dd3(DbiDemoData3::GetRangeDTF(),refDd3.GetAggregateNo());
00232 w_Dd3 << refDd3;
00233 w_Dd3 << refDd3;
00234 if ( ! w_Dd3.Close() ) testOK = false;
00235
00236 cout << " Reading data back and checking it ..." << endl;
00237 DbiResultPtr<DbiDemoData3> rp_dd3(DbiDemoData3::GetContextDTF());
00238 const DbiDemoData3* pDd3 = rp_dd3.GetRow(0);
00239 if ( ! refDd3.Compare(pDd3) ) testOK = false;
00240 pDd3 = rp_dd3.GetRow(1);
00241 if ( ! refDd3.Compare(pDd3) ) testOK = false;
00242 cout << " Complete\n" << endl;
00243
00244 // Export test
00245
00246 cout << "Export test ... ";
00247 if ( ! pDd3 ) cout << "must skip export test, failed to read back from database." << endl;
00248 else {
00249 DbiSqlValPacket exportPacket(*rp_dd3.GetValidityRec());
00250 std::string outFileName("from_mysql.dbm");
00251 if ( cascader.GetConnection(0)->GetDbType() == Dbi::kOracle ) outFileName = "from_oracle.dbm";
00252 ofstream exportFile(outFileName.c_str());
00253 if ( ! exportFile.good() ) cout << "skipped - cannot write to " << exportFile << endl;
00254 else {
00255 if ( ! exportPacket.Write(exportFile,true) ) testOK = false;
00256 else cout << "complete, wrote export file: " << outFileName << endl;
00257 }
00258 }
00259
00260 cout << "\n\nData Transmission Fidelity Test: "
00261 << ( testOK ? "passed" : "failed !!!") << "\n\n" << endl;
00262 return testOK;
00263
00264 }
|
|
|
Definition at line 40 of file TestDbi.cc. References DTFtest(), DbiTimerManager::Enable(), DbiTableProxyRegistry::GetCascader(), gSystem(), root(), server(), and Dbi::SetLogLevel(). 00040 {
00041
00042 #ifdef MACOSX
00043 TROOT root("TestDbi", "MINOS Database Interface Package Test");
00044 #endif
00045
00046 cout
00047 << " \n"
00048 << " TestDbi - Standalone testing of the DBI \n"
00049 << " \n"
00050 << " Uses special environmental variables- \n"
00051 << " \n"
00052 << " ENV_DENNIS_TEST Special tests for Dennis. \n"
00053 << " ENV_DTF_TEST Run Data Transmission Fidelity Test \n"
00054 << " ENV_NO_CLEAN_DB_TEST Don't erase test data afterwards \n"
00055 << " ENV_SKIP_ASCII_DB_TEST Skip ASCII DB tests. \n"
00056 << " ENV_TRANSLATE_SQL Translate value to ORACLE \n"
00057 << endl;
00058
00059 gROOT->SetBatch(kTRUE);
00060 TApplication::CreateApplication();
00061 Dbi::SetLogLevel(Msg::kInfo);
00062 // Dbi::SetLogLevel(Msg::kSynopsis);
00063 // Dbi::SetLogLevel(Msg::kDebug);
00064 // Dbi::SetLogLevel(Msg::kVerbose);
00065 DbiTimerManager::gTimerManager.Enable(kFALSE);
00066 // DbiResultPtr<DbiDemoData1> pet("TEST_TYPES");
00067
00068
00069 // Deal with Data Transmission Fidelity Test
00070 const char* inDTFFileName = gSystem->Getenv("ENV_DTF_TEST");
00071 if ( inDTFFileName ) {
00072 DTFtest(inDTFFileName);
00073 return 0;
00074 }
00075
00076 // Check for Dennis tests!
00077 if ( gSystem->Getenv("ENV_DENNIS_TEST") ) {
00078 cout << "\n\nEnvironment ENV_DENNIS_TEST detected, running special tests \n\n" << endl;
00079 // Dbi::SetLogLevel(Msg::kSynopsis);
00080 DbiTableProxyRegistry& tpr(DbiTableProxyRegistry::Instance());
00081 DbiCascader& cascader(tpr.GetCascader());
00082 // DbiStatement* stmtDB(cascader.CreateStatement(1));
00083 DbiConnection* con(cascader.GetConnection(1));
00084 TSQLServer* server(con->GetServer());
00085 server->EnableErrorOutput();
00086 TSQLStatement* stmtTSQL(server->Statement("select * from UGLIDBIGEOMETRYVLD where TimeStart <= '2006-07-11 12:00:00' and TimeEnd > '2006-06-21 12:00:00' and DetectorMask & 2 and SimMask & 1 and Task = 0 order by CREATIONDATE desc;"));
00087 stmtTSQL->Process();
00088 stmtTSQL->StoreResult();
00089 while ( stmtTSQL->NextResultRow() ) {
00090 cout << "debug "
00091 << " col 0 " << stmtTSQL->GetInt(0)
00092 << " col 1 " << stmtTSQL->GetString(1)
00093 << " col 2 " << stmtTSQL->GetString(2)
00094 << " col 3 " << stmtTSQL->GetInt(3)
00095 << " col 4 " << stmtTSQL->GetInt(4)
00096 << " col 5 " << stmtTSQL->GetInt(5)
00097 << " col 6 " << stmtTSQL->GetString(6)
00098 << " col 7 " << stmtTSQL->GetString(7)
00099 << endl;
00100 }
00101 delete stmtTSQL;
00102 stmtTSQL = 0;
00103
00104 VldTimeStamp ts(2006,7,1,12,0,0);
00105 VldContext vc(Detector::kFar,SimFlag::kData,ts);
00106
00107 DbiResultPtr<DbiConfigSet> cs_rp("UGLIDBIGEOMETRY",vc);
00108 return 0;
00109 }
00110
00111 // Check for SQL translation tests!
00112 if ( gSystem->Getenv("ENV_TRANSLATE_SQL") ) {
00113 string sql(gSystem->Getenv("ENV_TRANSLATE_SQL"));
00114 std::list<TString> sqlTrans(DbiTableProxyRegistry::Instance().GetCascader().CreateStatement(0)->TestTranslateSQL(sql,Dbi::kOracle));
00115 cout << "\n\nEnvironment ENV_TRANSLATE_SQL detected, SQL:-\n " << sql << endl;
00116 cout << "translates to " << sqlTrans.size() << " statements:- \n";
00117 std::list<TString>::const_iterator itr(sqlTrans.begin()), itrEnd(sqlTrans.end());
00118 while (itr != itrEnd) { cout << " " << *itr << endl; ++itr;}
00119 return 0;
00120 }
00121
00122 DbiValidate v;
00123
00124 v.RunAllTests();
00125 //v.RunTest(7);
00126 //v.RunTimeTest();
00127 return 0;
00128
00129 }
|
|
||||||||||||
|
|
1.3.9.1