7#include "rdbModel/Rdb.h"
8#include "rdbModel/RdbException.h"
9#include "rdbModel/Management/Manager.h"
10#include "rdbModel/Management/XercesBuilder.h"
11#include "rdbModel/Db/MysqlConnection.h"
12#include "rdbModel/Db/MysqlResults.h"
13#include "rdbModel/Tables/Table.h"
14#include "rdbModel/Tables/Column.h"
15#include "rdbModel/Tables/Datatype.h"
16#include "rdbModel/Tables/Assertion.h"
17#include "facilities/Util.h"
27 int serial,
int* newSerial);
31 std::string infile(
"$(RDBMODELROOT)/xml/calib_test.xml");
39 int errcode = man->
build();
42 std::cerr <<
"Build failed with error code " << errcode << std::endl;
56 std::vector<FieldVal> oldFields;
57 oldFields.reserve(10);
58 oldFields.push_back(FieldVal(
"proc_level",
"PROD",
false));
59 oldFields.push_back(FieldVal(
"calib_type",
"CAL_Ped",
false));
60 oldFields.push_back(FieldVal(
"ser_no",
"17",
false));
61 oldFields.push_back(FieldVal(
"completion",
"OK",
false));
62 oldFields.push_back(FieldVal(
"prod_start",
"",
true));
67 bool checkOld = a->
verify(oldRow1, toBeRow);
69 std::cout <<
"Result of verifying 'maySupersede' against oldRow1: "
70 << checkOld << std::endl << std::endl;
73 oldFields.push_back(FieldVal(
"proc_level",
"DEV",
false));
74 oldFields.push_back(FieldVal(
"calib_type",
"CAL_Ped",
false));
75 oldFields.push_back(FieldVal(
"ser_no",
"17",
false));
76 oldFields.push_back(FieldVal(
"completion",
"OK",
false));
80 checkOld = a->
verify(oldRow2, toBeRow);
82 std::cout <<
"Result of verifying 'maySupersede' against oldRow2: "
83 << checkOld << std::endl << std::endl;
92 std::cout <<
"Value of isPrimaryKey() for column ser_no is: "
96 std::cout <<
"Min and max for ser_no are " << colMin
97 <<
", " << colMax << std::endl;
99 std::cout <<
"ser_no has no min, max " << std::endl;
102 else std::cout <<
"no such column as 'ser_no' " << std::endl;
109 std::cout <<
"Min and max for vstart are " << colMin
110 <<
", " << colMax << std::endl;
112 std::cout <<
"vstart has no min, max " << std::endl;
115 else std::cout <<
"no such column as 'vstart' " << std::endl;
120 std::string connectfileT(
"$(RDBMODELROOT)/xml/connect/mysqlTester.xml");
122 std::string connectfileT(
"$(RDBMODELROOT)/xml/connect/mysqlSlacT.xml");
128 std::string connectfile(
"$(RDBMODELROOT)/xml/connect/mysqlSlac.xml");
130 if (!(con->
open(connectfile)) ) {
131 std::cerr <<
"Unable to connect to MySQL database" << std::endl;
140 std::cout <<
"XML schema and MySQL database are equivalent!" << std::endl;
143 std::cout <<
"XML schema and MySQL database are compatible" << std::endl;
146 std::cout <<
"XML schema and MySQL database are NOT compatible"
150 std::cout <<
"Connection failed while attempting match" << std::endl;
157 rq[0] =
"select * from metadata_v2r1";
158 rq[1] =
"select calib_type from metadata_v2r1";
159 rq[2] =
"select garbage from metadata_v2r1";
160 for (
int i = 0; i < 3; i++) {
165 std::cout <<
"dbRequest '" << rq[i] <<
"'" << std::endl;
166 std::cout <<
"succeeded, returned " << res->
getNRows()
167 <<
" rows" << std::endl;
170 std::cout <<
"dbRequest '" << rq[i] <<
"'" << std::endl;
171 std::cout <<
"succeeded, no returned data expected" << std::endl;
175 std::cerr <<
"dbRequest '" << rq[i] <<
"'" << std::endl;
176 std::cerr <<
" failed with error: " << ex.
getMsg() << std::endl;
177 std::cerr <<
"Code " << ex.
getCode() << std::endl;
185 if (!(con->
open(connectfile)) ) {
186 std::cerr <<
"Unable to connect to MySQL database" << std::endl;
192 if (!(con->
open(connectfileT)) ) {
193 std::cerr <<
"Unable to connect to MySQL database" << std::endl;
206 std::cout <<
"Hallelujah! Inserted new row, serial# "
207 << serial << std::endl;
220 }
else if (disable) {
226 int nUpdates =
doUpdate(rdb, serial);
229 std::cout <<
"Did " << nUpdates <<
" on row " << serial
232 else std::cout <<
"Failed to update row " << serial << std::endl;
235 std::cout <<
"Bah, humbug. Insert failed. " << std::endl;
240 std::cout <<
"Did insertLatest, inserted new row with ser_no = "
241 << serial << std::endl;
246 std::cout <<
"Supersede of " << serial <<
" successful." << std::endl;
247 std::cout <<
"New row is " << newSerial << std::endl;
250 std::cout <<
"Supersede of " << serial <<
" failed" << std::endl;
255 std::cout <<
"Bah, humbug. insertLatest failed. " << std::endl;
264 std::cout <<
"XML schema and MySQL database are equivalent!" << std::endl;
267 std::cout <<
"XML schema and MySQL database are compatible" << std::endl;
270 std::cout <<
"XML schema and MySQL database are NOT compatible"
275 std::cout <<
"Connection failed while attempting match" << std::endl;
284 std::cout <<
"XML schema and MySQL database are equivalent!"
288 std::cout <<
"XML schema and MySQL database are compatible" << std::endl;
291 std::cout <<
"XML schema and MySQL database are NOT compatible"
295 std::cout <<
"Connection failed while attempting match" << std::endl;
311 std::vector<FieldVal> fields;
314 fields.push_back(FieldVal(
"instrument",
"LAT"));
315 fields.push_back(FieldVal(
"calib_type",
"Test_Gen"));
316 fields.push_back(FieldVal(
"flavor",
"berry"));
317 fields.push_back(FieldVal(
"data_fmt",
"nonsense"));
318 fields.push_back(FieldVal(
"vstart",
"2003-02-01"));
319 fields.push_back(FieldVal(
"data_size",
"0"));
320 fields.push_back(FieldVal(
"locale",
"phobos"));
321 fields.push_back(FieldVal(
"completion",
"ABORT"));
322 fields.push_back(FieldVal(
"data_ident",
"$(mycalibs)/test/moreJunk.xml"));
323 fields.push_back(FieldVal(
"notes",
324 "Absurd test item, setting input_desc to NULL"));
325 fields.push_back(FieldVal(
"input_desc",
"",
true));
331 rdb->
insertRow(
"metadata_v2r1", row, &serial);
339 std::vector<FieldVal> fields;
342 fields.push_back(FieldVal(
"instrument",
"LAT"));
343 fields.push_back(FieldVal(
"calib_type",
"CAL_Ped"));
344 fields.push_back(FieldVal(
"flavor",
"vanilla"));
345 fields.push_back(FieldVal(
"proc_level",
"PROD"));
346 fields.push_back(FieldVal(
"completion",
"OK"));
347 fields.push_back(FieldVal(
"data_fmt",
"XML"));
348 fields.push_back(FieldVal(
"fmt_version",
"1.1"));
349 fields.push_back(FieldVal(
"data_ident",
"nofile.xml"));
350 fields.push_back(FieldVal(
"vstart",
"2004-01-04"));
351 fields.push_back(FieldVal(
"vend",
"2030-01-01"));
352 fields.push_back(FieldVal(
"locale",
"Oz"));
353 fields.push_back(FieldVal(
"input_desc",
"none"));
354 fields.push_back(FieldVal(
"notes",
"trying out insertLatest"));
355 fields.push_back(FieldVal(
"prod_end",
"",
true));
356 fields.push_back(FieldVal(
"input_start",
"",
true));
357 fields.push_back(FieldVal(
"input_end",
"",
true));
366 std::cerr <<
"insertLatest failed with message" << ex.
getMsg();
380 std::string serialStr;
381 Util::itoa(serial, serialStr);
382 Assertion::Operator* serEquals =
387 Assertion* whereSer =
new Assertion(serEquals);
393 std::vector<FieldVal> fields;
395 fields.push_back(FieldVal(
"notes",
"1st update: set data_size to non-zero value"));
396 fields.push_back(FieldVal(
"data_size",
"883"));
400 std::string table(
"metadata_v2r1");
402 unsigned nChange = rdb->
updateRows(table, row, whereSer);
406 fields.push_back(FieldVal(
"data_size",
"",
true));
407 fields.push_back(FieldVal(
"notes",
"2nd update: data_size set to NULL"));
410 nChange += rdb->
updateRows(table, row2, whereSer);
419 std::cerr << colname <<
" not found by getQuick" << std::endl;
423 std::string name = col->
getName();
424 if (colname.compare(name) != 0) {
425 std::cerr <<
"Instead of " << colname <<
", getColumnByName found "
426 << name << std::endl;
430 std::cout <<
"getColumnByName found correct column with name " << colname
444 row.addField(FieldVal(
"data_ident",
"supFile.xml"));
445 row.addField(FieldVal(
"notes",
"this supersede is not supposed to work"));
446 row.addField(FieldVal(
"instrument",
"cello"));
449 if (!retVal) nSuccess++;
454 row.addField(FieldVal(
"notes",
"oops! left out data_ident"));
457 if (!retVal) nSuccess++;
461 row.addField(FieldVal(
"data_ident",
"supFile.xml"));
462 row.addField(FieldVal(
"notes",
"Try supersede with good row input"));
464 if (!retVal) nSuccess++;
466 std::cout <<
"Attempted 3 supersedes; # success = " << nSuccess
474 std::string table(
"metadata_v2r1");
478 retVal = rdb->
supersedeRow(table, row, serial, newSerial);
480 std::cout <<
"supersede of row " << serial <<
" failed with code "
481 << retVal << std::endl;
484 std::cout <<
"supsersede of row " << serial <<
" succeeded" << std::endl;
488 std::cout <<
"supersede of row " << serial <<
" failed with exception "
490 std::cout << ex.
getMsg() << std::endl;
bool verify(Row &old, Row &toBe) const
bool isPrimaryKey() const
Datatype * getDatatype() const
const std::string & getName() const
bool getInterval(std::string &min, std::string &max)
void setInputSource(std::string pname)
void setBuilder(Builder *b)
static Manager * getManager()
virtual bool open(const std::string &host, const std::string &userid, const std::string &password, const std::string &dbName)
virtual ResultHandle * dbRequest(const std::string &request)
virtual void disableModify(bool disable)
virtual MATCH matchSchema(Rdb *rdb, bool matchDbName=true)
virtual int getCode() const
virtual std::string getMsg()
int supersedeRow(const std::string &tName, Row &row, int oldKey, int *newKey=0) const
Table * getTable(const std::string &name) const
int insertLatest(Table *t, Row &row, int *serial=0) const
int updateRows(const std::string &tName, Row &row, Assertion *where) const
Column * getColumn(const std::string &tableName, const std::string &colName) const
int insertRow(const std::string &tName, Row &row, int *serial=0) const
virtual unsigned int getNRows() const =0
Return number of rows in results.
int doInsert(rdbModel::Rdb *con)
int doSmartInsert(rdbModel::Rdb *rdb)
void tryQuick(rdbModel::Table *t, const std::string &colname)
int doSupersedes(rdbModel::Rdb *rdb, int serial, int *newSerial)
int doSupersede(rdbModel::Rdb *rdb, rdbModel::Row &row, int serial, int *newSerial)
int doUpdate(rdbModel::Rdb *, int serial)