File indexing completed on 2025-08-03 08:22:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef __CINT__
0030
0031
0032 #include <TError.h>
0033 #include <TH1.h>
0034 #include <TH2.h>
0035 #include <TProfile.h>
0036 #include <TRandom.h>
0037 #include <TROOT.h>
0038 #include <TSQLDriverManager.h>
0039 #include <TSQLConnection.h>
0040 #include <TSQLResultSet.h>
0041 #include <TSQLResultSetMetaData.h>
0042 #include <TSQLPreparedStatement.h>
0043
0044 #endif
0045
0046 const TString tableName = "object_test";
0047
0048
0049 TH1F* hpx;
0050 TH2F* hpxpy;
0051 TProfile* hprof;
0052
0053
0054 void CreateStuff(TSQLConnection* con)
0055 {
0056
0057
0058
0059 TSQLStatement* stmt = con->CreateStatement();
0060
0061 stmt->ExecuteUpdate( "delete from " + tableName);
0062 delete stmt;
0063
0064 TSQLPreparedStatement* pstmt = con->PrepareStatement(
0065 "insert into " +tableName+
0066 "(name,histos) values(?,?)" );
0067
0068 hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
0069 hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
0070 hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
0071
0072
0073 hpx->SetFillColor(48);
0074
0075 Float_t px, py, pz;
0076 int ii = 0;
0077
0078
0079 for (ii = 0; ii < 1000; ii++)
0080 {
0081 gRandom->Rannor(px,py);
0082 pz = px*px + py*py;
0083 hpx->Fill(px);
0084 hpxpy->Fill(px,py);
0085 hprof->Fill(px,pz);
0086 }
0087
0088 pstmt->SetString(1,"hpx");
0089 pstmt->SetObject(2,hpx);
0090 pstmt->ExecuteUpdate();
0091
0092 pstmt->SetString(1,"hpxpy");
0093 pstmt->SetObject(2,hpxpy);
0094 pstmt->ExecuteUpdate();
0095
0096 pstmt->SetString(1,"hprof");
0097 pstmt->SetObject(2,hprof);
0098 pstmt->ExecuteUpdate();
0099
0100 con->Commit();
0101 delete pstmt;
0102 }
0103
0104
0105 void DropStuff(TSQLConnection* con)
0106 {
0107
0108
0109 TSQLStatement* stmt = con->CreateStatement();
0110 stmt->ExecuteUpdate("drop table " + tableName);
0111 printf("Dropped table %s\n",tableName.Data());
0112 delete stmt;
0113 }
0114
0115
0116 void Fill(TSQLConnection* con)
0117 {
0118
0119
0120 TString str;
0121
0122 TSQLStatement* stmt =
0123 con->CreateStatement(kTYPE_SCROLL_SENSITIVE, kCONCUR_UPDATABLE);
0124 if (!stmt) return;
0125
0126 con->Print("a");
0127
0128 TSQLResultSet* rs;
0129
0130 Float_t px, py, pz;
0131 int ii = 0;
0132
0133
0134 while (1)
0135 {
0136 gRandom->Rannor(px,py);
0137 pz = px*px + py*py;
0138 hpx->Fill(px);
0139 hpxpy->Fill(px,py);
0140 hprof->Fill(px,pz);
0141
0142 if ((ii % 1000) == 0)
0143 {
0144 rs = stmt->ExecuteQuery("select name, histos from "
0145 + tableName);
0146
0147 if (!rs) break;
0148
0149 while(rs->Next())
0150 {
0151 str = rs->GetString(1);
0152 if(str==hpx->GetName()) rs->UpdateObject(2,hpx);
0153 else if(str==hpxpy->GetName()) rs->UpdateObject(2,hpxpy);
0154 else if(str==hprof->GetName()) rs->UpdateObject(2,hprof);
0155 rs->UpdateRow();
0156 }
0157 con->Commit();
0158 delete rs;
0159 }
0160 ii++;
0161 }
0162 delete stmt;
0163 }
0164
0165
0166 Int_t oproducer( const Text_t* dsn,
0167 const Text_t* usr,
0168 const Text_t* pwd )
0169 {
0170
0171
0172 TSQLConnection* con;
0173 TString str;
0174
0175
0176 TSQL::SetHandler("Catch(TSQLException*)");
0177
0178 str = "dsn="; str += dsn;
0179 str += "; uid="; str += usr;
0180
0181
0182 con = gSQLDriverManager->GetConnection(str);
0183
0184 gSystem->Sleep(5000);
0185
0186 if(!con) return -1;
0187
0188 if( con->GetMetaData()->SupportsTransactions() ) {
0189 con->SetAutoCommit(kFALSE);
0190 }
0191
0192 TSQL::UnsetHandler();
0193
0194 TSQL::SetHandler("Catch(TSQLException*)");
0195 CreateStuff(con);
0196
0197 TSQL::UnsetHandler();
0198
0199 con->Commit();
0200 con->Close();
0201 return 0;
0202 }
0203
0204
0205 void Catch(TSQLException* e)
0206 {
0207
0208
0209 TString str = e->GetMessage();
0210 printf("%s\n",str.Data());
0211 }