ODBCTest.cpp 26 KB

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