#include "TList.h"
#include "TParameter.h"
#include "TEnv.h"
#include "TSQLMonitoring.h"
#include "TSQLServer.h"
#include "TSQLResult.h"
TSQLMonitoringWriter::TSQLMonitoringWriter(const char *serv, const char *user,
const char *pass, const char *table)
: TVirtualMonitoringWriter("SQL", 0.0), fTable(table)
{
fDB = TSQLServer::Connect(serv, user, pass);
if (!fDB || fDB->IsZombie()) {
SafeDelete(fDB);
MakeZombie();
}
}
TSQLMonitoringWriter::~TSQLMonitoringWriter()
{
SafeDelete(fDB);
}
Bool_t TSQLMonitoringWriter::SendParameters(TList *values, const char *)
{
if (!fDB) {
return kFALSE;
}
if (!values || values->GetSize() <= 1)
return kFALSE;
TIter nxi(values);
TString sql = Form("INSERT INTO %s", fTable.Data());
TObject *o = 0;
char c = '(';
TString cols, vals;
while ((o = nxi())) {
if (!strncmp(o->ClassName(), "TNamed", 6)) {
cols += Form("%c'%s'", c, ((TNamed *)o)->GetName());
vals += Form("%c'%s'", c, ((TNamed *)o)->GetTitle());
} else if (!strcmp(o->ClassName(), "TParameter<Long64_t>")) {
cols += Form(",'%s'", c, ((TParameter<Long64_t> *)o)->GetName());
vals += Form("%c%lld", c, ((TParameter<Long64_t> *)o)->GetVal());
} else if (!strcmp(o->ClassName(), "TParameter<double>")) {
cols += Form("%c'%s'", c, ((TParameter<double> *)o)->GetName());
vals += Form("%c%f", c, ((TParameter<double> *)o)->GetVal());
} else if (!strcmp(o->ClassName(), "TParameter<float>")) {
cols += Form("%c'%s'", c, ((TParameter<float> *)o)->GetName());
vals += Form("%c%f", c, ((TParameter<float> *)o)->GetVal());
} else if (!strcmp(o->ClassName(), "TParameter<int>")) {
cols += Form("%c'%s'", c, ((TParameter<int> *)o)->GetName());
vals += Form("%c%d", c, ((TParameter<int> *)o)->GetVal());
} else if (!strcmp(o->ClassName(), "TParameter<long>")) {
cols += Form("%c'%s'", c, ((TParameter<long> *)o)->GetName());
vals += Form("%c%ld", c, ((TParameter<long> *)o)->GetVal());
}
c = ',';
}
cols += ")";
vals += ")";
sql += Form(" %s VALUES %s", cols.Data(), vals.Data());
TSQLResult *res = fDB->Query(sql);
if (!res) {
Error("SendParameters", "insert into %s failed", fTable.Data());
printf("%s\n", sql.Data());
return kFALSE;
}
delete res;
return kTRUE;
}
Last change: Wed Jun 25 08:52:36 2008
Last generated: 2008-06-25 08:52
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.