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

Last change on this file since 7101 was 6933, checked in by Daniela Dorner, 20 years ago
*** empty log message ***
File size: 2.9 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-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// InsertDate.C
28// ============
29//
30/////////////////////////////////////////////////////////////////////////////
31
32#include <iostream>
33#include <iomanip>
34#include <fstream>
35
36#include <TEnv.h>
37
38#include <MSQLServer.h>
39#include <TSQLRow.h>
40#include <TSQLResult.h>
41
42using namespace std;
43
44Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
45{
46 TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
47
48 cout << "query: " << query << endl;
49
50 TSQLResult *res = serv.Query(query);
51 if (!res)
52 return kFALSE;
53
54 Bool_t rc = kFALSE;
55
56 TSQLRow *row=res->Next();
57 if (row && (*row)[0])
58 rc=kTRUE;
59
60 delete res;
61 return rc;
62}
63
64
65int insertdate(TString date)
66{
67 TEnv env("sql.rc");
68
69 MSQLServer serv(env);
70 if (!serv.IsConnected())
71 {
72 cout << "ERROR - Connection to database failed." << endl;
73 return 0;
74 }
75 cout << "insertdate" << endl;
76 cout << "----------" << endl;
77 cout << endl;
78 cout << "Connected to " << serv.GetName() << endl;
79 cout << endl;
80
81 if (!ExistStr(serv, "fDate", "MyMagic.SequenceBuildStatus", date))
82 {
83 TString query(Form("INSERT MyMagic.SequenceBuildStatus SET fDate='%s', fCCFilled=Now() ",
84 date.Data()));
85
86 TSQLResult *res = serv.Query(query);
87 if (!res)
88 {
89 cout << "Error - could not insert entry" << endl;
90 return 0;
91 }
92 delete res;
93 }
94 else
95 {
96 cout << date << " already exists... do update. " << endl;
97
98 TString query="UPDATE MyMagic.SequenceBuildStatus SET fCCFilled=Now(), fExclusionsDone=NULL, ";
99 query +=Form("fSequenceEntriesBuilt=NULL WHERE fDate='%s' ", date.Data());
100
101 TSQLResult *res = serv.Query(query);
102 if (!res)
103 {
104 cout << "Error - could not update entry" << endl;
105 return 0;
106 }
107 delete res;
108 }
109
110 return 1;
111}
112
113
Note: See TracBrowser for help on using the repository browser.