1 | // This macro is a macro to create the Magic Database.
|
---|
2 | // It is kept up to date, if any changes in the database are made.
|
---|
3 |
|
---|
4 | #include <iomanip.h>
|
---|
5 | /*
|
---|
6 | Statements
|
---|
7 |
|
---|
8 | SELECT [ DISTINCT ] * | LIST OF COLUMNS, FUNCTIONS, CONSTANTS
|
---|
9 | FROM LIST OF TABLES OR VIEWS
|
---|
10 | [ WHERE CONDITION(S) ]
|
---|
11 | [ ORDER BY ORDERING COLUMN(S) [ ASC | DESC ] ]
|
---|
12 | [ GROUP BY GROUPING COLUMN(S) ]
|
---|
13 | [ HAVING CONDITION(S) ]
|
---|
14 |
|
---|
15 | DELETE FROM TABLE NAME
|
---|
16 | [ WHERE CONDITION(S) ]
|
---|
17 |
|
---|
18 | INSERT INTO TABLE NAME
|
---|
19 | [ (COLUMN LIST) ]
|
---|
20 | VALUES (VALUE LIST)
|
---|
21 |
|
---|
22 | UPDATE TABLE NAME
|
---|
23 | SET COLUMN NAME = VALUE
|
---|
24 | [ WHERE CONDITION ]
|
---|
25 |
|
---|
26 | Functions
|
---|
27 |
|
---|
28 | Function Purpose
|
---|
29 | SUM Total of the values in a field.
|
---|
30 | AVG Average of the values in a field.
|
---|
31 | MIN Lowest value in a field.
|
---|
32 | MAX Highest value in a field.
|
---|
33 | COUNT Number of values in a field, not counting Null (blank) values.
|
---|
34 |
|
---|
35 | Predicates
|
---|
36 |
|
---|
37 | Predicate Description
|
---|
38 | BETWEEN ... AND Compares a value to a range formed by two values.
|
---|
39 | IN Determines whether a value exists in a list of values or a table.
|
---|
40 | LIKE Compares, in part or in whole, one value with another.
|
---|
41 | JOIN Joins two tables.
|
---|
42 |
|
---|
43 | Data Definition
|
---|
44 |
|
---|
45 | CREATE TABLE TABLE_NAME
|
---|
46 | ( COLUMN_NAME DATA_TYPE [(SIZE)] COLUMN_CONSTRAINT,
|
---|
47 | [, other column definitions,...]
|
---|
48 | [, primary key constraint]
|
---|
49 | )
|
---|
50 |
|
---|
51 | ALTER TABLE TABLE_NAME ADD | DROP | MODIFY
|
---|
52 | ( COLUMN_NAME DATA_TYPE [(SIZE)] COLUMN_CONSTRAINT,
|
---|
53 | [, other column definitions,...]
|
---|
54 | )
|
---|
55 |
|
---|
56 | DROP TABLE TABLE_NAME
|
---|
57 |
|
---|
58 | CREATE [UNIQUE] [ASC | DESC] INDEX INDEX_NAME
|
---|
59 | ON TABLE_NAME ( COLUMN_LIST )
|
---|
60 |
|
---|
61 | DROP INDEX INDEX_NAME ON TABLE_NAME
|
---|
62 |
|
---|
63 | CREATE VIEW VIEW_NAME AS QUERY_NAME
|
---|
64 |
|
---|
65 | CONSTRAINT CONSTRAINT_NAME
|
---|
66 | {PRIMARY KEY | UNIQUE | NOT NULL |
|
---|
67 | REFERENCES FOREIGN_TABLE [(FIELD_LIST)]}
|
---|
68 |
|
---|
69 | */
|
---|
70 |
|
---|
71 | void Line(const TArrayI &max)
|
---|
72 | {
|
---|
73 | cout << "+" << setfill('-');
|
---|
74 | for (int i=0; i<max.GetSize(); i++)
|
---|
75 | cout << setw(max[i]+1) << "-" << "-+";
|
---|
76 | cout << endl;
|
---|
77 | }
|
---|
78 |
|
---|
79 | void Print(TSQLResult *res)
|
---|
80 | {
|
---|
81 | Int_t n = res->GetFieldCount();
|
---|
82 |
|
---|
83 | TArrayI max(n);
|
---|
84 |
|
---|
85 | for (int i=0; i<n; i++)
|
---|
86 | max[i] = strlen(res->GetFieldName(i));
|
---|
87 |
|
---|
88 | TSQLRow *row;
|
---|
89 |
|
---|
90 | TList rows;
|
---|
91 | while (row=res->Next())
|
---|
92 | {
|
---|
93 | for (int i=0; i<n; i++)
|
---|
94 | max[i] = TMath::Max(max[i], row->GetFieldLength(i));
|
---|
95 | rows.Add(row);
|
---|
96 | }
|
---|
97 |
|
---|
98 | Line(max);
|
---|
99 |
|
---|
100 | cout << "|" << setfill(' ');
|
---|
101 | for (int i=0; i<n; i++)
|
---|
102 | cout << setw(max[i]+1) << res->GetFieldName(i) << " |";
|
---|
103 | cout << endl;
|
---|
104 |
|
---|
105 | Line(max);
|
---|
106 |
|
---|
107 | cout << setfill(' ');
|
---|
108 | TIter Next(&rows);
|
---|
109 | while (row=(TSQLRow*)Next())
|
---|
110 | {
|
---|
111 | cout << "|";
|
---|
112 | for (int i=0; i<n; i++)
|
---|
113 | {
|
---|
114 | char *c = (*row)[i];
|
---|
115 | cout << setw(max[i]+1) << (c?c:"") << " |";
|
---|
116 | }
|
---|
117 | cout << endl;
|
---|
118 | }
|
---|
119 |
|
---|
120 | Line(max);
|
---|
121 | }
|
---|
122 |
|
---|
123 | TString GetFields(TSQLServer *serv, const char *db, const char *table)
|
---|
124 | {
|
---|
125 | res = serv->GetColumns(db, table);
|
---|
126 | if (!res)
|
---|
127 | return "";
|
---|
128 |
|
---|
129 | TString fields;
|
---|
130 |
|
---|
131 | TList rows;
|
---|
132 | while (row=res->Next())
|
---|
133 | rows.Add(row);
|
---|
134 |
|
---|
135 | TIter Next(&rows);
|
---|
136 | while (row=(TSQLRow*)Next())
|
---|
137 | {
|
---|
138 | fields += (*row)[0];
|
---|
139 | if (row!=rows.Last())
|
---|
140 | fields += ", ";
|
---|
141 | }
|
---|
142 |
|
---|
143 | return fields;
|
---|
144 | }
|
---|
145 |
|
---|
146 | void PrintContents(TSQLServer *serv, const char *db, const char *table)
|
---|
147 | {
|
---|
148 | TString fields=GetFields(serv, db, table);
|
---|
149 |
|
---|
150 | TSQLResult *res = serv->Query(Form("SELECT %s FROM %s", fields.Data(), table));
|
---|
151 | if (res)
|
---|
152 | {
|
---|
153 | Print(res);
|
---|
154 | delete res;
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | /*
|
---|
159 | GetTables(db):
|
---|
160 | \u "db"
|
---|
161 | SHOW TABLES;
|
---|
162 |
|
---|
163 | GetDataBases();
|
---|
164 | SHOW DATABASES;
|
---|
165 |
|
---|
166 | GetColumns(db, table);
|
---|
167 | EXPLAIN table;
|
---|
168 | DESCRIBE table;
|
---|
169 |
|
---|
170 | SHOW VARIABLES;
|
---|
171 |
|
---|
172 | PRIMARY_KEY impliziert NOT NULL
|
---|
173 |
|
---|
174 | */
|
---|
175 |
|
---|
176 | void CreatePrimaryEntries()
|
---|
177 | {
|
---|
178 | TList list;
|
---|
179 | list.SetOwner();
|
---|
180 |
|
---|
181 | // Trigger tables
|
---|
182 | list.Add(new TObjString(
|
---|
183 | "INSERT MyMagic.L1TriggerTable (fL1TriggerTableKEY, fL1TriggerTableName, fL1TriggerTable) VALUES "
|
---|
184 | " (1, 'n/a', 'Not available')"));
|
---|
185 |
|
---|
186 | list.Add(new TObjString(
|
---|
187 | "INSERT MyMagic.L2TriggerTable (fL2TriggerTableKEY, fL2TriggerTableName, fL2TriggerTable) VALUES "
|
---|
188 | " (1, 'n/a', 'Not available')"));
|
---|
189 |
|
---|
190 | // File path
|
---|
191 | list.Add(new TObjString(
|
---|
192 | "INSERT MyMagic.FilePath (fFilePathName, fFilePath) VALUES "
|
---|
193 | " ('n/a', 'Not available in the Data Center')"));
|
---|
194 |
|
---|
195 | // Magic number
|
---|
196 | list.Add(new TObjString(
|
---|
197 | "INSERT MyMagic.MagicNumber (fMagicNumber, fMagicNumberName) VALUES "
|
---|
198 | " (0x0001, 'Not available')," //1
|
---|
199 | " (0xc0c0, 'Ok')," //45344
|
---|
200 | " (0xc0c1, 'Not closed')," //45345
|
---|
201 | " (0x0000, 'Wrong')")); //0
|
---|
202 |
|
---|
203 | // Run type
|
---|
204 | list.Add(new TObjString(
|
---|
205 | "INSERT MyMagic.RunType (fRunType, fRunTypeName) VALUES "
|
---|
206 | " (0xffff, 'Not available'),"
|
---|
207 | " (0x0000, 'Data'),"
|
---|
208 | " (0x0001, 'Pedestal'),"
|
---|
209 | " (0x0002, 'Calibration'),"
|
---|
210 | " (0x0007, 'Point Run'),"
|
---|
211 | " (0x0100, 'Monte Carlo')"));
|
---|
212 |
|
---|
213 | // HvSettings
|
---|
214 | list.Add(new TObjString(
|
---|
215 | "INSERT MyMagic.HvSettings (fHvSettingsKEY, fHvSettingsName, fHvSettings) VALUES "
|
---|
216 | " (1, 'n/a', 'Not available')"));
|
---|
217 |
|
---|
218 | //Excluded From DataAnalysis
|
---|
219 | list.Add(new TObjString(
|
---|
220 | "INSERT MyMagic.ExcludedFDA (fExcludedFDAKEY, fExcludedFDAName, fExcludedFDA) VALUES "
|
---|
221 | " (1, \"Not excluded\", \"Not excluded from Data Analysis\")"));
|
---|
222 |
|
---|
223 | //Manually Changed
|
---|
224 | list.Add(new TObjString(
|
---|
225 | "INSERT MyMagic.ManuallyChanged (fManuallyChangedKEY, fManuallyChangedName, fManuallyChanged) VALUES "
|
---|
226 | " (1, \"Automatic\", \"This entry was created automatically without user intervention\")");
|
---|
227 |
|
---|
228 | // Source type
|
---|
229 | list.Add(new TObjString(
|
---|
230 | "INSERT MyMagic.SourceType (fSourceTypeName) VALUES ('Unknown')"));
|
---|
231 |
|
---|
232 | // LightConditions
|
---|
233 | list.Add(new TObjString(
|
---|
234 | "INSERT MyMagic.LightConditions (fLightConditionsKEY, fLightConditionsName, fLightConditions) VALUES "
|
---|
235 | " (1, 'n/a', 'Light conditions are not available')"));
|
---|
236 |
|
---|
237 | // Testflag
|
---|
238 | list.Add(new TObjString(
|
---|
239 | "INSERT MyMagic.TestFlag (fTestFlagKEY, fTestFlagName, fTestFlag) VALUES "
|
---|
240 | " (1, 'n/a', 'Testflag is not available')"));
|
---|
241 |
|
---|
242 | // Trigger delay table
|
---|
243 | list.Add(new TObjString(
|
---|
244 | "INSERT MyMagic.TriggerDelayTable (fTriggerDelayTableKEY, fTriggerDelayTableName, fTriggerDelayTable) VALUES "
|
---|
245 | " (1, 'n/a', 'Trigger delay table is not available')"));
|
---|
246 |
|
---|
247 | // Calibration script
|
---|
248 | list.Add(new TObjString(
|
---|
249 | "INSERT MyMagic.CalibrationScript (fCalibrationScriptKEY, fCalibrationScriptName, fCalibrationScript) VALUES "
|
---|
250 | " (1, 'n/a', 'Calibration script is not available')"));
|
---|
251 |
|
---|
252 | // discriminator threshold table
|
---|
253 | list.Add(new TObjString(
|
---|
254 | "INSERT MyMagic.DiscriminatorThresholdTable (fDiscriminatorThresholdTableKEY, fDiscriminatorThresholdTableName, fDiscriminatorThresholdTable) VALUES "
|
---|
255 | " (1, 'n/a', 'Discriminator threshold table is not available')"));
|
---|
256 |
|
---|
257 | // Observation Mode
|
---|
258 | list.Add(new TObjString(
|
---|
259 | "INSERT MyMagic.ObservationMode (fObservationModeKEY, fObservationModeName, fObservationMode) VALUES "
|
---|
260 | " (1, 'n/a', 'Not available')"));
|
---|
261 |
|
---|
262 |
|
---|
263 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
264 | if (!serv)
|
---|
265 | return;
|
---|
266 |
|
---|
267 | TIter Next(&list);
|
---|
268 | TObjString *str;
|
---|
269 |
|
---|
270 | cout << "Filling tables..." << endl;
|
---|
271 |
|
---|
272 | while ((str=(TObjString*)Next()))
|
---|
273 | {
|
---|
274 | TString q(str->GetString());
|
---|
275 |
|
---|
276 | Int_t f = q.First('(');
|
---|
277 | TString out = q(0, f);
|
---|
278 | cout << " - " << out << "... " << flush;
|
---|
279 | TSQLResult *res = serv->Query(q);
|
---|
280 | cout << (res==0 ? "ERROR!" : "Ok.") << endl;
|
---|
281 | if (res)
|
---|
282 | delete res;
|
---|
283 | }
|
---|
284 |
|
---|
285 | serv->Close();
|
---|
286 | delete serv;
|
---|
287 | }
|
---|
288 |
|
---|
289 | TObjString *CreateKeyTable(TString name)
|
---|
290 | {
|
---|
291 | return new TObjString(Form(
|
---|
292 | "CREATE TABLE MyMagic.%s ("
|
---|
293 | " f%sKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
294 | " f%sName VARCHAR(255) NOT NULL UNIQUE,"
|
---|
295 | " f%s VARCHAR(255) NULL"
|
---|
296 | ") MAX_ROWS=65536", name.Data(), name.Data(), name.Data(), name.Data()));
|
---|
297 | }
|
---|
298 |
|
---|
299 | void CreateMagicDataBase()
|
---|
300 | {
|
---|
301 | TList list;
|
---|
302 | list.SetOwner();
|
---|
303 |
|
---|
304 | TString query =
|
---|
305 | "CREATE TABLE MyMagic.RunData"
|
---|
306 | "("
|
---|
307 | " fRunDataKEY INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,"// COMMENT('The unique key for each run-file'),";
|
---|
308 | " fRunNumber INT UNSIGNED NOT NULL UNIQUE," // PACK_KEYS=1,";// COMMENT('Run number'),";
|
---|
309 | " fMagicNumberKEY TINYINT UNSIGNED NOT NULL," // PACK_KEYS=1,";// COMMENT('The MAGIC Key (first two bytes of a raw data file)'),";
|
---|
310 | " fFormatVersion SMALLINT UNSIGNED NOT NULL," // PACK_KEYS=1,";// COMMENT('File format version of the raw data file)'),";
|
---|
311 | " fRunTypeKEY TINYINT UNSIGNED NOT NULL," // PACK_KEYS=1,";// COMMENT('Run type'),";
|
---|
312 | " fProjectKEY SMALLINT UNSIGNED NOT NULL," // PACK_KEYS=1,";// COMMENT('Name of the project (assigned by the physics comittee)'),";
|
---|
313 | " fSourceKEY SMALLINT UNSIGNED NOT NULL," // PACK_KEYS=1,";// COMMENT('Name of the source observed'),";
|
---|
314 | " fNumEvents MEDIUMINT UNSIGNED NOT NULL," // COMMENT('Number of events in this run-file'),";
|
---|
315 | " fRunStart DATETIME NOT NULL," // COMMENT('Time when the run was started'),";
|
---|
316 | " fRunStop DATETIME NULL,"; // COMMENT('Time when the run has stopped')";
|
---|
317 | query +=
|
---|
318 | " fZenithDistance TINYINT NULL," // COMMENT('Time of last change'),";
|
---|
319 | " fAzimuth SMALLINT NULL," // COMMENT('Time of last change'),";
|
---|
320 | " fL1TriggerTableKEY SMALLINT UNSIGNED NOT NULL," // COMMENT('Time of last change'),";
|
---|
321 | " fL2TriggerTableKEY SMALLINT UNSIGNED NOT NULL," // COMMENT('Time of last change'),";
|
---|
322 | " fHvSettingsKEY SMALLINT UNSIGNED NOT NULL," // COMMENT('Time of last change'),";
|
---|
323 | " fDaqStoreRate SMALLINT UNSIGNED NULL," // COMMENT('Time of last change'),";
|
---|
324 | " fDaqTriggerRate SMALLINT UNSIGNED NULL," // COMMENT('Time of last change'),";
|
---|
325 | " fMeanTriggerRate SMALLINT UNSIGNED NULL," // COMMENT('Time of last change'),";
|
---|
326 | " fL2RatePresc SMALLINT UNSIGNED NULL," // COMMENT('Time of last change'),";
|
---|
327 | " fL2RateUnpresc SMALLINT UNSIGNED NULL," // COMMENT('Time of last change'),";
|
---|
328 | " fExcludedFDAKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
329 | " fSequenceFirst INT UNSIGNED NOT NULL,";
|
---|
330 | query +=
|
---|
331 | " fLastUpdate TIMESTAMP" // COMMENT('Time of last change'),";
|
---|
332 | " fTestFlagKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
333 | " fLightConditionsKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
334 | " fCalibrationScriptKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
335 | " fDiscriminatorThresholdTableKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
336 | " fTriggerDelayTableKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
337 | " fObservationModeKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
338 | ")";
|
---|
339 |
|
---|
340 | list.Add(new TObjString(query));
|
---|
341 |
|
---|
342 | list.Add(new TObjString(
|
---|
343 | "CREATE TABLE MyMagic.RunType ("
|
---|
344 | " fRunTypeKEY TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
345 | " fRunType SMALLINT UNSIGNED NOT NULL UNIQUE,"
|
---|
346 | " fRunTypeName VARCHAR(255) NOT NULL UNIQUE,"
|
---|
347 | ") MAX_ROWS=256"));
|
---|
348 |
|
---|
349 | list.Add(new TObjString(
|
---|
350 | "CREATE TABLE MyMagic.MagicNumber ("
|
---|
351 | " fMagicNumberKEY TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
352 | " fMagicNumber SMALLINT UNSIGNED NOT NULL UNIQUE,"
|
---|
353 | " fMagicNumberName VARCHAR(255) NOT NULL UNIQUE"
|
---|
354 | ") MAX_ROWS=256"));
|
---|
355 |
|
---|
356 | list.Add(new TObjString(
|
---|
357 | "CREATE TABLE MyMagic.Project ("
|
---|
358 | " fProjectKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
359 | " fProjectName CHAR(22) NOT NULL UNIQUE,"
|
---|
360 | " fProject VARCHAR(255) NOT NULL"
|
---|
361 | ") MAX_ROWS=65536"));
|
---|
362 |
|
---|
363 | list.Add(new TObjString(
|
---|
364 | "CREATE TABLE MyMagic.Source ("
|
---|
365 | " fSourceKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
366 | " fSourceName CHAR(12) NOT NULL UNIQUE,"
|
---|
367 | " fSourceTypeKEY SMALLINT UNSIGNED NULL,"
|
---|
368 | " fRightAscension DOUBLE NULL,"
|
---|
369 | " fDeclination DOUBLE NULL,"
|
---|
370 | " fEpochChar CHAR NULL,"// DEFAULT='J'
|
---|
371 | " fEpochDate SMALLINT(4) UNSIGNED NULL,"// DEFAULT=2000
|
---|
372 | " fMagnitude SMALLINT NULL," // 82=8.2
|
---|
373 | " fTest ENUM(\"no\",\"yes\") NOT NULL" //default no
|
---|
374 | ") MAX_ROWS=65536"));
|
---|
375 |
|
---|
376 | list.Add(new TObjString(
|
---|
377 | "CREATE TABLE MyMagic.SourceType ("
|
---|
378 | " fSourceTypeKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
379 | " fSourceTypeName VARCHAR(255) NOT NULL UNIQUE"
|
---|
380 | ") MAX_ROWS=65536"));
|
---|
381 |
|
---|
382 | list.Add(new TObjString(
|
---|
383 | "CREATE TABLE MyMagic.Files ("
|
---|
384 | " fRawFileKEY INT UNSIGNED NOT NULL PRIMARY KEY,"
|
---|
385 | " fRepFileKEY INT UNSIGNED NULL UNIQUE,"
|
---|
386 | " fDccFileKEY INT UNSIGNED NULL UNIQUE"
|
---|
387 | ")"));
|
---|
388 |
|
---|
389 | list.Add(new TObjString(
|
---|
390 | "CREATE TABLE MyMagic.RawFile ("
|
---|
391 | " fRawFileKEY INT UNSIGNED PRIMARY KEY,"
|
---|
392 | " fRawFileName VARCHAR(64) NOT NULL UNIQUE," // NULL means - Not in Wuerzburg!
|
---|
393 | " fFilePathKEY SMALLINT UNSIGNED NOT NULL"
|
---|
394 | ")"));
|
---|
395 |
|
---|
396 | list.Add(new TObjString(
|
---|
397 | "CREATE TABLE MyMagic.RepFile ("
|
---|
398 | " fRepFileKEY INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
399 | " fRepFileName VARCHAR(64) NOT NULL UNIQUE," // NULL means - Not in Wuerzburg!
|
---|
400 | " fFilePathKEY SMALLINT UNSIGNED NOT NULL"
|
---|
401 | ")"));
|
---|
402 |
|
---|
403 | list.Add(new TObjString(
|
---|
404 | "CREATE TABLE MyMagic.DccFile ("
|
---|
405 | " fDccFileKEY INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
406 | " fDccFileName VARCHAR(64) NOT NULL UNIQUE," // NULL means - Not in Wuerzburg!
|
---|
407 | " fFilePathKEY SMALLINT UNSIGNED NOT NULL"
|
---|
408 | ")"));
|
---|
409 |
|
---|
410 | list.Add(new TObjString(
|
---|
411 | "CREATE TABLE MyMagic.FilePath ("
|
---|
412 | " fFilePathKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
413 | " fFilePathName VARCHAR(255) NOT NULL UNIQUE,"
|
---|
414 | " fFilePath VARCHAR(255) NOT NULL UNIQUE"
|
---|
415 | ") MAX_ROWS=65536"));
|
---|
416 |
|
---|
417 | list.Add(CreateKeyTable("L1TriggerTable"));
|
---|
418 | list.Add(CreateKeyTable("L2TriggerTable"));
|
---|
419 | list.Add(CreateKeyTable("HvSettings"));
|
---|
420 | // list.Add(CreateKeyTable("ExcludedFDA"));
|
---|
421 | list.Add(CreateKeyTable("ManuallyChanged"));
|
---|
422 | list.Add(CreateKeyTable("TestFlag"));
|
---|
423 | list.Add(CreateKeyTable("LightConditions"));
|
---|
424 | list.Add(CreateKeyTable("CalibrationScript"));
|
---|
425 | list.Add(CreateKeyTable("DiscriminatorThresholdTable"));
|
---|
426 | list.Add(CreateKeyTable("TriggerDelayTable"));
|
---|
427 | list.Add(CreateKeyTable("ObservationMode"));
|
---|
428 |
|
---|
429 | list.Add(new TObjString(
|
---|
430 | "CREATE TABLE MyMagic.ExcludedFDA ("
|
---|
431 | " fExcludedFDAKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
432 | " fExcludedFDAImportance SMALLINT UNSIGNED NULL,"
|
---|
433 | " fExcludedFDAAutomatic ENUM(\"yes\",\"no\") NULL,"
|
---|
434 | " fExcludedFDAName VARCHAR(255) NOT NULL UNIQUE,"
|
---|
435 | " fExcludedFDA VARCHAR(255) NULL"
|
---|
436 | ") MAX_ROWS=65536"));
|
---|
437 |
|
---|
438 |
|
---|
439 | list.Add(new TObjString(
|
---|
440 | "CREATE TABLE MyMagic.DataCheck ("
|
---|
441 | " fRunNumber INT UNSIGNED PRIMARY KEY,"
|
---|
442 | " fEvents INT UNSIGNED NULL,"
|
---|
443 | " fPositionSignal TINYINT UNSIGNED NULL,"
|
---|
444 | " fPositionFWHM TINYINT UNSIGNED NULL,"
|
---|
445 | " fHeightSignal SMALLINT UNSIGNED NULL,"
|
---|
446 | " fHeightFWHM SMALLINT UNSIGNED NULL,"
|
---|
447 | " fHasSignal ENUM(\"yes\",\"no\") NULL,"
|
---|
448 | " fHasPedestal ENUM(\"yes\",\"no\") NULL,"
|
---|
449 | " fPositionAsym ENUM(\"yes\",\"no\") NULL,"
|
---|
450 | " fHeightAsym ENUM(\"yes\",\"no\") NULL,"
|
---|
451 | " fEventsInterlaced INT UNSIGNED NULL,"
|
---|
452 | " fPositionSignalInterlaced TINYINT UNSIGNED NULL,"
|
---|
453 | " fPositionFWHMInterlaced TINYINT UNSIGNED NULL,"
|
---|
454 | " fHeightSignalInterlaced SMALLINT UNSIGNED NULL,"
|
---|
455 | " fHeightFWHMInterlaced SMALLINT UNSIGNED NULL,"
|
---|
456 | " fHasSignalInterlaced ENUM(\"yes\",\"no\") NULL,"
|
---|
457 | " fHasPedestalInterlaced ENUM(\"yes\",\"no\") NULL,"
|
---|
458 | " fPositionAsymInterlaced ENUM(\"yes\",\"no\") NULL,"
|
---|
459 | " fHeightAsymInterlaced ENUM(\"yes\",\"no\") NULL"
|
---|
460 | ")"));
|
---|
461 |
|
---|
462 |
|
---|
463 | /*
|
---|
464 | list.Add(new TObjString(
|
---|
465 | "CREATE TABLE MyMagic.TriggerTable ("
|
---|
466 | " fTriggerTableKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
467 | " fTriggerTableName VARCHAR(255) NOT NULL UNIQUE,"
|
---|
468 | " fTriggerTable VARCHAR(255) NULL"
|
---|
469 | ") MAX_ROWS=65536"));
|
---|
470 |
|
---|
471 | list.Add(new TObjString(
|
---|
472 | "CREATE TABLE MyMagic.HvSettings ("
|
---|
473 | " fHvSettingsKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
474 | " fHvSettingsName VARCHAR(255) NOT NULL UNIQUE,"
|
---|
475 | " fHvSettings VARCHAR(255) NULL"
|
---|
476 | ") MAX_ROWS=65536"));
|
---|
477 |
|
---|
478 | list.Add(new TObjString(
|
---|
479 | "CREATE TABLE MyMagic.ExcludedFDA ("
|
---|
480 | " fExcludedFDAKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
481 | " fExcludedFDAName VARCHAR(255) NOT NULL UNIQUE,"
|
---|
482 | " fExcludedFDA VARCHAR(255) NULL"
|
---|
483 | ") MAX_ROWS=65536"));
|
---|
484 |
|
---|
485 | list.Add(new TObjString(
|
---|
486 | "CREATE TABLE MyMagic.ManuallyChanged ("
|
---|
487 | " fManuallyChangedKEY SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
488 | " fManuallyChangedName VARCHAR(255) NOT NULL UNIQUE,"
|
---|
489 | " fManuallyChanged VARCHAR(255) NULL"
|
---|
490 | ") MAX_ROWS=65536"));
|
---|
491 | */
|
---|
492 | list.Add(new TObjString(
|
---|
493 | "CREATE TABLE MyMagic.Changes ("
|
---|
494 | " fChangesKEY INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
495 | " fTimeStamp TIMESTAMP,"
|
---|
496 | " fTableName VARCHAR(64) NOT NULL,"
|
---|
497 | " fRowKEY INT UNSIGNED NOT NULL,"
|
---|
498 | " fColumnName VARCHAR(64) NOT NULL,"
|
---|
499 | " fDescription VARCHAR(255) NOT NULL"
|
---|
500 | ")"));
|
---|
501 |
|
---|
502 | list.Add(new TObjString(
|
---|
503 | "CREATE TABLE MyMagic.Comments ("
|
---|
504 | " fCommentsKEY INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
505 | " fCommentsName VARCHAR(255) NOT NULL,",
|
---|
506 | " fRunDataKEY INT UNSIGNED NOT NULL"
|
---|
507 | ")"));
|
---|
508 |
|
---|
509 | list.Add(new TObjString(
|
---|
510 | "CREATE TABLE MyMagic.RunBook ("
|
---|
511 | " fRunBookKEY INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
512 | " fRunBookDate DATETIME NOT NULL,",
|
---|
513 | " fRunBookText TEXT NOT NULL"
|
---|
514 | ")"));
|
---|
515 |
|
---|
516 | list.Add(new TObjString(
|
---|
517 | "CREATE TABLE MyMagic.Sequences ("
|
---|
518 | " fSequenceFirst INT UNSIGNED PRIMARY KEY, "
|
---|
519 | " fSequenceLast INT UNSIGNED NOT NULL UNIQUE, "
|
---|
520 | " fProjectKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
521 | " fSourceKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
522 | " fNumEvents MEDIUMINT UNSIGNED NOT NULL,"
|
---|
523 | " fRunTime SMALLINT UNSIGNED NOT NULL,"
|
---|
524 | " fRunStart DATETIME NOT NULL,"
|
---|
525 | " fZenithDistanceMin TINYINT NULL,"
|
---|
526 | " fZenithDistanceMax TINYINT NULL,"
|
---|
527 | " fAzimuthMin SMALLINT NULL,"
|
---|
528 | " fAzimuthMax SMALLINT NULL,"
|
---|
529 | " fL1TriggerTableKEY SMALLINT UNSIGNED NOT NULL,";
|
---|
530 | query +=
|
---|
531 | " fL2TriggerTableKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
532 | " fHvSettingsKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
533 | " fManuallyChanged SMALLINT UNSIGNED NOT NULL,"
|
---|
534 | " fLastUpdate TIMESTAMP" // COMMENT('Time of last change'),";
|
---|
535 | " fTestFlagKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
536 | " fLightConditionsKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
537 | " fDiscriminatorThresholdTableKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
538 | " fTriggerDelayTableKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
539 | " fObservationModeKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
540 | ")";
|
---|
541 |
|
---|
542 | list.Add(new TObjString(
|
---|
543 | "CREATE TABLE MyMagic.Calibration ("
|
---|
544 | " fSequenceFirst INT UNSIGNED PRIMARY KEY, "
|
---|
545 | " fUnsuitableInner SMALLINT UNSIGNED NOT NULL, "
|
---|
546 | " fUnsuitableOuter SMALLINT UNSIGNED NOT NULL, "
|
---|
547 | " fUnreliableInner SMALLINT UNSIGNED NOT NULL,"
|
---|
548 | " fUnreliableOuter SMALLINT UNSIGNED NOT NULL,"
|
---|
549 | " fIsolatedInner SMALLINT UNSIGNED NOT NULL,"
|
---|
550 | " fIsolatedOuter SMALLINT UNSIGNED NOT NULL,"
|
---|
551 | " fIsolatedMaxCluster SMALLINT UNSIGNED NOT NULL,"
|
---|
552 | " fMeanPedRmsInner FLOAT(6,2) NOT NULL,"
|
---|
553 | " fMeanPedRmsOuter FLOAT(6,2) NOT NULL,"
|
---|
554 | " fMeanSignalInner FLOAT(6,2) NOT NULL,"
|
---|
555 | " fMeanSignalOuter FLOAT(6,2) NOT NULL,"
|
---|
556 | " fArrTimeMeanInner FLOAT(5,1) NOT NULL,"
|
---|
557 | " fArrTimeRmsInner FLOAT(6,2) NOT NULL,"
|
---|
558 | " fArrTimeMeanOuter FLOAT(5,1) NOT NULL,"
|
---|
559 | " fArrTimeRmsOuter FLOAT(6,2) NOT NULL,"
|
---|
560 | " fConvFactorInner FLOAT(6,3) NOT NULL,"
|
---|
561 | " fConvFactorOuter FLOAT(6,3) NOT NULL,"
|
---|
562 | " fPulsePosMean FLOAT(6,2) NOT NULL,"
|
---|
563 | " fPulsePosRms FLOAT(6,2) NOT NULL,"
|
---|
564 | " fPulsePosCheckMean FLOAT(6,2) NULL,"
|
---|
565 | " fPulsePosCheckRms FLOAT(6,2) NULL,"
|
---|
566 | " fLastUpdate TIMESTAMP"
|
---|
567 | ")"));
|
---|
568 |
|
---|
569 | list.Add(new TObjString(
|
---|
570 | "CREATE TABLE MyMagic.Star ("
|
---|
571 | " fSequenceFirst INT UNSIGNED PRIMARY KEY, "
|
---|
572 | " fMeanNumberIslands FLOAT(6,2) NOT NULL,"
|
---|
573 | " fPSF FLOAT(5,1) NOT NULL,"
|
---|
574 | " fRatio FLOAT(5,1) NOT NULL,"
|
---|
575 | " fMuonRate FLOAT(6,2) NOT NULL,"
|
---|
576 | " fMuonNumber INT UNSIGNED NOT NULL,"
|
---|
577 | " fEffOnTime INT UNSIGNED NOT NULL,"
|
---|
578 | " fDataRate INT UNSIGNED NOT NULL,"
|
---|
579 | " fMaxHumidity FLOAT(6,1) NOT NULL,"
|
---|
580 | " fInhomogeneity FLOAT(5,1) NOT NULL,"
|
---|
581 | " fNumStarsMean FLOAT(5,1) NOT NULL,"
|
---|
582 | " fNumStarsRMS FLOAT(5,1) NOT NULL,"
|
---|
583 | " fBrightnessMean FLOAT(5,1) NOT NULL,"
|
---|
584 | " fBrightnessRMS FLOAT(5,1) NOT NULL,"
|
---|
585 | " fLastUpdate TIMESTAMP"
|
---|
586 | ")"));
|
---|
587 |
|
---|
588 | list.Add(new TObjString(
|
---|
589 | "CREATE TABLE MyMagic.DataSets ("
|
---|
590 | " fDataSetNumber INT UNSIGNED PRIMARY KEY, "
|
---|
591 | " fSourceKEY SMALLINT UNSIGNED NOT NULL,"
|
---|
592 | " fWobble ENUM('Y','N') NULL,"
|
---|
593 | " fComment VARCHAR(255) NULL,"
|
---|
594 | " fLastUpdate TIMESTAMP"
|
---|
595 | ")"));
|
---|
596 |
|
---|
597 | list.Add(new TObjString(
|
---|
598 | "CREATE TABLE MyMagic.Ganymed ("
|
---|
599 | " fDataSetNumber INT UNSIGNED PRIMARY KEY, "
|
---|
600 | " fExcessEvents INT UNSIGNED NOT NULL,"
|
---|
601 | " fBackgroundEvents INT UNSIGNED NOT NULL,"
|
---|
602 | " fSignalEvents INT UNSIGNED NOT NULL,"
|
---|
603 | " fEffOnTime INT UNSIGNED NOT NULL,"
|
---|
604 | " fSignificance FLOAT(5,1) NOT NULL,"
|
---|
605 | " fScaleFactor FLOAT(5,2) NOT NULL,"
|
---|
606 | " fStandard ENUM(\"no\",\"yes\") NOT NULL," //default no
|
---|
607 | " fLastUpdate TIMESTAMP"
|
---|
608 | ")"));
|
---|
609 |
|
---|
610 | list.Add(new TObjString(
|
---|
611 | "CREATE TABLE MyMagic.DataSetProcessStatus ("
|
---|
612 | " fDataSetNumber INT UNSIGNED PRIMARY KEY, "
|
---|
613 | " fDataSetInserted DATETIME NULL,"
|
---|
614 | " fStarFilesAvail DATETIME NULL,"
|
---|
615 | " fGanymed DATETIME NULL,"
|
---|
616 | " fFillGanymed DATETIME NULL,"
|
---|
617 | " fStartTime DATETIME NULL,"
|
---|
618 | " fFailedTime DATETIME NULL,"
|
---|
619 | " fFailedCode SMALLINT UNSIGNED NULL,"
|
---|
620 | " fReturnCode SMALLINT UNSIGNED NULL,"
|
---|
621 | " fFailedCodeAdd INT UNSIGNED NULL"
|
---|
622 | ")";
|
---|
623 |
|
---|
624 | list.Add(new TObjString(
|
---|
625 | "CREATE TABLE MyMagic.SequenceBuildStatus ("
|
---|
626 | " fDate DATE PRIMARY KEY, "
|
---|
627 | " fCCFilled DATETIME NULL,"
|
---|
628 | " fExclusionsDone DATETIME NULL,"
|
---|
629 | " fSequenceEntriesBuilt DATETIME NULL,"
|
---|
630 | " fStartTime DATETIME NULL,"
|
---|
631 | " fFailedTime DATETIME NULL,"
|
---|
632 | " fFailedCode SMALLINT UNSIGNED NULL,"
|
---|
633 | " fReturnCode SMALLINT UNSIGNED NULL,"
|
---|
634 | " fFailedCodeAdd INT UNSIGNED NULL"
|
---|
635 | ")";
|
---|
636 |
|
---|
637 | list.Add(new TObjString(
|
---|
638 | "CREATE TABLE MyMagic.RunProcessStatus ("
|
---|
639 | " fRunNumber INT UNSIGNED PRIMARY KEY, "
|
---|
640 | " fCCFileAvail DATETIME NULL,"
|
---|
641 | " fCaCoFileAvail DATETIME NULL,"
|
---|
642 | " fCaCoFileFound INT UNSIGNED NULL,"
|
---|
643 | " fRawFileAvail DATETIME NULL,"
|
---|
644 | " fDataCheckDone DATETIME NULL,"
|
---|
645 | " fTimingCorrection DATETIME NULL,"
|
---|
646 | " fMerpp DATETIME NULL,"
|
---|
647 | " fMerppCCUpdate DATETIME NULL,"
|
---|
648 | " fMerppCaCoUpdate DATETIME NULL,"
|
---|
649 | " fStartTime DATETIME NULL,"
|
---|
650 | " fFailedTime DATETIME NULL,"
|
---|
651 | " fFailedCode SMALLINT UNSIGNED NULL,"
|
---|
652 | " fReturnCode SMALLINT UNSIGNED NULL,"
|
---|
653 | " fFailedCodeAdd INT UNSIGNED NULL"
|
---|
654 | ")";
|
---|
655 |
|
---|
656 | list.Add(new TObjString(
|
---|
657 | "CREATE TABLE MyMagic.SequenceProcessStatus ("
|
---|
658 | " fSequenceFirst INT UNSIGNED PRIMARY KEY, "
|
---|
659 | " fSequenceFileWritten DATETIME NULL,"
|
---|
660 | " fAllFilesAvail DATETIME NULL,"
|
---|
661 | " fCallisto DATETIME NULL,"
|
---|
662 | " fFillCallisto DATETIME NULL,"
|
---|
663 | " fStar DATETIME NULL,"
|
---|
664 | " fFillStar DATETIME NULL,"
|
---|
665 | " fStartTime DATETIME NULL,"
|
---|
666 | " fFailedTime DATETIME NULL,"
|
---|
667 | " fFailedCode SMALLINT UNSIGNED NULL,"
|
---|
668 | " fReturnCode SMALLINT UNSIGNED NULL,"
|
---|
669 | " fFailedCodeAdd INT UNSIGNED NULL"
|
---|
670 | ")";
|
---|
671 |
|
---|
672 | list.Add(new TObjString(
|
---|
673 | "CREATE TABLE MyMagic.MarsVersion ("
|
---|
674 | " fMarsVersion SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
---|
675 | " fStartDate DATETIME NULL ,"
|
---|
676 | " fMarsVersionName VARCHAR(12) NOT NULL UNIQUE"
|
---|
677 | ") MAX_ROWS=256"));
|
---|
678 |
|
---|
679 | TSQLResult *res;
|
---|
680 |
|
---|
681 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
682 | if (!serv)
|
---|
683 | return;
|
---|
684 |
|
---|
685 | res = serv->DropDataBase("MyMagic");
|
---|
686 | res = serv->CreateDataBase("MyMagic");
|
---|
687 | if (res)
|
---|
688 | {
|
---|
689 | cout << "Error creating Data Base!" << endl;
|
---|
690 | return;
|
---|
691 | }
|
---|
692 |
|
---|
693 | TIter Next(&list);
|
---|
694 | TObjString *str;
|
---|
695 |
|
---|
696 | cout << "Creating tables..." << endl;
|
---|
697 |
|
---|
698 | while ((str=(TObjString*)Next()))
|
---|
699 | {
|
---|
700 | TString q(str->GetString());
|
---|
701 |
|
---|
702 | Int_t f = q.First('(');
|
---|
703 | TString out = q(0, f);
|
---|
704 | cout << " - " << out << "... " << flush;
|
---|
705 | res = serv->Query(q);
|
---|
706 | cout << (res==0 ? "ERROR!" : "Ok.") << endl;
|
---|
707 | if (res)
|
---|
708 | delete res;
|
---|
709 | }
|
---|
710 |
|
---|
711 | serv->Close();
|
---|
712 | delete serv;
|
---|
713 | }
|
---|
714 |
|
---|
715 | void DisplayMagicDataBase()
|
---|
716 | {
|
---|
717 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
718 | if (!serv)
|
---|
719 | return;
|
---|
720 |
|
---|
721 | res = serv->GetColumns("MyMagic", "RunData");
|
---|
722 | if (res)
|
---|
723 | Print(res);
|
---|
724 | res = serv->GetColumns("MyMagic", "RunType");
|
---|
725 | if (res)
|
---|
726 | Print(res);
|
---|
727 | res = serv->GetColumns("MyMagic", "MagicNumber");
|
---|
728 | if (res)
|
---|
729 | Print(res);
|
---|
730 | res = serv->GetColumns("MyMagic", "Project");
|
---|
731 | if (res)
|
---|
732 | Print(res);
|
---|
733 | res = serv->GetColumns("MyMagic", "Source");
|
---|
734 | if (res)
|
---|
735 | Print(res);
|
---|
736 | res = serv->GetColumns("MyMagic", "TriggerTable");
|
---|
737 | if (res)
|
---|
738 | Print(res);
|
---|
739 | res = serv->GetColumns("MyMagic", "HvSettings");
|
---|
740 | if (res)
|
---|
741 | Print(res);
|
---|
742 |
|
---|
743 | serv->Close();
|
---|
744 | }
|
---|
745 |
|
---|
746 | Bool_t ExistStr(TSQLServer *serv, const char *column, const char *table, const char *test)
|
---|
747 | {
|
---|
748 | TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
|
---|
749 | TSQLResult *res = serv->Query(query);
|
---|
750 | if (!res)
|
---|
751 | return kFALSE;
|
---|
752 | delete res;
|
---|
753 |
|
---|
754 | TSQLRow *row;
|
---|
755 |
|
---|
756 | while (row=res->Next())
|
---|
757 | {
|
---|
758 | if ((*row)[0])
|
---|
759 | return kTRUE;
|
---|
760 | }
|
---|
761 |
|
---|
762 | return kFALSE;
|
---|
763 | }
|
---|
764 | /*
|
---|
765 | void LoadSourceNames(const char *fname)
|
---|
766 | {
|
---|
767 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
768 | if (!serv)
|
---|
769 | return;
|
---|
770 |
|
---|
771 | ifstream fin(fname);
|
---|
772 | if (!fin)
|
---|
773 | {
|
---|
774 | cout << "Cannot open " << fname << endl;
|
---|
775 | return;
|
---|
776 | }
|
---|
777 |
|
---|
778 | while (1)
|
---|
779 | {
|
---|
780 | TString query, name;
|
---|
781 |
|
---|
782 | name.ReadLine(fin);
|
---|
783 | if (!fin)
|
---|
784 | break;
|
---|
785 |
|
---|
786 | if (ExistStr(serv, "fSourceName", "MyMagic.Source", name))
|
---|
787 | {
|
---|
788 | cout << "Entry " << name << " exists." << endl;
|
---|
789 | continue;
|
---|
790 | }
|
---|
791 |
|
---|
792 | query = "INSERT MyMagic.Source SET ";
|
---|
793 | query += " fSourceName='";
|
---|
794 | query += name;
|
---|
795 | query += "', fSourceTypeKEY=1";
|
---|
796 | if (!serv->Query(query))
|
---|
797 | {
|
---|
798 | cout << query << " - FAILED!" << endl;
|
---|
799 | return;
|
---|
800 | }
|
---|
801 | }
|
---|
802 |
|
---|
803 | serv->Close();
|
---|
804 | }
|
---|
805 |
|
---|
806 | void LoadProjectNames(const char *fname)
|
---|
807 | {
|
---|
808 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
809 | if (!serv)
|
---|
810 | return;
|
---|
811 |
|
---|
812 | ifstream fin(fname);
|
---|
813 | if (!fin)
|
---|
814 | {
|
---|
815 | cout << "Cannot open " << fname << endl;
|
---|
816 | return;
|
---|
817 | }
|
---|
818 |
|
---|
819 | while (1)
|
---|
820 | {
|
---|
821 | TString query, name;
|
---|
822 |
|
---|
823 | name.ReadLine(fin);
|
---|
824 | if (!fin)
|
---|
825 | break;
|
---|
826 |
|
---|
827 | if (ExistStr(serv, "fProjectName", "MyMagic.Project", name))
|
---|
828 | {
|
---|
829 | cout << "Entry " << name << " exists." << endl;
|
---|
830 | continue;
|
---|
831 | }
|
---|
832 |
|
---|
833 | query = "INSERT MyMagic.Project SET ";
|
---|
834 | query += " fProjectName='";
|
---|
835 | query += name;
|
---|
836 | query += "', fProject='AUTO: ";
|
---|
837 | query += name;
|
---|
838 | query += "'";
|
---|
839 | if (!serv->Query(query))
|
---|
840 | {
|
---|
841 | cout << query << " - FAILED!" << endl;
|
---|
842 | return;
|
---|
843 | }
|
---|
844 | }
|
---|
845 |
|
---|
846 | serv->Close();
|
---|
847 | }
|
---|
848 |
|
---|
849 | void LoadTriggerTableNames(const char *fname)
|
---|
850 | {
|
---|
851 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
852 | if (!serv)
|
---|
853 | return;
|
---|
854 |
|
---|
855 | ifstream fin(fname);
|
---|
856 | if (!fin)
|
---|
857 | {
|
---|
858 | cout << "Cannot open " << fname << endl;
|
---|
859 | return;
|
---|
860 | }
|
---|
861 |
|
---|
862 | while (1)
|
---|
863 | {
|
---|
864 | TString query, name;
|
---|
865 |
|
---|
866 | name.ReadLine(fin);
|
---|
867 | if (!fin)
|
---|
868 | break;
|
---|
869 |
|
---|
870 | if (ExistStr(serv, "fTriggerTableName", "MyMagic.TriggerTable", name))
|
---|
871 | {
|
---|
872 | cout << "Entry " << name << " exists." << endl;
|
---|
873 | continue;
|
---|
874 | }
|
---|
875 |
|
---|
876 | query = "INSERT MyMagic.TriggerTable SET ";
|
---|
877 | query += " fTriggerTableName='";
|
---|
878 | query += name;
|
---|
879 | query += "'";
|
---|
880 | if (!serv->Query(query))
|
---|
881 | {
|
---|
882 | cout << query << " - FAILED!" << endl;
|
---|
883 | return;
|
---|
884 | }
|
---|
885 | }
|
---|
886 |
|
---|
887 | serv->Close();
|
---|
888 | }
|
---|
889 | */
|
---|
890 | void setupdb()
|
---|
891 | {
|
---|
892 | CreateMagicDataBase();
|
---|
893 | CreatePrimaryEntries();
|
---|
894 | //LoadSourceNames("sourcenames.txt");
|
---|
895 | //LoadProjectNames("projectnames.txt");
|
---|
896 | //LoadTriggerTableNames("triggertablenames.txt");
|
---|
897 |
|
---|
898 |
|
---|
899 | return;
|
---|
900 |
|
---|
901 | //TSQLServer *serv = TSQLServer::Connect("mysql://magic:3306", "root", "marWin");
|
---|
902 | //TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "database", "ImM9G1CD8");
|
---|
903 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
904 | if (!serv)
|
---|
905 | return;
|
---|
906 |
|
---|
907 | cout << "ServerInfo: " << serv->ServerInfo() << endl;
|
---|
908 | cout << "DBMS: " << serv->GetDBMS() << endl;
|
---|
909 | cout << "Host: " << serv->GetHost() << endl;
|
---|
910 | cout << "Port: " << serv->GetPort() << endl;
|
---|
911 |
|
---|
912 | TSQLResult *res;
|
---|
913 |
|
---|
914 | cout << endl;
|
---|
915 |
|
---|
916 | res = serv->GetDataBases();
|
---|
917 | if (res)
|
---|
918 | Print(res);
|
---|
919 |
|
---|
920 | serv->Close();
|
---|
921 | /*
|
---|
922 | TList list;
|
---|
923 | if (!list.FindObject(triggertablename))
|
---|
924 | {
|
---|
925 | TNamed *name = new TNamed(triggertablename, "");
|
---|
926 | list.Add(name);
|
---|
927 | }
|
---|
928 |
|
---|
929 | list.Print();
|
---|
930 | */
|
---|
931 | }
|
---|