1 //
2 // MySQLTest.cpp
3 //
4 // Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
5 // and Contributors.
6 //
7 // SPDX-License-Identifier:	BSL-1.0
8 //
9 
10 
11 #include "MySQLTest.h"
12 #include "CppUnit/TestCaller.h"
13 #include "CppUnit/TestSuite.h"
14 #include "Poco/String.h"
15 #include "Poco/Format.h"
16 #include "Poco/Tuple.h"
17 #include "Poco/NamedTuple.h"
18 #include "Poco/Exception.h"
19 #include "Poco/Data/LOB.h"
20 #include "Poco/Data/StatementImpl.h"
21 #include "Poco/Data/MySQL/Connector.h"
22 #include "Poco/Data/MySQL/Utility.h"
23 #include "Poco/Data/MySQL/MySQLException.h"
24 #include "Poco/Nullable.h"
25 #include "Poco/Data/DataException.h"
26 #include <iostream>
27 
28 using namespace Poco::Data;
29 using namespace Poco::Data::Keywords;
30 using Poco::Data::MySQL::ConnectionException;
31 using Poco::Data::MySQL::Utility;
32 using Poco::Data::MySQL::StatementException;
33 using Poco::format;
34 using Poco::NotFoundException;
35 using Poco::Int32;
36 using Poco::Nullable;
37 using Poco::Tuple;
38 using Poco::NamedTuple;
39 
40 Poco::SharedPtr<Poco::Data::Session> MySQLTest::_pSession = 0;
41 Poco::SharedPtr<SQLExecutor> MySQLTest::_pExecutor = 0;
42 
43 //
44 // Parameters for barebone-test
45 #define MYSQL_USER "pocotest"
46 #define MYSQL_PWD  "pocotest"
47 #define MYSQL_HOST "127.0.0.1"
48 #define MYSQL_PORT 3306
49 #define MYSQL_DB   "pocotest"
50 
51 //
52 // Connection string
53 std::string MySQLTest::_dbConnString = "host=" MYSQL_HOST
54 	";user=" MYSQL_USER
55 	";password=" MYSQL_PWD
56 	";db=" MYSQL_DB
57 	";compress=true"
58 	";auto-reconnect=true"
59 	";secure-auth=true"
60 	";protocol=tcp";
61 
62 
MySQLTest(const std::string & name)63 MySQLTest::MySQLTest(const std::string& name):
64 	CppUnit::TestCase(name)
65 {
66 	MySQL::Connector::registerConnector();
67 }
68 
69 
~MySQLTest()70 MySQLTest::~MySQLTest()
71 {
72 	MySQL::Connector::unregisterConnector();
73 }
74 
75 
dbInfo(Session & session)76 void MySQLTest::dbInfo(Session& session)
77 {
78 	std::cout << "Server Info: " << Utility::serverInfo(session) << std::endl;
79 	std::cout << "Server Version: " << Utility::serverVersion(session) << std::endl;
80 	std::cout << "Host Info: " << Utility::hostInfo(session) << std::endl;
81 }
82 
83 
connectNoDB()84 void MySQLTest::connectNoDB()
85 {
86 	std::string dbConnString = "host=" MYSQL_HOST
87 		";user=" MYSQL_USER
88 		";password=" MYSQL_PWD
89 		";compress=true;auto-reconnect=true;protocol=tcp";
90 
91 	try
92 	{
93 		Session session(MySQL::Connector::KEY, dbConnString);
94 		std::cout << "Connected to [" << "MySQL" << "] without database." << std::endl;
95 		dbInfo(session);
96 		session << "CREATE DATABASE IF NOT EXISTS " MYSQL_DB ";", now;
97 		std::cout << "Disconnecting ..." << std::endl;
98 		session.close();
99 		std::cout << "Disconnected." << std::endl;
100 	}
101 	catch (ConnectionFailedException& ex)
102 	{
103 		std::cout << ex.displayText() << std::endl;
104 	}
105 }
106 
107 
testBareboneMySQL()108 void MySQLTest::testBareboneMySQL()
109 {
110 	if (!_pSession) fail ("Test not available.");
111 
112 	std::string tableCreateString = "CREATE TABLE Test "
113 		"(First VARCHAR(30),"
114 		"Second VARCHAR(30),"
115 		"Third VARBINARY(30),"
116 		"Fourth INTEGER,"
117 		"Fifth FLOAT)";
118 
119 	_pExecutor->bareboneMySQLTest(MYSQL_HOST, MYSQL_USER, MYSQL_PWD, MYSQL_DB, MYSQL_PORT, tableCreateString.c_str());
120 }
121 
122 
testSimpleAccess()123 void MySQLTest::testSimpleAccess()
124 {
125 	if (!_pSession) fail ("Test not available.");
126 
127 	recreatePersonTable();
128 	_pExecutor->simpleAccess();
129 }
130 
131 
testComplexType()132 void MySQLTest::testComplexType()
133 {
134 	if (!_pSession) fail ("Test not available.");
135 
136 	recreatePersonTable();
137 	_pExecutor->complexType();
138 }
139 
140 
testSimpleAccessVector()141 void MySQLTest::testSimpleAccessVector()
142 {
143 	if (!_pSession) fail ("Test not available.");
144 
145 	recreatePersonTable();
146 	_pExecutor->simpleAccessVector();
147 }
148 
149 
testComplexTypeVector()150 void MySQLTest::testComplexTypeVector()
151 {
152 	if (!_pSession) fail ("Test not available.");
153 
154 	recreatePersonTable();
155 	_pExecutor->complexTypeVector();
156 }
157 
158 
testInsertVector()159 void MySQLTest::testInsertVector()
160 {
161 	if (!_pSession) fail ("Test not available.");
162 
163 	recreateStringsTable();
164 	_pExecutor->insertVector();
165 }
166 
167 
testInsertEmptyVector()168 void MySQLTest::testInsertEmptyVector()
169 {
170 	if (!_pSession) fail ("Test not available.");
171 
172 	recreateStringsTable();
173 	_pExecutor->insertEmptyVector();
174 }
175 
176 
testInsertSingleBulk()177 void MySQLTest::testInsertSingleBulk()
178 {
179 	if (!_pSession) fail ("Test not available.");
180 
181 	recreateIntsTable();
182 	_pExecutor->insertSingleBulk();
183 }
184 
185 
testInsertSingleBulkVec()186 void MySQLTest::testInsertSingleBulkVec()
187 {
188 	if (!_pSession) fail ("Test not available.");
189 
190 	recreateIntsTable();
191 	_pExecutor->insertSingleBulkVec();
192 }
193 
194 
testLimit()195 void MySQLTest::testLimit()
196 {
197 	if (!_pSession) fail ("Test not available.");
198 
199 	recreateIntsTable();
200 	_pExecutor->limits();
201 }
202 
203 
testLimitZero()204 void MySQLTest::testLimitZero()
205 {
206 	if (!_pSession) fail ("Test not available.");
207 
208 	recreateIntsTable();
209 	_pExecutor->limitZero();
210 }
211 
212 
testLimitOnce()213 void MySQLTest::testLimitOnce()
214 {
215 	if (!_pSession) fail ("Test not available.");
216 
217 	recreateIntsTable();
218 	_pExecutor->limitOnce();
219 }
220 
221 
testLimitPrepare()222 void MySQLTest::testLimitPrepare()
223 {
224 	if (!_pSession) fail ("Test not available.");
225 
226 	recreateIntsTable();
227 	_pExecutor->limitPrepare();
228 }
229 
230 
231 
testPrepare()232 void MySQLTest::testPrepare()
233 {
234 	if (!_pSession) fail ("Test not available.");
235 
236 	recreateIntsTable();
237 	_pExecutor->prepare();
238 }
239 
240 
testSetSimple()241 void MySQLTest::testSetSimple()
242 {
243 	if (!_pSession) fail ("Test not available.");
244 
245 	recreatePersonTable();
246 	_pExecutor->setSimple();
247 }
248 
249 
testSetComplex()250 void MySQLTest::testSetComplex()
251 {
252 	if (!_pSession) fail ("Test not available.");
253 
254 	recreatePersonTable();
255 	_pExecutor->setComplex();
256 }
257 
258 
testSetComplexUnique()259 void MySQLTest::testSetComplexUnique()
260 {
261 	if (!_pSession) fail ("Test not available.");
262 
263 	recreatePersonTable();
264 	_pExecutor->setComplexUnique();
265 }
266 
testMultiSetSimple()267 void MySQLTest::testMultiSetSimple()
268 {
269 	if (!_pSession) fail ("Test not available.");
270 
271 	recreatePersonTable();
272 	_pExecutor->multiSetSimple();
273 }
274 
275 
testMultiSetComplex()276 void MySQLTest::testMultiSetComplex()
277 {
278 	if (!_pSession) fail ("Test not available.");
279 
280 	recreatePersonTable();
281 	_pExecutor->multiSetComplex();
282 }
283 
284 
testMapComplex()285 void MySQLTest::testMapComplex()
286 {
287 	if (!_pSession) fail ("Test not available.");
288 
289 	recreatePersonTable();
290 	_pExecutor->mapComplex();
291 }
292 
293 
testMapComplexUnique()294 void MySQLTest::testMapComplexUnique()
295 {
296 	if (!_pSession) fail ("Test not available.");
297 
298 	recreatePersonTable();
299 	_pExecutor->mapComplexUnique();
300 }
301 
302 
testMultiMapComplex()303 void MySQLTest::testMultiMapComplex()
304 {
305 	if (!_pSession) fail ("Test not available.");
306 
307 	recreatePersonTable();
308 	_pExecutor->multiMapComplex();
309 }
310 
311 
testSelectIntoSingle()312 void MySQLTest::testSelectIntoSingle()
313 {
314 	if (!_pSession) fail ("Test not available.");
315 
316 	recreatePersonTable();
317 	_pExecutor->selectIntoSingle();
318 }
319 
320 
testSelectIntoSingleStep()321 void MySQLTest::testSelectIntoSingleStep()
322 {
323 	if (!_pSession) fail ("Test not available.");
324 
325 	recreatePersonTable();
326 	_pExecutor->selectIntoSingleStep();
327 }
328 
329 
testSelectIntoSingleFail()330 void MySQLTest::testSelectIntoSingleFail()
331 {
332 	if (!_pSession) fail ("Test not available.");
333 
334 	recreatePersonTable();
335 	_pExecutor->selectIntoSingleFail();
336 }
337 
338 
testLowerLimitOk()339 void MySQLTest::testLowerLimitOk()
340 {
341 	if (!_pSession) fail ("Test not available.");
342 
343 	recreatePersonTable();
344 	_pExecutor->lowerLimitOk();
345 }
346 
347 
testSingleSelect()348 void MySQLTest::testSingleSelect()
349 {
350 	if (!_pSession) fail ("Test not available.");
351 
352 	recreatePersonTable();
353 	_pExecutor->singleSelect();
354 }
355 
356 
testLowerLimitFail()357 void MySQLTest::testLowerLimitFail()
358 {
359 	if (!_pSession) fail ("Test not available.");
360 
361 	recreatePersonTable();
362 	_pExecutor->lowerLimitFail();
363 }
364 
365 
testCombinedLimits()366 void MySQLTest::testCombinedLimits()
367 {
368 	if (!_pSession) fail ("Test not available.");
369 
370 	recreatePersonTable();
371 	_pExecutor->combinedLimits();
372 }
373 
374 
375 
testRange()376 void MySQLTest::testRange()
377 {
378 	if (!_pSession) fail ("Test not available.");
379 
380 	recreatePersonTable();
381 	_pExecutor->ranges();
382 }
383 
384 
testCombinedIllegalLimits()385 void MySQLTest::testCombinedIllegalLimits()
386 {
387 	if (!_pSession) fail ("Test not available.");
388 
389 	recreatePersonTable();
390 	_pExecutor->combinedIllegalLimits();
391 }
392 
393 
394 
testIllegalRange()395 void MySQLTest::testIllegalRange()
396 {
397 	if (!_pSession) fail ("Test not available.");
398 
399 	recreatePersonTable();
400 	_pExecutor->illegalRange();
401 }
402 
403 
testEmptyDB()404 void MySQLTest::testEmptyDB()
405 {
406 	if (!_pSession) fail ("Test not available.");
407 
408 	recreatePersonTable();
409 	_pExecutor->emptyDB();
410 }
411 
412 
testDateTime()413 void MySQLTest::testDateTime()
414 {
415 	if (!_pSession) fail ("Test not available.");
416 
417 	recreatePersonDateTimeTable();
418 	_pExecutor->dateTime();
419 	recreatePersonDateTable();
420 	_pExecutor->date();
421 	recreatePersonTimeTable();
422 	_pExecutor->time();
423 }
424 
425 
testBLOB()426 void MySQLTest::testBLOB()
427 {
428 	if (!_pSession) fail ("Test not available.");
429 
430 	recreatePersonBLOBTable();
431 	_pExecutor->blob();
432 
433 	const std::size_t maxFldSize = 65534;
434 	_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
435 	recreatePersonBLOBTable();
436 
437 	try
438 	{
439 		_pExecutor->blob(maxFldSize);
440 		fail ("must fail");
441 	}
442 	catch (DataException&)
443 	{
444 		_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
445 	}
446 
447 	recreatePersonBLOBTable();
448 	_pExecutor->blob(maxFldSize);
449 
450 	recreatePersonBLOBTable();
451 
452 	try
453 	{
454 		_pExecutor->blob(maxFldSize+1);
455 		fail ("must fail");
456 	}
457 	catch (DataException&) { }
458 }
459 
460 
testBLOBStmt()461 void MySQLTest::testBLOBStmt()
462 {
463 	if (!_pSession) fail ("Test not available.");
464 
465 	recreatePersonBLOBTable();
466 	_pExecutor->blobStmt();
467 }
468 
469 
testUnsignedInts()470 void MySQLTest::testUnsignedInts()
471 {
472 	if (!_pSession) fail ("Test not available.");
473 
474 	recreateUnsignedIntsTable();
475 	_pExecutor->unsignedInts();
476 }
477 
478 
testFloat()479 void MySQLTest::testFloat()
480 {
481 	if (!_pSession) fail ("Test not available.");
482 
483 	recreateFloatsTable();
484 	_pExecutor->floats();
485 }
486 
487 
testDouble()488 void MySQLTest::testDouble()
489 {
490 	if (!_pSession) fail ("Test not available.");
491 
492 	recreateFloatsTable();
493 	_pExecutor->doubles();
494 }
495 
496 
testTuple()497 void MySQLTest::testTuple()
498 {
499 	if (!_pSession) fail ("Test not available.");
500 
501 	recreateTuplesTable();
502 	_pExecutor->tuples();
503 }
504 
505 
testTupleVector()506 void MySQLTest::testTupleVector()
507 {
508 	if (!_pSession) fail ("Test not available.");
509 
510 	recreateTuplesTable();
511 	_pExecutor->tupleVector();
512 }
513 
514 
testInternalExtraction()515 void MySQLTest::testInternalExtraction()
516 {
517 	if (!_pSession) fail ("Test not available.");
518 
519 	recreateVectorsTable();
520 	_pExecutor->internalExtraction();
521 }
522 
523 
testNull()524 void MySQLTest::testNull()
525 {
526 	if (!_pSession) fail ("Test not available.");
527 
528 	recreateVectorsTable();
529 	_pExecutor->doNull();
530 }
531 
532 
testSessionTransaction()533 void MySQLTest::testSessionTransaction()
534 {
535 	if (!_pSession) fail ("Test not available.");
536 
537 	recreatePersonTable();
538 	_pExecutor->sessionTransaction(_dbConnString);
539 }
540 
541 
testTransaction()542 void MySQLTest::testTransaction()
543 {
544 	if (!_pSession) fail ("Test not available.");
545 
546 	recreatePersonTable();
547 	_pExecutor->transaction(_dbConnString);
548 }
549 
550 
testReconnect()551 void MySQLTest::testReconnect()
552 {
553 	if (!_pSession) fail ("Test not available.");
554 
555 	recreatePersonTable();
556 	_pExecutor->reconnect();
557 }
558 
559 
testNullableInt()560 void MySQLTest::testNullableInt()
561 {
562 	if (!_pSession) fail ("Test not available.");
563 
564 	recreateNullableIntTable();
565 
566 	Nullable<Int32> i1(1);
567 	Nullable<Int32> i2;
568 
569 	int id = 1;
570 	*_pSession << "INSERT INTO NullableIntTest VALUES(?, ?)", use(id), use(i1), now;
571 	id = 2;
572 	*_pSession << "INSERT INTO NullableIntTest VALUES(?, ?)", use(id), use(i2), now;
573 	id = 3;
574 	i2 = 3;
575 	*_pSession << "INSERT INTO NullableIntTest VALUES(?, ?)", use(id), use(i2), now;
576 
577 	int count = 0;
578 	*_pSession << "SELECT COUNT(*) FROM NullableIntTest", into(count), now;
579 	assertTrue (count == 3);
580 
581 	Nullable<Int32> ci1;
582 	Nullable<Int32> ci2;
583 	Nullable<Int32> ci3;
584 	id = 1;
585 	*_pSession << "SELECT Value FROM NullableIntTest WHERE Id = ?", into(ci1), use(id), now;
586 	assertTrue (ci1 == i1);
587 	id = 2;
588 	*_pSession << "SELECT Value FROM NullableIntTest WHERE Id = ?", into(ci2), use(id), now;
589 	assertTrue (ci2.isNull());
590 	assertTrue (!(0 == ci2));
591 	assertTrue (0 != ci2);
592 	assertTrue (!(ci2 == 0));
593 	assertTrue (ci2 != 0);
594 	ci2 = 10;
595 	assertTrue (10 == ci2);
596 	assertTrue (ci2 == 10);
597 	assertTrue (!ci2.isNull());
598 	id = 3;
599 	*_pSession << "SELECT Value FROM NullableIntTest WHERE Id = ?", into(ci3), use(id), now;
600 	assertTrue (!ci3.isNull());
601 	assertTrue (ci3 == 3);
602 	assertTrue (3 == ci3);
603 }
604 
605 
testNullableString()606 void MySQLTest::testNullableString()
607 {
608 	if (!_pSession) fail ("Test not available.");
609 
610 	recreateNullableStringTable();
611 
612 	Int32 id = 0;
613 	Nullable<std::string> address("Address");
614 	Nullable<Int32> age = 10;
615 	*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(id), use(address), use(age), now;
616 	id++;
617 	address = null;
618 	age = null;
619 	*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(id), use(address), use(age), now;
620 
621 	Nullable<std::string> resAddress;
622 	Nullable<Int32> resAge;
623 	*_pSession << "SELECT Address, Age FROM NullableStringTest WHERE Id = ?", into(resAddress), into(resAge), use(id), now;
624 	assertTrue (resAddress == address);
625 	assertTrue (resAge == age);
626 	assertTrue (resAddress.isNull());
627 	assertTrue (null == resAddress);
628 	assertTrue (resAddress == null);
629 
630 	resAddress = std::string("Test");
631 	assertTrue (!resAddress.isNull());
632 	assertTrue (resAddress == std::string("Test"));
633 	assertTrue (std::string("Test") == resAddress);
634 	assertTrue (null != resAddress);
635 	assertTrue (resAddress != null);
636 }
637 
638 
testTupleWithNullable()639 void MySQLTest::testTupleWithNullable()
640 {
641 	if (!_pSession) fail ("Test not available.");
642 
643 	recreateNullableStringTable();
644 
645 	typedef Poco::Tuple<Int32, Nullable<std::string>, Nullable<Int32> > Info;
646 
647 	Info info(0, std::string("Address"), 10);
648 	*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
649 
650 	info.set<0>(info.get<0>()++);
651 	info.set<1>(null);
652 	*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
653 
654 	info.set<0>(info.get<0>()++);
655 	info.set<1>(std::string("Address!"));
656 	info.set<2>(null);
657 	*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(info), now;
658 
659 	std::vector<Info> infos;
660 	infos.push_back(Info(10, std::string("A"), 0));
661 	infos.push_back(Info(11, null, 12));
662 	infos.push_back(Info(12, std::string("B"), null));
663 
664 	*_pSession << "INSERT INTO NullableStringTest VALUES(?, ?, ?)", use(infos), now;
665 
666 	std::vector<Info> result;
667 
668 	*_pSession << "SELECT Id, Address, Age FROM NullableStringTest", into(result), now;
669 
670 	assertTrue (result[0].get<1>() == std::string("Address"));
671 	assertTrue (result[0].get<2>() == 10);
672 
673 	assertTrue (result[1].get<1>() == null);
674 	assertTrue (result[1].get<2>() == 10);
675 
676 	assertTrue (result[2].get<1>() == std::string("Address!"));
677 	assertTrue (result[2].get<2>() == null);
678 
679 	assertTrue (result[3].get<1>() == std::string("A"));
680 	assertTrue (result[3].get<2>() == 0);
681 
682 	assertTrue (result[4].get<1>() == null);
683 	assertTrue (result[4].get<2>() == 12);
684 
685 	assertTrue (result[5].get<1>() == std::string("B"));
686 	assertTrue (result[5].get<2>() == null);
687 
688 }
689 
690 
dropTable(const std::string & tableName)691 void MySQLTest::dropTable(const std::string& tableName)
692 {
693 	try { *_pSession << format("DROP TABLE IF EXISTS %s", tableName), now; }
694 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("dropTable()"); }
695 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("dropTable()"); }
696 }
697 
698 
recreatePersonTable()699 void MySQLTest::recreatePersonTable()
700 {
701 	dropTable("Person");
702 	try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
703 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonTable()"); }
704 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonTable()"); }
705 }
706 
707 
recreatePersonBLOBTable()708 void MySQLTest::recreatePersonBLOBTable()
709 {
710 	dropTable("Person");
711 	try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
712 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonBLOBTable()"); }
713 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonBLOBTable()"); }
714 }
715 
716 
recreatePersonDateTimeTable()717 void MySQLTest::recreatePersonDateTimeTable()
718 {
719 	dropTable("Person");
720 	try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday DATETIME(6))", now; }
721 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
722 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTimeTable()"); }
723 }
724 
725 
recreatePersonDateTable()726 void MySQLTest::recreatePersonDateTable()
727 {
728 	dropTable("Person");
729 	try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday DATE)", now; }
730 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonDateTable()"); }
731 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonDateTable()"); }
732 }
733 
734 
recreatePersonTimeTable()735 void MySQLTest::recreatePersonTimeTable()
736 {
737 	dropTable("Person");
738 	try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Birthday TIME)", now; }
739 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreatePersonTimeTable()"); }
740 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreatePersonTimeTable()"); }
741 }
742 
743 
recreateIntsTable()744 void MySQLTest::recreateIntsTable()
745 {
746 	dropTable("Strings");
747 	try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
748 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateIntsTable()"); }
749 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateIntsTable()"); }
750 }
751 
752 
recreateStringsTable()753 void MySQLTest::recreateStringsTable()
754 {
755 	dropTable("Strings");
756 	try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
757 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateStringsTable()"); }
758 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateStringsTable()"); }
759 }
760 
761 
recreateUnsignedIntsTable()762 void MySQLTest::recreateUnsignedIntsTable()
763 {
764 	dropTable("Strings");
765 	try { *_pSession << "CREATE TABLE Strings (str INTEGER UNSIGNED)", now; }
766 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateUnsignedIntegersTable()"); }
767 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateUnsignedIntegersTable()"); }
768 }
769 
770 
recreateFloatsTable()771 void MySQLTest::recreateFloatsTable()
772 {
773 	dropTable("Strings");
774 	try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
775 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateFloatsTable()"); }
776 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateFloatsTable()"); }
777 }
778 
779 
recreateTuplesTable()780 void MySQLTest::recreateTuplesTable()
781 {
782 	dropTable("Tuples");
783 	try { *_pSession << "CREATE TABLE Tuples "
784 		"(i0 INTEGER, i1 INTEGER, i2 INTEGER, i3 INTEGER, i4 INTEGER, i5 INTEGER, i6 INTEGER, "
785 		"i7 INTEGER, i8 INTEGER, i9 INTEGER, i10 INTEGER, i11 INTEGER, i12 INTEGER, i13 INTEGER,"
786 		"i14 INTEGER, i15 INTEGER, i16 INTEGER, i17 INTEGER, i18 INTEGER, i19 INTEGER)", now; }
787 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateTuplesTable()"); }
788 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateTuplesTable()"); }
789 }
790 
791 
recreateNullableIntTable()792 void MySQLTest::recreateNullableIntTable()
793 {
794 	dropTable("NullableIntTest");
795 	try {
796 		*_pSession << "CREATE TABLE NullableIntTest (Id INTEGER(10), Value INTEGER(10))", now;
797 	}
798 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateNullableIntTable()"); }
799 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateNullableIntTable()"); }
800 }
801 
802 
recreateNullableStringTable()803 void MySQLTest::recreateNullableStringTable()
804 {
805 	dropTable("NullableStringTest");
806 	try {
807 		*_pSession << "CREATE TABLE NullableStringTest (Id INTEGER(10), Address VARCHAR(30), Age INTEGER(10))", now;
808 	}
809 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateNullableStringTable()"); }
810 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateNullableStringTable()"); }
811 }
812 
813 
recreateVectorsTable()814 void MySQLTest::recreateVectorsTable()
815 {
816 	dropTable("Vectors");
817 	try { *_pSession << "CREATE TABLE Vectors (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
818 	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("recreateVectorsTable()"); }
819 	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("recreateVectorsTable()"); }
820 }
821 
822 
setUp()823 void MySQLTest::setUp()
824 {
825 }
826 
827 
tearDown()828 void MySQLTest::tearDown()
829 {
830 	dropTable("Person");
831 	dropTable("Strings");
832 }
833 
834 
suite()835 CppUnit::Test* MySQLTest::suite()
836 {
837 	MySQL::Connector::registerConnector();
838 
839 	try
840 	{
841 		_pSession = new Session(MySQL::Connector::KEY, _dbConnString);
842 	}
843 	catch (ConnectionFailedException& ex)
844 	{
845 		std::cout << ex.displayText() << std::endl;
846 		std::cout << "Trying to connect without DB and create one ..." << std::endl;
847 		connectNoDB();
848 		try
849 		{
850 			_pSession = new Session(MySQL::Connector::KEY, _dbConnString);
851 		}
852 		catch (ConnectionFailedException& ex)
853 		{
854 			std::cout << ex.displayText() << std::endl;
855 			return 0;
856 		}
857 	}
858 
859 	std::cout << "*** Connected to [" << "MySQL" << "] test database." << std::endl;
860 	dbInfo(*_pSession);
861 
862 	_pExecutor = new SQLExecutor("MySQL SQL Executor", _pSession);
863 
864 	CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MySQLTest");
865 
866 	CppUnit_addTest(pSuite, MySQLTest, testBareboneMySQL);
867 	CppUnit_addTest(pSuite, MySQLTest, testSimpleAccess);
868 	CppUnit_addTest(pSuite, MySQLTest, testComplexType);
869 	CppUnit_addTest(pSuite, MySQLTest, testSimpleAccessVector);
870 	CppUnit_addTest(pSuite, MySQLTest, testComplexTypeVector);
871 	CppUnit_addTest(pSuite, MySQLTest, testInsertVector);
872 	CppUnit_addTest(pSuite, MySQLTest, testInsertEmptyVector);
873 	CppUnit_addTest(pSuite, MySQLTest, testInsertSingleBulk);
874 	CppUnit_addTest(pSuite, MySQLTest, testInsertSingleBulkVec);
875 	CppUnit_addTest(pSuite, MySQLTest, testLimit);
876 	CppUnit_addTest(pSuite, MySQLTest, testLimitOnce);
877 	CppUnit_addTest(pSuite, MySQLTest, testLimitPrepare);
878 	CppUnit_addTest(pSuite, MySQLTest, testLimitZero);
879 	CppUnit_addTest(pSuite, MySQLTest, testPrepare);
880 	CppUnit_addTest(pSuite, MySQLTest, testSetSimple);
881 	CppUnit_addTest(pSuite, MySQLTest, testSetComplex);
882 	CppUnit_addTest(pSuite, MySQLTest, testSetComplexUnique);
883 	CppUnit_addTest(pSuite, MySQLTest, testMultiSetSimple);
884 	CppUnit_addTest(pSuite, MySQLTest, testMultiSetComplex);
885 	CppUnit_addTest(pSuite, MySQLTest, testMapComplex);
886 	CppUnit_addTest(pSuite, MySQLTest, testMapComplexUnique);
887 	CppUnit_addTest(pSuite, MySQLTest, testMultiMapComplex);
888 	CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingle);
889 	CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingleStep);
890 	CppUnit_addTest(pSuite, MySQLTest, testSelectIntoSingleFail);
891 	CppUnit_addTest(pSuite, MySQLTest, testLowerLimitOk);
892 	CppUnit_addTest(pSuite, MySQLTest, testLowerLimitFail);
893 	CppUnit_addTest(pSuite, MySQLTest, testCombinedLimits);
894 	CppUnit_addTest(pSuite, MySQLTest, testCombinedIllegalLimits);
895 	CppUnit_addTest(pSuite, MySQLTest, testRange);
896 	CppUnit_addTest(pSuite, MySQLTest, testIllegalRange);
897 	CppUnit_addTest(pSuite, MySQLTest, testSingleSelect);
898 	CppUnit_addTest(pSuite, MySQLTest, testEmptyDB);
899 	CppUnit_addTest(pSuite, MySQLTest, testDateTime);
900 	//CppUnit_addTest(pSuite, MySQLTest, testBLOB);
901 	CppUnit_addTest(pSuite, MySQLTest, testBLOBStmt);
902 	CppUnit_addTest(pSuite, MySQLTest, testUnsignedInts);
903 	CppUnit_addTest(pSuite, MySQLTest, testFloat);
904 	CppUnit_addTest(pSuite, MySQLTest, testDouble);
905 	CppUnit_addTest(pSuite, MySQLTest, testTuple);
906 	CppUnit_addTest(pSuite, MySQLTest, testTupleVector);
907 	CppUnit_addTest(pSuite, MySQLTest, testInternalExtraction);
908 	CppUnit_addTest(pSuite, MySQLTest, testNull);
909 	CppUnit_addTest(pSuite, MySQLTest, testNullableInt);
910 	CppUnit_addTest(pSuite, MySQLTest, testNullableString);
911 	CppUnit_addTest(pSuite, MySQLTest, testTupleWithNullable);
912 	CppUnit_addTest(pSuite, MySQLTest, testSessionTransaction);
913 	CppUnit_addTest(pSuite, MySQLTest, testTransaction);
914 	CppUnit_addTest(pSuite, MySQLTest, testReconnect);
915 
916 	return pSuite;
917 }
918