1 //
2 // ODBCTest.cpp
3 //
4 // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
5 // and Contributors.
6 //
7 // SPDX-License-Identifier:	BSL-1.0
8 //
9 
10 
11 #include "ODBCTest.h"
12 #include "CppUnit/TestCaller.h"
13 #include "CppUnit/TestSuite.h"
14 #include "Poco/String.h"
15 #include "Poco/Format.h"
16 #include "Poco/Any.h"
17 #include "Poco/DynamicAny.h"
18 #include "Poco/Tuple.h"
19 #include "Poco/DateTime.h"
20 #include "Poco/Exception.h"
21 #include "Poco/Data/LOB.h"
22 #include "Poco/Data/StatementImpl.h"
23 #include "Poco/Data/ODBC/Connector.h"
24 #include "Poco/Data/ODBC/Utility.h"
25 #include "Poco/Data/ODBC/Diagnostics.h"
26 #include "Poco/Data/ODBC/ODBCException.h"
27 #include "Poco/Data/ODBC/ODBCStatementImpl.h"
28 #include "Poco/Data/DataException.h"
29 #include <sqltypes.h>
30 #include <iostream>
31 
32 
33 using namespace Poco::Data::Keywords;
34 using Poco::Data::Session;
35 using Poco::Data::ConnectionFailedException;
36 using Poco::Data::CLOB;
37 using Poco::Data::ODBC::Utility;
38 using Poco::Data::ODBC::ODBCException;
39 using Poco::Data::ODBC::ConnectionException;
40 using Poco::Data::ODBC::StatementException;
41 using Poco::Data::ODBC::StatementDiagnostics;
42 using Poco::format;
43 using Poco::Tuple;
44 using Poco::Any;
45 using Poco::AnyCast;
46 using Poco::DynamicAny;
47 using Poco::DateTime;
48 using Poco::NotFoundException;
49 
50 
51 ODBCTest::Drivers ODBCTest::_drivers;
52 const bool        ODBCTest::_bindValues[8] =
53 	{true, true, true, false, false, true, false, false};
54 
55 
ODBCTest(const std::string & name,SessionPtr pSession,ExecPtr pExecutor,std::string & rDSN,std::string & rUID,std::string & rPwd,std::string & rConnectString)56 ODBCTest::ODBCTest(const std::string& name,
57 	SessionPtr pSession,
58 	ExecPtr    pExecutor,
59 	std::string& rDSN,
60 	std::string& rUID,
61 	std::string& rPwd,
62 	std::string& rConnectString):
63 	CppUnit::TestCase(name),
64 	_pSession(pSession),
65 	_pExecutor(pExecutor),
66 	_rDSN(rDSN),
67 	_rUID(rUID),
68 	_rPwd(rPwd),
69 	_rConnectString(rConnectString)
70 {
71 	_pSession->setFeature("autoCommit", true);
72 }
73 
74 
~ODBCTest()75 ODBCTest::~ODBCTest()
76 {
77 }
78 
79 
testZeroRows()80 void ODBCTest::testZeroRows()
81 {
82 	if (!_pSession) fail ("Test not available.");
83 
84 	std::string tableName("Person");
85 
86 	for (int i = 0; i < 8;)
87 	{
88 		recreatePersonTable();
89 		_pSession->setFeature("autoBind", bindValue(i));
90 		_pSession->setFeature("autoExtract", bindValue(i+1));
91 		_pExecutor->zeroRows();
92 		i += 2;
93 	}
94 }
95 
96 
testSimpleAccess()97 void ODBCTest::testSimpleAccess()
98 {
99 	if (!_pSession) fail ("Test not available.");
100 
101 	std::string tableName("Person");
102 
103 	for (int i = 0; i < 8;)
104 	{
105 		recreatePersonTable();
106 		_pSession->setFeature("autoBind", bindValue(i));
107 		_pSession->setFeature("autoExtract", bindValue(i+1));
108 		_pExecutor->simpleAccess();
109 		i += 2;
110 	}
111 }
112 
113 
testComplexType()114 void ODBCTest::testComplexType()
115 {
116 	if (!_pSession) fail ("Test not available.");
117 
118 	for (int i = 0; i < 8;)
119 	{
120 		recreatePersonTable();
121 		_pSession->setFeature("autoBind", bindValue(i));
122 		_pSession->setFeature("autoExtract", bindValue(i+1));
123 		_pExecutor->complexType();
124 		i += 2;
125 	}
126 }
127 
128 
testComplexTypeTuple()129 void ODBCTest::testComplexTypeTuple()
130 {
131 	if (!_pSession) fail ("Test not available.");
132 
133 	for (int i = 0; i < 8;)
134 	{
135 		recreatePersonTupleTable();
136 		_pSession->setFeature("autoBind", bindValue(i));
137 		_pSession->setFeature("autoExtract", bindValue(i+1));
138 		_pExecutor->complexTypeTuple();
139 		i += 2;
140 	}
141 }
142 
143 
testSimpleAccessVector()144 void ODBCTest::testSimpleAccessVector()
145 {
146 	if (!_pSession) fail ("Test not available.");
147 
148 	for (int i = 0; i < 8;)
149 	{
150 		recreatePersonTable();
151 		_pSession->setFeature("autoBind", bindValue(i));
152 		_pSession->setFeature("autoExtract", bindValue(i+1));
153 		_pExecutor->simpleAccessVector();
154 		i += 2;
155 	}
156 }
157 
158 
testComplexTypeVector()159 void ODBCTest::testComplexTypeVector()
160 {
161 	if (!_pSession) fail ("Test not available.");
162 
163 	for (int i = 0; i < 8;)
164 	{
165 		recreatePersonTable();
166 		_pSession->setFeature("autoBind", bindValue(i));
167 		_pSession->setFeature("autoExtract", bindValue(i+1));
168 		_pExecutor->complexTypeVector();
169 		i += 2;
170 	}
171 }
172 
173 
testSharedPtrComplexTypeVector()174 void ODBCTest::testSharedPtrComplexTypeVector()
175 {
176 	if (!_pSession) fail ("Test not available.");
177 
178 	for (int i = 0; i < 8;)
179 	{
180 		recreatePersonTable();
181 		_pSession->setFeature("autoBind", bindValue(i));
182 		_pSession->setFeature("autoExtract", bindValue(i+1));
183 		_pExecutor->sharedPtrComplexTypeVector();
184 		i += 2;
185 	}
186 }
187 
188 
testAutoPtrComplexTypeVector()189 void ODBCTest::testAutoPtrComplexTypeVector()
190 {
191 	if (!_pSession) fail ("Test not available.");
192 
193 	for (int i = 0; i < 8;)
194 	{
195 		recreatePersonTable();
196 		_pSession->setFeature("autoBind", bindValue(i));
197 		_pSession->setFeature("autoExtract", bindValue(i+1));
198 		_pExecutor->autoPtrComplexTypeVector();
199 		i += 2;
200 	}
201 }
202 
203 
testInsertVector()204 void ODBCTest::testInsertVector()
205 {
206 	if (!_pSession) fail ("Test not available.");
207 
208 	for (int i = 0; i < 8;)
209 	{
210 		recreateStringsTable();
211 		_pSession->setFeature("autoBind", bindValue(i));
212 		_pSession->setFeature("autoExtract", bindValue(i+1));
213 		_pExecutor->insertVector();
214 		i += 2;
215 	}
216 }
217 
218 
testInsertEmptyVector()219 void ODBCTest::testInsertEmptyVector()
220 {
221 	if (!_pSession) fail ("Test not available.");
222 
223 	for (int i = 0; i < 8;)
224 	{
225 		recreateStringsTable();
226 		_pSession->setFeature("autoBind", bindValue(i));
227 		_pSession->setFeature("autoExtract", bindValue(i+1));
228 		_pExecutor->insertEmptyVector();
229 		i += 2;
230 	}
231 }
232 
233 
testSimpleAccessList()234 void ODBCTest::testSimpleAccessList()
235 {
236 	if (!_pSession) fail ("Test not available.");
237 
238 	for (int i = 0; i < 8;)
239 	{
240 		recreatePersonTable();
241 		_pSession->setFeature("autoBind", bindValue(i));
242 		_pSession->setFeature("autoExtract", bindValue(i+1));
243 		_pExecutor->simpleAccessList();
244 		i += 2;
245 	}
246 }
247 
248 
testComplexTypeList()249 void ODBCTest::testComplexTypeList()
250 {
251 	if (!_pSession) fail ("Test not available.");
252 
253 	for (int i = 0; i < 8;)
254 	{
255 		recreatePersonTable();
256 		_pSession->setFeature("autoBind", bindValue(i));
257 		_pSession->setFeature("autoExtract", bindValue(i+1));
258 		_pExecutor->complexTypeList();
259 		i += 2;
260 	}
261 }
262 
263 
testInsertList()264 void ODBCTest::testInsertList()
265 {
266 	if (!_pSession) fail ("Test not available.");
267 
268 	for (int i = 0; i < 8;)
269 	{
270 		recreateStringsTable();
271 		_pSession->setFeature("autoBind", bindValue(i));
272 		_pSession->setFeature("autoExtract", bindValue(i+1));
273 		_pExecutor->insertList();
274 		i += 2;
275 	}
276 }
277 
278 
testInsertEmptyList()279 void ODBCTest::testInsertEmptyList()
280 {
281 	if (!_pSession) fail ("Test not available.");
282 
283 	for (int i = 0; i < 8;)
284 	{
285 		recreateStringsTable();
286 		_pSession->setFeature("autoBind", bindValue(i));
287 		_pSession->setFeature("autoExtract", bindValue(i+1));
288 		_pExecutor->insertEmptyList();
289 		i += 2;
290 	}
291 }
292 
293 
testSimpleAccessDeque()294 void ODBCTest::testSimpleAccessDeque()
295 {
296 	if (!_pSession) fail ("Test not available.");
297 
298 	for (int i = 0; i < 8;)
299 	{
300 		recreatePersonTable();
301 		_pSession->setFeature("autoBind", bindValue(i));
302 		_pSession->setFeature("autoExtract", bindValue(i+1));
303 		_pExecutor->simpleAccessDeque();
304 		i += 2;
305 	}
306 }
307 
308 
testComplexTypeDeque()309 void ODBCTest::testComplexTypeDeque()
310 {
311 	if (!_pSession) fail ("Test not available.");
312 
313 	for (int i = 0; i < 8;)
314 	{
315 		recreatePersonTable();
316 		_pSession->setFeature("autoBind", bindValue(i));
317 		_pSession->setFeature("autoExtract", bindValue(i+1));
318 		_pExecutor->complexTypeDeque();
319 		i += 2;
320 	}
321 }
322 
323 
testInsertDeque()324 void ODBCTest::testInsertDeque()
325 {
326 	if (!_pSession) fail ("Test not available.");
327 
328 	for (int i = 0; i < 8;)
329 	{
330 		recreateStringsTable();
331 		_pSession->setFeature("autoBind", bindValue(i));
332 		_pSession->setFeature("autoExtract", bindValue(i+1));
333 		_pExecutor->insertDeque();
334 		i += 2;
335 	}
336 }
337 
338 
testInsertEmptyDeque()339 void ODBCTest::testInsertEmptyDeque()
340 {
341 	if (!_pSession) fail ("Test not available.");
342 
343 	for (int i = 0; i < 8;)
344 	{
345 		recreateStringsTable();
346 		_pSession->setFeature("autoBind", bindValue(i));
347 		_pSession->setFeature("autoExtract", bindValue(i+1));
348 		_pExecutor->insertEmptyDeque();
349 		i += 2;
350 	}
351 }
352 
353 
testAffectedRows()354 void ODBCTest::testAffectedRows()
355 {
356 	if (!_pSession) fail ("Test not available.");
357 
358 	for (int i = 0; i < 8;)
359 	{
360 		recreateStringsTable();
361 		_pSession->setFeature("autoBind", bindValue(i));
362 		_pSession->setFeature("autoExtract", bindValue(i+1));
363 		_pExecutor->affectedRows();
364 		i += 2;
365 	}
366 }
367 
368 
testInsertSingleBulk()369 void ODBCTest::testInsertSingleBulk()
370 {
371 	if (!_pSession) fail ("Test not available.");
372 
373 	for (int i = 0; i < 8;)
374 	{
375 		recreateIntsTable();
376 		_pSession->setFeature("autoBind", bindValue(i));
377 		_pSession->setFeature("autoExtract", bindValue(i+1));
378 		_pExecutor->insertSingleBulk();
379 		i += 2;
380 	}
381 }
382 
383 
testInsertSingleBulkVec()384 void ODBCTest::testInsertSingleBulkVec()
385 {
386 	if (!_pSession) fail ("Test not available.");
387 
388 	for (int i = 0; i < 8;)
389 	{
390 		recreateIntsTable();
391 		_pSession->setFeature("autoBind", bindValue(i));
392 		_pSession->setFeature("autoExtract", bindValue(i+1));
393 		_pExecutor->insertSingleBulkVec();
394 		i += 2;
395 	}
396 }
397 
398 
testLimit()399 void ODBCTest::testLimit()
400 {
401 	if (!_pSession) fail ("Test not available.");
402 
403 	for (int i = 0; i < 8;)
404 	{
405 		recreateIntsTable();
406 		_pSession->setFeature("autoBind", bindValue(i));
407 		_pSession->setFeature("autoExtract", bindValue(i+1));
408 		_pExecutor->limits();
409 		i += 2;
410 	}
411 }
412 
413 
testLimitZero()414 void ODBCTest::testLimitZero()
415 {
416 	if (!_pSession) fail ("Test not available.");
417 
418 	for (int i = 0; i < 8;)
419 	{
420 		recreateIntsTable();
421 		_pSession->setFeature("autoBind", bindValue(i));
422 		_pSession->setFeature("autoExtract", bindValue(i+1));
423 		_pExecutor->limitZero();
424 		i += 2;
425 	}
426 }
427 
428 
testLimitOnce()429 void ODBCTest::testLimitOnce()
430 {
431 	if (!_pSession) fail ("Test not available.");
432 
433 	recreateIntsTable();
434 	_pExecutor->limitOnce();
435 
436 }
437 
438 
testLimitPrepare()439 void ODBCTest::testLimitPrepare()
440 {
441 	if (!_pSession) fail ("Test not available.");
442 
443 	for (int i = 0; i < 8;)
444 	{
445 		recreateIntsTable();
446 		_pSession->setFeature("autoBind", bindValue(i));
447 		_pSession->setFeature("autoExtract", bindValue(i+1));
448 		_pExecutor->limitPrepare();
449 		i += 2;
450 	}
451 }
452 
453 
454 
testPrepare()455 void ODBCTest::testPrepare()
456 {
457 	if (!_pSession) fail ("Test not available.");
458 
459 	for (int i = 0; i < 8;)
460 	{
461 		recreateIntsTable();
462 		_pSession->setFeature("autoBind", bindValue(i));
463 		_pSession->setFeature("autoExtract", bindValue(i+1));
464 		_pExecutor->prepare();
465 		i += 2;
466 	}
467 }
468 
469 
testBulk()470 void ODBCTest::testBulk()
471 {
472 	if (!_pSession) fail ("Test not available.");
473 
474 	_pSession->setFeature("autoBind", true);
475 	_pSession->setFeature("autoExtract", true);
476 
477 	recreateMiscTable();
478 	_pExecutor->doBulk<std::vector<int>,
479 		std::vector<std::string>,
480 		std::vector<CLOB>,
481 		std::vector<double>,
482 		std::vector<DateTime> >(100);
483 
484 	recreateMiscTable();
485 	_pExecutor->doBulk<std::deque<int>,
486 		std::deque<std::string>,
487 		std::deque<CLOB>,
488 		std::deque<double>,
489 		std::deque<DateTime> >(100);
490 
491 	recreateMiscTable();
492 	_pExecutor->doBulk<std::list<int>,
493 		std::list<std::string>,
494 		std::list<CLOB>,
495 		std::list<double>,
496 		std::list<DateTime> >(100);
497 }
498 
499 
testBulkPerformance()500 void ODBCTest::testBulkPerformance()
501 {
502 	if (!_pSession) fail ("Test not available.");
503 
504 	_pSession->setFeature("autoBind", true);
505 	_pSession->setFeature("autoExtract", true);
506 
507 	recreateMiscTable();
508 	_pExecutor->doBulkPerformance(1000);
509 }
510 
511 
testSetSimple()512 void ODBCTest::testSetSimple()
513 {
514 	if (!_pSession) fail ("Test not available.");
515 
516 	for (int i = 0; i < 8;)
517 	{
518 		recreatePersonTable();
519 		_pSession->setFeature("autoBind", bindValue(i));
520 		_pSession->setFeature("autoExtract", bindValue(i+1));
521 		_pExecutor->setSimple();
522 		i += 2;
523 	}
524 }
525 
526 
testSetComplex()527 void ODBCTest::testSetComplex()
528 {
529 	if (!_pSession) fail ("Test not available.");
530 
531 	for (int i = 0; i < 8;)
532 	{
533 		recreatePersonTable();
534 		_pSession->setFeature("autoBind", bindValue(i));
535 		_pSession->setFeature("autoExtract", bindValue(i+1));
536 		_pExecutor->setComplex();
537 		i += 2;
538 	}
539 }
540 
541 
testSetComplexUnique()542 void ODBCTest::testSetComplexUnique()
543 {
544 	if (!_pSession) fail ("Test not available.");
545 
546 	for (int i = 0; i < 8;)
547 	{
548 		recreatePersonTable();
549 		_pSession->setFeature("autoBind", bindValue(i));
550 		_pSession->setFeature("autoExtract", bindValue(i+1));
551 		_pExecutor->setComplexUnique();
552 		i += 2;
553 	}
554 }
555 
testMultiSetSimple()556 void ODBCTest::testMultiSetSimple()
557 {
558 	if (!_pSession) fail ("Test not available.");
559 
560 	for (int i = 0; i < 8;)
561 	{
562 		recreatePersonTable();
563 		_pSession->setFeature("autoBind", bindValue(i));
564 		_pSession->setFeature("autoExtract", bindValue(i+1));
565 		_pExecutor->multiSetSimple();
566 		i += 2;
567 	}
568 }
569 
570 
testMultiSetComplex()571 void ODBCTest::testMultiSetComplex()
572 {
573 	if (!_pSession) fail ("Test not available.");
574 
575 	for (int i = 0; i < 8;)
576 	{
577 		recreatePersonTable();
578 		_pSession->setFeature("autoBind", bindValue(i));
579 		_pSession->setFeature("autoExtract", bindValue(i+1));
580 		_pExecutor->multiSetComplex();
581 		i += 2;
582 	}
583 }
584 
585 
testMapComplex()586 void ODBCTest::testMapComplex()
587 {
588 	if (!_pSession) fail ("Test not available.");
589 
590 	for (int i = 0; i < 8;)
591 	{
592 		recreatePersonTable();
593 		_pSession->setFeature("autoBind", bindValue(i));
594 		_pSession->setFeature("autoExtract", bindValue(i+1));
595 		_pExecutor->mapComplex();
596 		i += 2;
597 	}
598 }
599 
600 
testMapComplexUnique()601 void ODBCTest::testMapComplexUnique()
602 {
603 	if (!_pSession) fail ("Test not available.");
604 
605 	for (int i = 0; i < 8;)
606 	{
607 		recreatePersonTable();
608 		_pSession->setFeature("autoBind", bindValue(i));
609 		_pSession->setFeature("autoExtract", bindValue(i+1));
610 		_pExecutor->mapComplexUnique();
611 		i += 2;
612 	}
613 }
614 
615 
testMultiMapComplex()616 void ODBCTest::testMultiMapComplex()
617 {
618 	if (!_pSession) fail ("Test not available.");
619 
620 	for (int i = 0; i < 8;)
621 	{
622 		recreatePersonTable();
623 		_pSession->setFeature("autoBind", bindValue(i));
624 		_pSession->setFeature("autoExtract", bindValue(i+1));
625 		_pExecutor->multiMapComplex();
626 		i += 2;
627 	}
628 }
629 
630 
testSelectIntoSingle()631 void ODBCTest::testSelectIntoSingle()
632 {
633 	if (!_pSession) fail ("Test not available.");
634 
635 	for (int i = 0; i < 8;)
636 	{
637 		recreatePersonTable();
638 		_pSession->setFeature("autoBind", bindValue(i));
639 		_pSession->setFeature("autoExtract", bindValue(i+1));
640 		_pExecutor->selectIntoSingle();
641 		i += 2;
642 	}
643 }
644 
645 
testSelectIntoSingleStep()646 void ODBCTest::testSelectIntoSingleStep()
647 {
648 	if (!_pSession) fail ("Test not available.");
649 
650 	for (int i = 0; i < 8;)
651 	{
652 		recreatePersonTable();
653 		_pSession->setFeature("autoBind", bindValue(i));
654 		_pSession->setFeature("autoExtract", bindValue(i+1));
655 		_pExecutor->selectIntoSingleStep();
656 		i += 2;
657 	}
658 }
659 
660 
testSelectIntoSingleFail()661 void ODBCTest::testSelectIntoSingleFail()
662 {
663 	if (!_pSession) fail ("Test not available.");
664 
665 	for (int i = 0; i < 8;)
666 	{
667 		recreatePersonTable();
668 		_pSession->setFeature("autoBind", bindValue(i));
669 		_pSession->setFeature("autoExtract", bindValue(i+1));
670 		_pExecutor->selectIntoSingleFail();
671 		i += 2;
672 	}
673 }
674 
675 
testLowerLimitOk()676 void ODBCTest::testLowerLimitOk()
677 {
678 	if (!_pSession) fail ("Test not available.");
679 
680 	for (int i = 0; i < 8;)
681 	{
682 		recreatePersonTable();
683 		_pSession->setFeature("autoBind", bindValue(i));
684 		_pSession->setFeature("autoExtract", bindValue(i+1));
685 		_pExecutor->lowerLimitOk();
686 		i += 2;
687 	}
688 }
689 
690 
testSingleSelect()691 void ODBCTest::testSingleSelect()
692 {
693 	if (!_pSession) fail ("Test not available.");
694 
695 	for (int i = 0; i < 8;)
696 	{
697 		recreatePersonTable();
698 		_pSession->setFeature("autoBind", bindValue(i));
699 		_pSession->setFeature("autoExtract", bindValue(i+1));
700 		_pExecutor->singleSelect();
701 		i += 2;
702 	}
703 }
704 
705 
testLowerLimitFail()706 void ODBCTest::testLowerLimitFail()
707 {
708 	if (!_pSession) fail ("Test not available.");
709 
710 	for (int i = 0; i < 8;)
711 	{
712 		recreatePersonTable();
713 		_pSession->setFeature("autoBind", bindValue(i));
714 		_pSession->setFeature("autoExtract", bindValue(i+1));
715 		_pExecutor->lowerLimitFail();
716 		i += 2;
717 	}
718 }
719 
720 
testCombinedLimits()721 void ODBCTest::testCombinedLimits()
722 {
723 	if (!_pSession) fail ("Test not available.");
724 
725 	for (int i = 0; i < 8;)
726 	{
727 		recreatePersonTable();
728 		_pSession->setFeature("autoBind", bindValue(i));
729 		_pSession->setFeature("autoExtract", bindValue(i+1));
730 		_pExecutor->combinedLimits();
731 		i += 2;
732 	}
733 }
734 
735 
736 
testRange()737 void ODBCTest::testRange()
738 {
739 	if (!_pSession) fail ("Test not available.");
740 
741 	for (int i = 0; i < 8;)
742 	{
743 		recreatePersonTable();
744 		_pSession->setFeature("autoBind", bindValue(i));
745 		_pSession->setFeature("autoExtract", bindValue(i+1));
746 		_pExecutor->ranges();
747 		i += 2;
748 	}
749 }
750 
751 
testCombinedIllegalLimits()752 void ODBCTest::testCombinedIllegalLimits()
753 {
754 	if (!_pSession) fail ("Test not available.");
755 
756 	for (int i = 0; i < 8;)
757 	{
758 		recreatePersonTable();
759 		_pSession->setFeature("autoBind", bindValue(i));
760 		_pSession->setFeature("autoExtract", bindValue(i+1));
761 		_pExecutor->combinedIllegalLimits();
762 		i += 2;
763 	}
764 }
765 
766 
767 
testIllegalRange()768 void ODBCTest::testIllegalRange()
769 {
770 	if (!_pSession) fail ("Test not available.");
771 
772 	for (int i = 0; i < 8;)
773 	{
774 		recreatePersonTable();
775 		_pSession->setFeature("autoBind", bindValue(i));
776 		_pSession->setFeature("autoExtract", bindValue(i+1));
777 		_pExecutor->illegalRange();
778 		i += 2;
779 	}
780 }
781 
782 
testEmptyDB()783 void ODBCTest::testEmptyDB()
784 {
785 	if (!_pSession) fail ("Test not available.");
786 
787 	for (int i = 0; i < 8;)
788 	{
789 		recreatePersonTable();
790 		_pSession->setFeature("autoBind", bindValue(i));
791 		_pSession->setFeature("autoExtract", bindValue(i+1));
792 		_pExecutor->emptyDB();
793 		i += 2;
794 	}
795 }
796 
797 
testBLOB()798 void ODBCTest::testBLOB()
799 {
800 	if (!_pSession) fail ("Test not available.");
801 
802 	for (int i = 0; i < 8;)
803 	{
804 		recreatePersonBLOBTable();
805 		_pSession->setFeature("autoBind", bindValue(i));
806 		_pSession->setFeature("autoExtract", bindValue(i+1));
807 		_pExecutor->blob();
808 		i += 2;
809 	}
810 }
811 
812 
testBLOBContainer()813 void ODBCTest::testBLOBContainer()
814 {
815 	for (int i = 0; i < 8;)
816 	{
817 		session().setFeature("autoBind", bindValue(i));
818 		session().setFeature("autoExtract", bindValue(i+1));
819 		recreatePersonBLOBTable();
820 		_pExecutor->blobContainer<std::vector<std::string>, std::vector<CLOB> >(10);
821 		recreatePersonBLOBTable();
822 		_pExecutor->blobContainer<std::deque<std::string>, std::deque<CLOB> >(10);
823 		recreatePersonBLOBTable();
824 		_pExecutor->blobContainer<std::list<std::string>, std::list<CLOB> >(10);
825 		i += 2;
826 	}
827 }
828 
829 
testBLOBStmt()830 void ODBCTest::testBLOBStmt()
831 {
832 	if (!_pSession) fail ("Test not available.");
833 
834 	for (int i = 0; i < 8;)
835 	{
836 		recreatePersonBLOBTable();
837 		_pSession->setFeature("autoBind", bindValue(i));
838 		_pSession->setFeature("autoExtract", bindValue(i+1));
839 		_pExecutor->blobStmt();
840 		i += 2;
841 	}
842 }
843 
844 
testDateTime()845 void ODBCTest::testDateTime()
846 {
847 	if (!_pSession) fail ("Test not available.");
848 
849 	for (int i = 0; i < 8;)
850 	{
851 		recreatePersonDateTimeTable();
852 		_pSession->setFeature("autoBind", bindValue(i));
853 		_pSession->setFeature("autoExtract", bindValue(i+1));
854 		_pExecutor->dateTime();
855 		i += 2;
856 	}
857 }
858 
859 
testDate()860 void ODBCTest::testDate()
861 {
862 	if (!_pSession) fail ("Test not available.");
863 
864 	for (int i = 0; i < 8;)
865 	{
866 		recreatePersonDateTable();
867 		_pSession->setFeature("autoBind", bindValue(i));
868 		_pSession->setFeature("autoExtract", bindValue(i+1));
869 		_pExecutor->date();
870 		i += 2;
871 	}
872 }
873 
874 
testTime()875 void ODBCTest::testTime()
876 {
877 	if (!_pSession) fail ("Test not available.");
878 
879 	for (int i = 0; i < 8;)
880 	{
881 		recreatePersonTimeTable();
882 		_pSession->setFeature("autoBind", bindValue(i));
883 		_pSession->setFeature("autoExtract", bindValue(i+1));
884 		_pExecutor->time();
885 		i += 2;
886 	}
887 }
888 
889 
testFloat()890 void ODBCTest::testFloat()
891 {
892 	if (!_pSession) fail ("Test not available.");
893 
894 	for (int i = 0; i < 8;)
895 	{
896 		recreateFloatsTable();
897 		_pSession->setFeature("autoBind", bindValue(i));
898 		_pSession->setFeature("autoExtract", bindValue(i+1));
899 		_pExecutor->floats();
900 		i += 2;
901 	}
902 }
903 
904 
testDouble()905 void ODBCTest::testDouble()
906 {
907 	if (!_pSession) fail ("Test not available.");
908 
909 	for (int i = 0; i < 8;)
910 	{
911 		recreateFloatsTable();
912 		_pSession->setFeature("autoBind", bindValue(i));
913 		_pSession->setFeature("autoExtract", bindValue(i+1));
914 		_pExecutor->doubles();
915 		i += 2;
916 	}
917 }
918 
919 
testTuple()920 void ODBCTest::testTuple()
921 {
922 	if (!_pSession) fail ("Test not available.");
923 
924 	for (int i = 0; i < 8;)
925 	{
926 		recreateTuplesTable();
927 		_pSession->setFeature("autoBind", bindValue(i));
928 		_pSession->setFeature("autoExtract", bindValue(i+1));
929 		_pExecutor->tuples();
930 		i += 2;
931 	}
932 }
933 
934 
testTupleVector()935 void ODBCTest::testTupleVector()
936 {
937 	if (!_pSession) fail ("Test not available.");
938 
939 	for (int i = 0; i < 8;)
940 	{
941 		recreateTuplesTable();
942 		_pSession->setFeature("autoBind", bindValue(i));
943 		_pSession->setFeature("autoExtract", bindValue(i+1));
944 		_pExecutor->tupleVector();
945 		i += 2;
946 	}
947 }
948 
949 
testInternalExtraction()950 void ODBCTest::testInternalExtraction()
951 {
952 	if (!_pSession) fail ("Test not available.");
953 
954 	for (int i = 0; i < 8;)
955 	{
956 		recreateVectorsTable();
957 		_pSession->setFeature("autoBind", bindValue(i));
958 		_pSession->setFeature("autoExtract", bindValue(i+1));
959 		_pExecutor->internalExtraction();
960 		i += 2;
961 	}
962 }
963 
964 
testFilter()965 void ODBCTest::testFilter()
966 {
967 	if (!_pSession) fail ("Test not available.");
968 
969 	for (int i = 0; i < 8;)
970 	{
971 		recreateVectorsTable();
972 		_pSession->setFeature("autoBind", bindValue(i));
973 		_pSession->setFeature("autoExtract", bindValue(i+1));
974 		_pExecutor->filter();
975 		i += 2;
976 	}
977 }
978 
979 
testInternalBulkExtraction()980 void ODBCTest::testInternalBulkExtraction()
981 {
982 	if (!_pSession) fail ("Test not available.");
983 
984 	recreatePersonTable();
985 	_pSession->setFeature("autoBind", true);
986 	_pSession->setFeature("autoExtract", true);
987 #ifdef POCO_ODBC_UNICODE
988 	_pExecutor->internalBulkExtractionUTF16();
989 #else
990 	_pExecutor->internalBulkExtraction();
991 #endif
992 }
993 
994 
testInternalStorageType()995 void ODBCTest::testInternalStorageType()
996 {
997 	if (!_pSession) fail ("Test not available.");
998 
999 	for (int i = 0; i < 8;)
1000 	{
1001 		recreateVectorsTable();
1002 		_pSession->setFeature("autoBind", bindValue(i));
1003 		_pSession->setFeature("autoExtract", bindValue(i+1));
1004 		_pExecutor->internalStorageType();
1005 		i += 2;
1006 	}
1007 }
1008 
1009 
testNull()1010 void ODBCTest::testNull()
1011 {
1012 	if (!_pSession) fail ("Test not available.");
1013 
1014 	// test for NOT NULL violation exception
1015 	for (int i = 0; i < 8;)
1016 	{
1017 		recreateNullsTable("NOT NULL");
1018 		_pSession->setFeature("autoBind", bindValue(i));
1019 		_pSession->setFeature("autoExtract", bindValue(i+1));
1020 		_pExecutor->notNulls();
1021 		i += 2;
1022 	}
1023 
1024 	// test for null insertion
1025 	for (int i = 0; i < 8;)
1026 	{
1027 		recreateNullsTable();
1028 		_pSession->setFeature("autoBind", bindValue(i));
1029 		_pSession->setFeature("autoExtract", bindValue(i+1));
1030 		_pExecutor->nulls();
1031 		i += 2;
1032 	}
1033 }
1034 
1035 
testRowIterator()1036 void ODBCTest::testRowIterator()
1037 {
1038 	if (!_pSession) fail ("Test not available.");
1039 
1040 	for (int i = 0; i < 8;)
1041 	{
1042 		recreateVectorsTable();
1043 		_pSession->setFeature("autoBind", bindValue(i));
1044 		_pSession->setFeature("autoExtract", bindValue(i+1));
1045 		_pExecutor->rowIterator();
1046 		i += 2;
1047 	}
1048 }
1049 
1050 
testStdVectorBool()1051 void ODBCTest::testStdVectorBool()
1052 {
1053 	if (!_pSession) fail ("Test not available.");
1054 
1055 	for (int i = 0; i < 8;)
1056 	{
1057 		recreateBoolTable();
1058 		_pSession->setFeature("autoBind", bindValue(i));
1059 		_pSession->setFeature("autoExtract", bindValue(i+1));
1060 		_pExecutor->stdVectorBool();
1061 		i += 2;
1062 	}
1063 }
1064 
1065 
testAsync()1066 void ODBCTest::testAsync()
1067 {
1068 	if (!_pSession) fail ("Test not available.");
1069 
1070 	for (int i = 0; i < 8;)
1071 	{
1072 		recreateIntsTable();
1073 		_pSession->setFeature("autoBind", bindValue(i));
1074 		_pSession->setFeature("autoExtract", bindValue(i+1));
1075 		_pExecutor->asynchronous(2000);
1076 		i += 2;
1077 	}
1078 }
1079 
1080 
testAny()1081 void ODBCTest::testAny()
1082 {
1083 	if (!_pSession) fail ("Test not available.");
1084 
1085 	for (int i = 0; i < 8;)
1086 	{
1087 		recreateAnysTable();
1088 		_pSession->setFeature("autoBind", bindValue(i));
1089 		_pSession->setFeature("autoExtract", bindValue(i+1));
1090 		_pExecutor->any();
1091 
1092 		i += 2;
1093 	}
1094 }
1095 
1096 
testDynamicAny()1097 void ODBCTest::testDynamicAny()
1098 {
1099 	if (!_pSession) fail ("Test not available.");
1100 
1101 	for (int i = 0; i < 8;)
1102 	{
1103 		recreateAnysTable();
1104 		_pSession->setFeature("autoBind", bindValue(i));
1105 		_pSession->setFeature("autoExtract", bindValue(i+1));
1106 		_pExecutor->dynamicAny();
1107 
1108 		i += 2;
1109 	}
1110 }
1111 
1112 
testMultipleResults()1113 void ODBCTest::testMultipleResults()
1114 {
1115 	if (!_pSession) fail ("Test not available.");
1116 
1117 	for (int i = 0; i < 8;)
1118 	{
1119 		recreatePersonTable();
1120 		_pSession->setFeature("autoBind", bindValue(i));
1121 		_pSession->setFeature("autoExtract", bindValue(i+1));
1122 		_pExecutor->multipleResults();
1123 
1124 		i += 2;
1125 	}
1126 }
1127 
1128 
testSQLChannel()1129 void ODBCTest::testSQLChannel()
1130 {
1131 	if (!_pSession) fail ("Test not available.");
1132 
1133 	for (int i = 0; i < 8;)
1134 	{
1135 		recreateLogTable();
1136 		_pSession->setFeature("autoBind", bindValue(i));
1137 		_pSession->setFeature("autoExtract", bindValue(i+1));
1138 		_pExecutor->sqlChannel(_rConnectString);
1139 
1140 		i += 2;
1141 	}
1142 }
1143 
1144 
testSQLLogger()1145 void ODBCTest::testSQLLogger()
1146 {
1147 	if (!_pSession) fail ("Test not available.");
1148 
1149 	for (int i = 0; i < 8;)
1150 	{
1151 		recreateLogTable();
1152 		_pSession->setFeature("autoBind", bindValue(i));
1153 		_pSession->setFeature("autoExtract", bindValue(i+1));
1154 		_pExecutor->sqlLogger(_rConnectString);
1155 
1156 		i += 2;
1157 	}
1158 }
1159 
1160 
testSessionTransaction()1161 void ODBCTest::testSessionTransaction()
1162 {
1163 	if (!_pSession) fail ("Test not available.");
1164 
1165 	for (int i = 0; i < 8;)
1166 	{
1167 		recreatePersonTable();
1168 		_pSession->setFeature("autoBind", bindValue(i));
1169 		_pSession->setFeature("autoExtract", bindValue(i+1));
1170 		_pExecutor->sessionTransaction(_rConnectString);
1171 		i += 2;
1172 	}
1173 }
1174 
1175 
testTransaction()1176 void ODBCTest::testTransaction()
1177 {
1178 	if (!_pSession) fail ("Test not available.");
1179 
1180 	for (int i = 0; i < 8;)
1181 	{
1182 		recreatePersonTable();
1183 		_pSession->setFeature("autoBind", bindValue(i));
1184 		_pSession->setFeature("autoExtract", bindValue(i+1));
1185 		_pExecutor->transaction(_rConnectString);
1186 		i += 2;
1187 	}
1188 }
1189 
1190 
testTransactor()1191 void ODBCTest::testTransactor()
1192 {
1193 	if (!_pSession) fail ("Test not available.");
1194 
1195 	for (int i = 0; i < 8;)
1196 	{
1197 		recreatePersonTable();
1198 		_pSession->setFeature("autoBind", bindValue(i));
1199 		_pSession->setFeature("autoExtract", bindValue(i+1));
1200 		_pExecutor->transactor();
1201 		i += 2;
1202 	}
1203 }
1204 
1205 
testNullable()1206 void ODBCTest::testNullable()
1207 {
1208 	if (!_pSession) fail ("Test not available.");
1209 
1210 	for (int i = 0; i < 8;)
1211 	{
1212 		recreateNullableTable();
1213 		_pSession->setFeature("autoBind", bindValue(i));
1214 		_pSession->setFeature("autoExtract", bindValue(i+1));
1215 		_pExecutor->nullable();
1216 		i += 2;
1217 	}
1218 }
1219 
1220 
testUnicode()1221 void ODBCTest::testUnicode()
1222 {
1223 #if defined (POCO_ODBC_UNICODE)
1224 	if (!_pSession) fail("Test not available.");
1225 
1226 	for (int i = 0; i < 8;)
1227 	{
1228 		recreateUnicodeTable();
1229 		_pSession->setFeature("autoBind", bindValue(i));
1230 		_pSession->setFeature("autoExtract", bindValue(i + 1));
1231 		_pExecutor->unicode(_rConnectString);
1232 		i += 2;
1233 	}
1234 #else
1235 	std::cout << "Not an UNICODE build, skipping." << std::endl;
1236 #endif
1237 }
1238 
1239 
testReconnect()1240 void ODBCTest::testReconnect()
1241 {
1242 	if (!_pSession) fail ("Test not available.");
1243 
1244 	std::string tableName("Person");
1245 
1246 	for (int i = 0; i < 8;)
1247 	{
1248 		recreatePersonTable();
1249 		_pSession->setFeature("autoBind", bindValue(i));
1250 		_pSession->setFeature("autoExtract", bindValue(i+1));
1251 		_pExecutor->reconnect();
1252 		i += 2;
1253 	}
1254 }
1255 
1256 
canConnect(const std::string & driver,std::string & dsn,std::string & uid,std::string & pwd,std::string & dbConnString,const std::string & db)1257 bool ODBCTest::canConnect(const std::string& driver,
1258 	std::string& dsn,
1259 	std::string& uid,
1260 	std::string& pwd,
1261 	std::string& dbConnString,
1262 	const std::string& db)
1263 {
1264 	Utility::DriverMap::iterator itDrv = _drivers.begin();
1265 	for (; itDrv != _drivers.end(); ++itDrv)
1266 	{
1267 		if (((itDrv->first).find(driver) != std::string::npos))
1268 		{
1269 			std::cout << "Driver found: " << itDrv->first
1270 				<< " (" << itDrv->second << ')' << std::endl;
1271 			break;
1272 		}
1273 	}
1274 
1275 	if (_drivers.end() == itDrv)
1276 	{
1277 		dsn = "";
1278 		uid = "";
1279 		pwd = "";
1280 		dbConnString = "";
1281 		std::cout << driver << " driver NOT found, tests not available." << std::endl;
1282 		return false;
1283 	}
1284 
1285 	Utility::DSNMap dataSources;
1286 	Utility::dataSources(dataSources);
1287 	if (dataSources.size() > 0)
1288 	{
1289 		Utility::DSNMap::iterator itDSN = dataSources.begin();
1290 		std::cout << dataSources.size() << " DSNs found, enumerating ..." << std::endl;
1291 		for (; itDSN != dataSources.end(); ++itDSN)
1292 		{
1293 			if (itDSN->first == dsn && itDSN->second == driver)
1294 			{
1295 				std::cout << "DSN found: " << itDSN->first
1296 					<< " (" << itDSN->second << ')' << std::endl;
1297 
1298 				dbConnString = format("DSN=%s;UID=%s;PWD=%s;", dsn, uid, pwd);
1299 				if (!db.empty())
1300 					format(dbConnString, "DATABASE=%s;", db);
1301 
1302 				return true;
1303 			}
1304 		}
1305 	}
1306 	else
1307 		std::cout << "No DSNs found, will attempt DSN-less connection ..." << std::endl;
1308 
1309 	dsn = "";
1310 	return true;
1311 }
1312 
1313 
setUp()1314 void ODBCTest::setUp()
1315 {
1316 }
1317 
1318 
tearDown()1319 void ODBCTest::tearDown()
1320 {
1321 }
1322 
1323 
init(const std::string & driver,std::string & dsn,std::string & uid,std::string & pwd,std::string & dbConnString,const std::string & db)1324 ODBCTest::SessionPtr ODBCTest::init(const std::string& driver,
1325 	std::string& dsn,
1326 	std::string& uid,
1327 	std::string& pwd,
1328 	std::string& dbConnString,
1329 	const std::string& db)
1330 {
1331 	Utility::drivers(_drivers);
1332 	if (!canConnect(driver, dsn, uid, pwd, dbConnString, db)) return 0;
1333 
1334 	try
1335 	{
1336 		std::cout << "Conecting to [" << dbConnString << ']' << std::endl;
1337 		return new Session(Poco::Data::ODBC::Connector::KEY, dbConnString, 5);
1338 	}catch (ConnectionFailedException& ex)
1339 	{
1340 		std::cout << ex.displayText() << std::endl;
1341 		return 0;
1342 	}
1343 }
1344