28 {
30
31 std::string infile("$(RDBMODELROOT)/xml/calib_test.xml");
32
34
37
38
39 int errcode = man->
build();
40
41 if (errcode) {
42 std::cerr << "Build failed with error code " << errcode << std::endl;
43 return errcode;
44 }
46
48
54
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));
63
66
67 bool checkOld = a->
verify(oldRow1, toBeRow);
68
69 std::cout << "Result of verifying 'maySupersede' against oldRow1: "
70 << checkOld << std::endl << std::endl;
71
72 oldFields.clear();
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));
77
79
80 checkOld = a->
verify(oldRow2, toBeRow);
81
82 std::cout << "Result of verifying 'maySupersede' against oldRow2: "
83 << checkOld << std::endl << std::endl;
84
85 std::string colMin;
86 std::string colMax;
87
89 if (serCol) {
91
92 std::cout << "Value of isPrimaryKey() for column ser_no is: "
94
96 std::cout << "Min and max for ser_no are " << colMin
97 << ", " << colMax << std::endl;
98 } else {
99 std::cout << "ser_no has no min, max " << std::endl;
100 }
101 }
102 else std::cout << "no such column as 'ser_no' " << std::endl;
103
105 if (vstartCol) {
107
109 std::cout << "Min and max for vstart are " << colMin
110 << ", " << colMax << std::endl;
111 } else {
112 std::cout << "vstart has no min, max " << std::endl;
113 }
114 }
115 else std::cout << "no such column as 'vstart' " << std::endl;
116
117
118
119#ifdef TEST_INSERT
120 std::string connectfileT("$(RDBMODELROOT)/xml/connect/mysqlTester.xml");
121#else
122 std::string connectfileT("$(RDBMODELROOT)/xml/connect/mysqlSlacT.xml");
123#endif
124
125
127
128 std::string connectfile("$(RDBMODELROOT)/xml/connect/mysqlSlac.xml");
129
130 if (!(con->
open(connectfile)) ) {
131 std::cerr << "Unable to connect to MySQL database" << std::endl;
132 return -1;
133 }
134
135
137
138 switch (match) {
140 std::cout << "XML schema and MySQL database are equivalent!" << std::endl;
141 break;
143 std::cout << "XML schema and MySQL database are compatible" << std::endl;
144 break;
146 std::cout << "XML schema and MySQL database are NOT compatible"
147 << std::endl;
148 return -2;
150 std::cout << "Connection failed while attempting match" << std::endl;
151 return -1;
152 }
153
154
155
156 std::string rq[3];
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++) {
161 try {
164 if (res) {
165 std::cout << "dbRequest '" << rq[i] << "'" << std::endl;
166 std::cout <<
"succeeded, returned " << res->
getNRows()
167 << " rows" << std::endl;
168 }
169 else {
170 std::cout << "dbRequest '" << rq[i] << "'" << std::endl;
171 std::cout << "succeeded, no returned data expected" << std::endl;
172 }
173 }
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;
178 }
179 }
180
181
182
184
185 if (!(con->
open(connectfile)) ) {
186 std::cerr << "Unable to connect to MySQL database" << std::endl;
187 return -1;
188 }
190
191
192 if (!(con->
open(connectfileT)) ) {
193 std::cerr << "Unable to connect to MySQL database" << std::endl;
194 return -1;
195 }
197
198
199
200
201#ifdef TEST_INSERT
202 bool disable = true;
205 if (serial) {
206 std::cout << "Hallelujah! Inserted new row, serial# "
207 << serial << std::endl;
208
209
210
211
212
213
214
215
216
217
218
219
220 } else if (disable) {
221 serial = 17;
222 }
223 if (serial) {
224
225
226 int nUpdates =
doUpdate(rdb, serial);
227
228 if (nUpdates) {
229 std::cout << "Did " << nUpdates << " on row " << serial
230 << std::endl;
231 }
232 else std::cout << "Failed to update row " << serial << std::endl;
233 }
234 else {
235 std::cout << "Bah, humbug. Insert failed. " << std::endl;
236 }
237
239 if (serial) {
240 std::cout << "Did insertLatest, inserted new row with ser_no = "
241 << serial << std::endl;
242
243 int newSerial;
245 if (didSup) {
246 std::cout << "Supersede of " << serial << " successful." << std::endl;
247 std::cout << "New row is " << newSerial << std::endl;
248 }
249 else {
250 std::cout << "Supersede of " << serial << " failed" << std::endl;
251 }
252
253 }
254 else if (!disable) {
255 std::cout << "Bah, humbug. insertLatest failed. " << std::endl;
256 }
257#else
258
259
260
261
262 switch (match) {
264 std::cout << "XML schema and MySQL database are equivalent!" << std::endl;
265 break;
267 std::cout << "XML schema and MySQL database are compatible" << std::endl;
268 break;
270 std::cout << "XML schema and MySQL database are NOT compatible"
271 << std::endl;
272 break;
273
275 std::cout << "Connection failed while attempting match" << std::endl;
276 return -1;
277 }
278
281
282 switch (match) {
284 std::cout << "XML schema and MySQL database are equivalent!"
285 << std::endl;
286 break;
288 std::cout << "XML schema and MySQL database are compatible" << std::endl;
289 break;
291 std::cout << "XML schema and MySQL database are NOT compatible"
292 << std::endl;
293
295 std::cout << "Connection failed while attempting match" << std::endl;
296 return -1;
297 }
298
299 }
300#endif
301
302 return 0;
303}
bool verify(Row &old, Row &toBe) const
bool isPrimaryKey() const
Datatype * getDatatype() 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
Table * getTable(const std::string &name) const
Column * getColumn(const std::string &tableName, const std::string &colName) 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 doUpdate(rdbModel::Rdb *, int serial)