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 | // fillsources.C
|
---|
28 | // ============
|
---|
29 | //
|
---|
30 | // Returns 0 in case of failure and 1 in case of success.
|
---|
31 | //
|
---|
32 | /////////////////////////////////////////////////////////////////////////////
|
---|
33 |
|
---|
34 | #include <iostream>
|
---|
35 | #include <iomanip>
|
---|
36 | #include <fstream>
|
---|
37 |
|
---|
38 | #include <TSQLRow.h>
|
---|
39 | #include <TSQLResult.h>
|
---|
40 |
|
---|
41 | #include "MSQLServer.h"
|
---|
42 |
|
---|
43 | using namespace std;
|
---|
44 |
|
---|
45 | Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
|
---|
46 | {
|
---|
47 | TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
|
---|
48 |
|
---|
49 | cout << "query: " << query << endl;
|
---|
50 |
|
---|
51 | TSQLResult *res = serv.Query(query);
|
---|
52 | if (!res)
|
---|
53 | return kFALSE;
|
---|
54 |
|
---|
55 | Bool_t rc = kFALSE;
|
---|
56 |
|
---|
57 | TSQLRow *row=res->Next();
|
---|
58 | if (row && (*row)[0])
|
---|
59 | rc=kTRUE;
|
---|
60 |
|
---|
61 | delete res;
|
---|
62 | return rc;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | int fillsources(TString catalog)
|
---|
67 | {
|
---|
68 | MSQLServer serv("sql.rc");
|
---|
69 | if (!serv.IsConnected())
|
---|
70 | {
|
---|
71 | cout << "ERROR - Connection to database failed." << endl;
|
---|
72 | return 0;
|
---|
73 | }
|
---|
74 | cout << "insertdate" << endl;
|
---|
75 | cout << "----------" << endl;
|
---|
76 | cout << endl;
|
---|
77 | cout << "Connected to " << serv.GetName() << endl;
|
---|
78 | cout << endl;
|
---|
79 |
|
---|
80 | TString source;
|
---|
81 | TString RA;
|
---|
82 | TString Dec;
|
---|
83 | TString waste;
|
---|
84 | ifstream fin(catalog);
|
---|
85 | if (!fin)
|
---|
86 | {
|
---|
87 | cout << "Could not open file " << catalog << endl;
|
---|
88 | return 0;
|
---|
89 | }
|
---|
90 |
|
---|
91 | while (1)
|
---|
92 | {
|
---|
93 | if (!fin)
|
---|
94 | break;
|
---|
95 |
|
---|
96 | source.ReadToDelim(fin, ',');
|
---|
97 | waste.ReadToDelim(fin, ',');
|
---|
98 | RA.ReadToDelim(fin, ',');
|
---|
99 | Dec.ReadToDelim(fin, ',');
|
---|
100 | waste.ReadToDelim(fin, '\n');
|
---|
101 |
|
---|
102 | cout << "source: " << source << endl;
|
---|
103 | cout << "RA: " << RA << endl;
|
---|
104 | cout << "Dec: " << Dec << endl;
|
---|
105 |
|
---|
106 | //insert entry for date into the table SequenceBuildStatus,
|
---|
107 | // if entry is not yet existing
|
---|
108 | if (!ExistStr(serv, "fSourceName", "Source", source))
|
---|
109 | {
|
---|
110 | TString query(Form("INSERT Source SET fSourceName='%s', fRightAscension='%s', fDeclination='%s' ",
|
---|
111 | source.Data(), RA.Data(), Dec.Data()));
|
---|
112 |
|
---|
113 | cout << "query: " << query << endl;
|
---|
114 | /*
|
---|
115 | TSQLResult *res = serv.Query(query);
|
---|
116 | if (!res)
|
---|
117 | {
|
---|
118 | cout << "Error - could not insert entry" << endl;
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 | delete res;
|
---|
122 | */
|
---|
123 | }
|
---|
124 | else
|
---|
125 | {
|
---|
126 | cout << source << " already exists... do update. " << endl;
|
---|
127 |
|
---|
128 | TString query(Form("Update Source SET fRightAscension='%s', fDeclination='%s' WHERE fSourceName='%s',",
|
---|
129 | RA.Data(), Dec.Data(), source.Data()));
|
---|
130 |
|
---|
131 | cout << "query: " << query << endl;
|
---|
132 | /*
|
---|
133 | TSQLResult *res = serv.Query(query);
|
---|
134 | if (!res)
|
---|
135 | {
|
---|
136 | cout << "Error - could not update entry" << endl;
|
---|
137 | return 0;
|
---|
138 | }
|
---|
139 | delete res;*/
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | return 1;
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|