00001
00002
00003
00004
00005
00006
00007
00008
00009 const char* dbname = "mysql://host.domain/test";
00010 const char* username = "user";
00011 const char* userpass = "pass";
00012
00013
00014
00015
00016
00017
00018
00019 void sqltables()
00020 {
00021 tables_write();
00022 tables_read();
00023 }
00024
00025 void tables_write()
00026 {
00027
00028
00029 TSQLFile* f = new TSQLFile(dbname, "recreate", username, userpass);
00030 if (f->IsZombie()) { delete f; return; }
00031
00032
00033
00034 f->SetUseSuffixes(kFALSE);
00035 f->SetArrayLimit(1000);
00036 f->SetUseIndexes(1);
00037
00038
00039
00040
00041 TH1I* h1 = new TH1I("histo1","histo title", 1000, -4., 4.);
00042 h1->FillRandom("gaus",10000);
00043 h1->Write("histo");
00044 h1->SetDirectory(0);
00045
00046
00047
00048 TList* arr = new TList;
00049 for(Int_t n=0;n<10;n++) {
00050 TBox* b = new TBox(n*10,n*100,n*20,n*200);
00051 arr->Add(b, Form("option_%d_option",n));
00052 }
00053 arr->Write("list",TObject::kSingleKey);
00054
00055
00056 TClonesArray clones("TBox",10);
00057 for(int n=0;n<10;n++)
00058 new (clones[n]) TBox(n*10,n*100,n*20,n*200);
00059 clones.Write("clones",TObject::kSingleKey);
00060
00061
00062 delete f;
00063 }
00064
00065
00066 void tables_read()
00067 {
00068
00069 TSQLFile* f = new TSQLFile(dbname, "open", username, userpass);
00070 if (f->IsZombie()) { delete f; return; }
00071
00072
00073 f->ls();
00074
00075
00076 TH1* h1 = (TH1*) f->Get("histo");
00077 if (h1!=0) {
00078 h1->SetDirectory(0);
00079 h1->Draw();
00080 }
00081
00082
00083 TObject* obj = f->Get("list");
00084 cout << "Printout of TList object" << endl;
00085 if (obj!=0) obj->Print("*");
00086 delete obj;
00087
00088
00089 obj = f->Get("clones");
00090 cout << "Printout of TClonesArray object" << endl;
00091 if (obj!=0) obj->Print("*");
00092 delete obj;
00093
00094
00095 cout << "================ TBox QUERY ================ " << endl;
00096 cout << f->MakeSelectQuery(TBox::Class()) << endl;
00097 cout << "================ END of TBox QUERY ================ " << endl;
00098
00099 cout << "================== TH1I QUERY ================ " << endl;
00100 cout << f->MakeSelectQuery(TH1I::Class()) << endl;
00101 cout << "================ END of TH1I QUERY ================ " << endl;
00102
00103
00104 delete f;
00105 }