source: trunk/MagicSoft/Mars/datacenter/macros/insertdate.C@ 7548

Last change on this file since 7548 was 7460, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 3.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2006
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// insertdate.C
28// ============
29//
30// This macro is inserting a date into the table SequenceBuildStatus.
31// It is executed by the script copyscript, which copies the slow control
32// data to the appropriate directory and inserts the information into the
33// database.
34//
35// Usage:
36// .x insertdate.C+("date")
37//
38// Make sure, that database and password are corretly set in a resource
39// file called sql.rc and the resource file is found.
40//
41// Returns 0 in case of failure and 1 in case of success.
42//
43/////////////////////////////////////////////////////////////////////////////
44
45#include <iostream>
46#include <iomanip>
47#include <fstream>
48
49#include <TEnv.h>
50
51#include <MSQLServer.h>
52#include <TSQLRow.h>
53#include <TSQLResult.h>
54
55using namespace std;
56
57Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
58{
59 TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
60
61 cout << "query: " << query << endl;
62
63 TSQLResult *res = serv.Query(query);
64 if (!res)
65 return kFALSE;
66
67 Bool_t rc = kFALSE;
68
69 TSQLRow *row=res->Next();
70 if (row && (*row)[0])
71 rc=kTRUE;
72
73 delete res;
74 return rc;
75}
76
77
78int insertdate(TString date)
79{
80 TEnv env("sql.rc");
81
82 MSQLServer serv(env);
83 if (!serv.IsConnected())
84 {
85 cout << "ERROR - Connection to database failed." << endl;
86 return 0;
87 }
88 cout << "insertdate" << endl;
89 cout << "----------" << endl;
90 cout << endl;
91 cout << "Connected to " << serv.GetName() << endl;
92 cout << endl;
93
94 //insert entry for date into the table SequenceBuildStatus,
95 // if entry is not yet existing
96 if (!ExistStr(serv, "fDate", "SequenceBuildStatus", date))
97 {
98 TString query(Form("INSERT SequenceBuildStatus SET fDate='%s', fCCFilled=Now() ",
99 date.Data()));
100
101 TSQLResult *res = serv.Query(query);
102 if (!res)
103 {
104 cout << "Error - could not insert entry" << endl;
105 return 0;
106 }
107 delete res;
108 }
109 else
110 {
111 cout << date << " already exists... do update. " << endl;
112
113 TString query="UPDATE SequenceBuildStatus SET fCCFilled=Now(), fExclusionsDone=NULL, ";
114 query +=Form("fSequenceEntriesBuilt=NULL WHERE fDate='%s' ", date.Data());
115
116 TSQLResult *res = serv.Query(query);
117 if (!res)
118 {
119 cout << "Error - could not update entry" << endl;
120 return 0;
121 }
122 delete res;
123 }
124
125 return 1;
126}
127
128
Note: See TracBrowser for help on using the repository browser.