ODBCMySQLTest.cpp 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. //
  2. // ODBCMySQLTest.cpp
  3. //
  4. // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCMySQLTest.cpp#3 $
  5. //
  6. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  7. // and Contributors.
  8. //
  9. // Permission is hereby granted, free of charge, to any person or organization
  10. // obtaining a copy of the software and accompanying documentation covered by
  11. // this license (the "Software") to use, reproduce, display, distribute,
  12. // execute, and transmit the Software, and to prepare derivative works of the
  13. // Software, and to permit third-parties to whom the Software is furnished to
  14. // do so, all subject to the following:
  15. //
  16. // The copyright notices in the Software and this entire statement, including
  17. // the above license grant, this restriction and the following disclaimer,
  18. // must be included in all copies of the Software, in whole or in part, and
  19. // all derivative works of the Software, unless such copies or derivative
  20. // works are solely in the form of machine-executable object code generated by
  21. // a source language processor.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  26. // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  27. // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  28. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. // DEALINGS IN THE SOFTWARE.
  30. //
  31. #include "ODBCMySQLTest.h"
  32. #include "CppUnit/TestCaller.h"
  33. #include "CppUnit/TestSuite.h"
  34. #include "Poco/String.h"
  35. #include "Poco/Format.h"
  36. #include "Poco/Tuple.h"
  37. #include "Poco/Exception.h"
  38. #include "Poco/Data/Common.h"
  39. #include "Poco/Data/BLOB.h"
  40. #include "Poco/Data/StatementImpl.h"
  41. #include "Poco/Data/ODBC/Connector.h"
  42. #include "Poco/Data/ODBC/Utility.h"
  43. #include "Poco/Data/ODBC/Diagnostics.h"
  44. #include "Poco/Data/ODBC/ODBCException.h"
  45. #include "Poco/Data/ODBC/ODBCStatementImpl.h"
  46. #include <sqltypes.h>
  47. #include <iostream>
  48. using namespace Poco::Data;
  49. using Poco::Data::ODBC::Utility;
  50. using Poco::Data::ODBC::ConnectionException;
  51. using Poco::Data::ODBC::StatementException;
  52. using Poco::Data::ODBC::StatementDiagnostics;
  53. using Poco::format;
  54. using Poco::Tuple;
  55. using Poco::NotFoundException;
  56. const bool ODBCMySQLTest::bindValues[8] = {true, true, true, false, false, true, false, false};
  57. Poco::SharedPtr<Poco::Data::Session> ODBCMySQLTest::_pSession = 0;
  58. Poco::SharedPtr<SQLExecutor> ODBCMySQLTest::_pExecutor = 0;
  59. std::string ODBCMySQLTest::_dbConnString;
  60. Poco::Data::ODBC::Utility::DriverMap ODBCMySQLTest::_drivers;
  61. ODBCMySQLTest::ODBCMySQLTest(const std::string& name):
  62. CppUnit::TestCase(name)
  63. {
  64. }
  65. ODBCMySQLTest::~ODBCMySQLTest()
  66. {
  67. }
  68. void ODBCMySQLTest::testBareboneODBC()
  69. {
  70. if (!_pSession) fail ("Test not available.");
  71. std::string tableCreateString = "CREATE TABLE Test "
  72. "(First VARCHAR(30),"
  73. "Second VARCHAR(30),"
  74. "Third VARBINARY(30),"
  75. "Fourth INTEGER,"
  76. "Fifth FLOAT)";
  77. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  78. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  79. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  80. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  81. }
  82. void ODBCMySQLTest::testSimpleAccess()
  83. {
  84. if (!_pSession) fail ("Test not available.");
  85. for (int i = 0; i < 8;)
  86. {
  87. recreatePersonTable();
  88. _pSession->setFeature("autoBind", bindValues[i]);
  89. _pSession->setFeature("autoExtract", bindValues[i+1]);
  90. _pExecutor->simpleAccess();
  91. i += 2;
  92. }
  93. }
  94. void ODBCMySQLTest::testComplexType()
  95. {
  96. if (!_pSession) fail ("Test not available.");
  97. for (int i = 0; i < 8;)
  98. {
  99. recreatePersonTable();
  100. _pSession->setFeature("autoBind", bindValues[i]);
  101. _pSession->setFeature("autoExtract", bindValues[i+1]);
  102. _pExecutor->complexType();
  103. i += 2;
  104. }
  105. }
  106. void ODBCMySQLTest::testSimpleAccessVector()
  107. {
  108. if (!_pSession) fail ("Test not available.");
  109. for (int i = 0; i < 8;)
  110. {
  111. recreatePersonTable();
  112. _pSession->setFeature("autoBind", bindValues[i]);
  113. _pSession->setFeature("autoExtract", bindValues[i+1]);
  114. _pExecutor->simpleAccessVector();
  115. i += 2;
  116. }
  117. }
  118. void ODBCMySQLTest::testComplexTypeVector()
  119. {
  120. if (!_pSession) fail ("Test not available.");
  121. for (int i = 0; i < 8;)
  122. {
  123. recreatePersonTable();
  124. _pSession->setFeature("autoBind", bindValues[i]);
  125. _pSession->setFeature("autoExtract", bindValues[i+1]);
  126. _pExecutor->complexTypeVector();
  127. i += 2;
  128. }
  129. }
  130. void ODBCMySQLTest::testInsertVector()
  131. {
  132. if (!_pSession) fail ("Test not available.");
  133. for (int i = 0; i < 8;)
  134. {
  135. recreateStringsTable();
  136. _pSession->setFeature("autoBind", bindValues[i]);
  137. _pSession->setFeature("autoExtract", bindValues[i+1]);
  138. _pExecutor->insertVector();
  139. i += 2;
  140. }
  141. }
  142. void ODBCMySQLTest::testInsertEmptyVector()
  143. {
  144. if (!_pSession) fail ("Test not available.");
  145. for (int i = 0; i < 8;)
  146. {
  147. recreateStringsTable();
  148. _pSession->setFeature("autoBind", bindValues[i]);
  149. _pSession->setFeature("autoExtract", bindValues[i+1]);
  150. _pExecutor->insertEmptyVector();
  151. i += 2;
  152. }
  153. }
  154. void ODBCMySQLTest::testSimpleAccessList()
  155. {
  156. if (!_pSession) fail ("Test not available.");
  157. for (int i = 0; i < 8;)
  158. {
  159. recreatePersonTable();
  160. _pSession->setFeature("autoBind", bindValues[i]);
  161. _pSession->setFeature("autoExtract", bindValues[i+1]);
  162. _pExecutor->simpleAccessList();
  163. i += 2;
  164. }
  165. }
  166. void ODBCMySQLTest::testComplexTypeList()
  167. {
  168. if (!_pSession) fail ("Test not available.");
  169. for (int i = 0; i < 8;)
  170. {
  171. recreatePersonTable();
  172. _pSession->setFeature("autoBind", bindValues[i]);
  173. _pSession->setFeature("autoExtract", bindValues[i+1]);
  174. _pExecutor->complexTypeList();
  175. i += 2;
  176. }
  177. }
  178. void ODBCMySQLTest::testInsertList()
  179. {
  180. if (!_pSession) fail ("Test not available.");
  181. for (int i = 0; i < 8;)
  182. {
  183. recreateStringsTable();
  184. _pSession->setFeature("autoBind", bindValues[i]);
  185. _pSession->setFeature("autoExtract", bindValues[i+1]);
  186. _pExecutor->insertList();
  187. i += 2;
  188. }
  189. }
  190. void ODBCMySQLTest::testInsertEmptyList()
  191. {
  192. if (!_pSession) fail ("Test not available.");
  193. for (int i = 0; i < 8;)
  194. {
  195. recreateStringsTable();
  196. _pSession->setFeature("autoBind", bindValues[i]);
  197. _pSession->setFeature("autoExtract", bindValues[i+1]);
  198. _pExecutor->insertEmptyList();
  199. i += 2;
  200. }
  201. }
  202. void ODBCMySQLTest::testSimpleAccessDeque()
  203. {
  204. if (!_pSession) fail ("Test not available.");
  205. for (int i = 0; i < 8;)
  206. {
  207. recreatePersonTable();
  208. _pSession->setFeature("autoBind", bindValues[i]);
  209. _pSession->setFeature("autoExtract", bindValues[i+1]);
  210. _pExecutor->simpleAccessDeque();
  211. i += 2;
  212. }
  213. }
  214. void ODBCMySQLTest::testComplexTypeDeque()
  215. {
  216. if (!_pSession) fail ("Test not available.");
  217. for (int i = 0; i < 8;)
  218. {
  219. recreatePersonTable();
  220. _pSession->setFeature("autoBind", bindValues[i]);
  221. _pSession->setFeature("autoExtract", bindValues[i+1]);
  222. _pExecutor->complexTypeDeque();
  223. i += 2;
  224. }
  225. }
  226. void ODBCMySQLTest::testInsertDeque()
  227. {
  228. if (!_pSession) fail ("Test not available.");
  229. for (int i = 0; i < 8;)
  230. {
  231. recreateStringsTable();
  232. _pSession->setFeature("autoBind", bindValues[i]);
  233. _pSession->setFeature("autoExtract", bindValues[i+1]);
  234. _pExecutor->insertDeque();
  235. i += 2;
  236. }
  237. }
  238. void ODBCMySQLTest::testInsertEmptyDeque()
  239. {
  240. if (!_pSession) fail ("Test not available.");
  241. for (int i = 0; i < 8;)
  242. {
  243. recreateStringsTable();
  244. _pSession->setFeature("autoBind", bindValues[i]);
  245. _pSession->setFeature("autoExtract", bindValues[i+1]);
  246. _pExecutor->insertEmptyDeque();
  247. i += 2;
  248. }
  249. }
  250. void ODBCMySQLTest::testInsertSingleBulk()
  251. {
  252. if (!_pSession) fail ("Test not available.");
  253. for (int i = 0; i < 8;)
  254. {
  255. recreateIntsTable();
  256. _pSession->setFeature("autoBind", bindValues[i]);
  257. _pSession->setFeature("autoExtract", bindValues[i+1]);
  258. _pExecutor->insertSingleBulk();
  259. i += 2;
  260. }
  261. }
  262. void ODBCMySQLTest::testInsertSingleBulkVec()
  263. {
  264. if (!_pSession) fail ("Test not available.");
  265. for (int i = 0; i < 8;)
  266. {
  267. recreateIntsTable();
  268. _pSession->setFeature("autoBind", bindValues[i]);
  269. _pSession->setFeature("autoExtract", bindValues[i+1]);
  270. _pExecutor->insertSingleBulkVec();
  271. i += 2;
  272. }
  273. }
  274. void ODBCMySQLTest::testLimit()
  275. {
  276. if (!_pSession) fail ("Test not available.");
  277. for (int i = 0; i < 8;)
  278. {
  279. recreateIntsTable();
  280. _pSession->setFeature("autoBind", bindValues[i]);
  281. _pSession->setFeature("autoExtract", bindValues[i+1]);
  282. _pExecutor->limits();
  283. i += 2;
  284. }
  285. }
  286. void ODBCMySQLTest::testLimitZero()
  287. {
  288. if (!_pSession) fail ("Test not available.");
  289. for (int i = 0; i < 8;)
  290. {
  291. recreateIntsTable();
  292. _pSession->setFeature("autoBind", bindValues[i]);
  293. _pSession->setFeature("autoExtract", bindValues[i+1]);
  294. _pExecutor->limitZero();
  295. i += 2;
  296. }
  297. }
  298. void ODBCMySQLTest::testLimitOnce()
  299. {
  300. if (!_pSession) fail ("Test not available.");
  301. recreateIntsTable();
  302. _pExecutor->limitOnce();
  303. }
  304. void ODBCMySQLTest::testLimitPrepare()
  305. {
  306. if (!_pSession) fail ("Test not available.");
  307. for (int i = 0; i < 8;)
  308. {
  309. recreateIntsTable();
  310. _pSession->setFeature("autoBind", bindValues[i]);
  311. _pSession->setFeature("autoExtract", bindValues[i+1]);
  312. _pExecutor->limitPrepare();
  313. i += 2;
  314. }
  315. }
  316. void ODBCMySQLTest::testPrepare()
  317. {
  318. if (!_pSession) fail ("Test not available.");
  319. for (int i = 0; i < 8;)
  320. {
  321. recreateIntsTable();
  322. _pSession->setFeature("autoBind", bindValues[i]);
  323. _pSession->setFeature("autoExtract", bindValues[i+1]);
  324. _pExecutor->prepare();
  325. i += 2;
  326. }
  327. }
  328. void ODBCMySQLTest::testSetSimple()
  329. {
  330. if (!_pSession) fail ("Test not available.");
  331. for (int i = 0; i < 8;)
  332. {
  333. recreatePersonTable();
  334. _pSession->setFeature("autoBind", bindValues[i]);
  335. _pSession->setFeature("autoExtract", bindValues[i+1]);
  336. _pExecutor->setSimple();
  337. i += 2;
  338. }
  339. }
  340. void ODBCMySQLTest::testSetComplex()
  341. {
  342. if (!_pSession) fail ("Test not available.");
  343. for (int i = 0; i < 8;)
  344. {
  345. recreatePersonTable();
  346. _pSession->setFeature("autoBind", bindValues[i]);
  347. _pSession->setFeature("autoExtract", bindValues[i+1]);
  348. _pExecutor->setComplex();
  349. i += 2;
  350. }
  351. }
  352. void ODBCMySQLTest::testSetComplexUnique()
  353. {
  354. if (!_pSession) fail ("Test not available.");
  355. for (int i = 0; i < 8;)
  356. {
  357. recreatePersonTable();
  358. _pSession->setFeature("autoBind", bindValues[i]);
  359. _pSession->setFeature("autoExtract", bindValues[i+1]);
  360. _pExecutor->setComplexUnique();
  361. i += 2;
  362. }
  363. }
  364. void ODBCMySQLTest::testMultiSetSimple()
  365. {
  366. if (!_pSession) fail ("Test not available.");
  367. for (int i = 0; i < 8;)
  368. {
  369. recreatePersonTable();
  370. _pSession->setFeature("autoBind", bindValues[i]);
  371. _pSession->setFeature("autoExtract", bindValues[i+1]);
  372. _pExecutor->multiSetSimple();
  373. i += 2;
  374. }
  375. }
  376. void ODBCMySQLTest::testMultiSetComplex()
  377. {
  378. if (!_pSession) fail ("Test not available.");
  379. for (int i = 0; i < 8;)
  380. {
  381. recreatePersonTable();
  382. _pSession->setFeature("autoBind", bindValues[i]);
  383. _pSession->setFeature("autoExtract", bindValues[i+1]);
  384. _pExecutor->multiSetComplex();
  385. i += 2;
  386. }
  387. }
  388. void ODBCMySQLTest::testMapComplex()
  389. {
  390. if (!_pSession) fail ("Test not available.");
  391. for (int i = 0; i < 8;)
  392. {
  393. recreatePersonTable();
  394. _pSession->setFeature("autoBind", bindValues[i]);
  395. _pSession->setFeature("autoExtract", bindValues[i+1]);
  396. _pExecutor->mapComplex();
  397. i += 2;
  398. }
  399. }
  400. void ODBCMySQLTest::testMapComplexUnique()
  401. {
  402. if (!_pSession) fail ("Test not available.");
  403. for (int i = 0; i < 8;)
  404. {
  405. recreatePersonTable();
  406. _pSession->setFeature("autoBind", bindValues[i]);
  407. _pSession->setFeature("autoExtract", bindValues[i+1]);
  408. _pExecutor->mapComplexUnique();
  409. i += 2;
  410. }
  411. }
  412. void ODBCMySQLTest::testMultiMapComplex()
  413. {
  414. if (!_pSession) fail ("Test not available.");
  415. for (int i = 0; i < 8;)
  416. {
  417. recreatePersonTable();
  418. _pSession->setFeature("autoBind", bindValues[i]);
  419. _pSession->setFeature("autoExtract", bindValues[i+1]);
  420. _pExecutor->multiMapComplex();
  421. i += 2;
  422. }
  423. }
  424. void ODBCMySQLTest::testSelectIntoSingle()
  425. {
  426. if (!_pSession) fail ("Test not available.");
  427. for (int i = 0; i < 8;)
  428. {
  429. recreatePersonTable();
  430. _pSession->setFeature("autoBind", bindValues[i]);
  431. _pSession->setFeature("autoExtract", bindValues[i+1]);
  432. _pExecutor->selectIntoSingle();
  433. i += 2;
  434. }
  435. }
  436. void ODBCMySQLTest::testSelectIntoSingleStep()
  437. {
  438. if (!_pSession) fail ("Test not available.");
  439. for (int i = 0; i < 8;)
  440. {
  441. recreatePersonTable();
  442. _pSession->setFeature("autoBind", bindValues[i]);
  443. _pSession->setFeature("autoExtract", bindValues[i+1]);
  444. _pExecutor->selectIntoSingleStep();
  445. i += 2;
  446. }
  447. }
  448. void ODBCMySQLTest::testSelectIntoSingleFail()
  449. {
  450. if (!_pSession) fail ("Test not available.");
  451. for (int i = 0; i < 8;)
  452. {
  453. recreatePersonTable();
  454. _pSession->setFeature("autoBind", bindValues[i]);
  455. _pSession->setFeature("autoExtract", bindValues[i+1]);
  456. _pExecutor->selectIntoSingleFail();
  457. i += 2;
  458. }
  459. }
  460. void ODBCMySQLTest::testLowerLimitOk()
  461. {
  462. if (!_pSession) fail ("Test not available.");
  463. for (int i = 0; i < 8;)
  464. {
  465. recreatePersonTable();
  466. _pSession->setFeature("autoBind", bindValues[i]);
  467. _pSession->setFeature("autoExtract", bindValues[i+1]);
  468. _pExecutor->lowerLimitOk();
  469. i += 2;
  470. }
  471. }
  472. void ODBCMySQLTest::testSingleSelect()
  473. {
  474. if (!_pSession) fail ("Test not available.");
  475. for (int i = 0; i < 8;)
  476. {
  477. recreatePersonTable();
  478. _pSession->setFeature("autoBind", bindValues[i]);
  479. _pSession->setFeature("autoExtract", bindValues[i+1]);
  480. _pExecutor->singleSelect();
  481. i += 2;
  482. }
  483. }
  484. void ODBCMySQLTest::testLowerLimitFail()
  485. {
  486. if (!_pSession) fail ("Test not available.");
  487. for (int i = 0; i < 8;)
  488. {
  489. recreatePersonTable();
  490. _pSession->setFeature("autoBind", bindValues[i]);
  491. _pSession->setFeature("autoExtract", bindValues[i+1]);
  492. _pExecutor->lowerLimitFail();
  493. i += 2;
  494. }
  495. }
  496. void ODBCMySQLTest::testCombinedLimits()
  497. {
  498. if (!_pSession) fail ("Test not available.");
  499. for (int i = 0; i < 8;)
  500. {
  501. recreatePersonTable();
  502. _pSession->setFeature("autoBind", bindValues[i]);
  503. _pSession->setFeature("autoExtract", bindValues[i+1]);
  504. _pExecutor->combinedLimits();
  505. i += 2;
  506. }
  507. }
  508. void ODBCMySQLTest::testRange()
  509. {
  510. if (!_pSession) fail ("Test not available.");
  511. for (int i = 0; i < 8;)
  512. {
  513. recreatePersonTable();
  514. _pSession->setFeature("autoBind", bindValues[i]);
  515. _pSession->setFeature("autoExtract", bindValues[i+1]);
  516. _pExecutor->ranges();
  517. i += 2;
  518. }
  519. }
  520. void ODBCMySQLTest::testCombinedIllegalLimits()
  521. {
  522. if (!_pSession) fail ("Test not available.");
  523. for (int i = 0; i < 8;)
  524. {
  525. recreatePersonTable();
  526. _pSession->setFeature("autoBind", bindValues[i]);
  527. _pSession->setFeature("autoExtract", bindValues[i+1]);
  528. _pExecutor->combinedIllegalLimits();
  529. i += 2;
  530. }
  531. }
  532. void ODBCMySQLTest::testIllegalRange()
  533. {
  534. if (!_pSession) fail ("Test not available.");
  535. for (int i = 0; i < 8;)
  536. {
  537. recreatePersonTable();
  538. _pSession->setFeature("autoBind", bindValues[i]);
  539. _pSession->setFeature("autoExtract", bindValues[i+1]);
  540. _pExecutor->illegalRange();
  541. i += 2;
  542. }
  543. }
  544. void ODBCMySQLTest::testEmptyDB()
  545. {
  546. if (!_pSession) fail ("Test not available.");
  547. for (int i = 0; i < 8;)
  548. {
  549. recreatePersonTable();
  550. _pSession->setFeature("autoBind", bindValues[i]);
  551. _pSession->setFeature("autoExtract", bindValues[i+1]);
  552. _pExecutor->emptyDB();
  553. i += 2;
  554. }
  555. }
  556. void ODBCMySQLTest::testBLOB()
  557. {
  558. if (!_pSession) fail ("Test not available.");
  559. const std::size_t maxFldSize = 65534;
  560. _pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
  561. recreatePersonBLOBTable();
  562. try
  563. {
  564. _pExecutor->blob(maxFldSize);
  565. fail ("must fail");
  566. }
  567. catch (DataException&)
  568. {
  569. _pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
  570. }
  571. for (int i = 0; i < 8;)
  572. {
  573. recreatePersonBLOBTable();
  574. _pSession->setFeature("autoBind", bindValues[i]);
  575. _pSession->setFeature("autoExtract", bindValues[i+1]);
  576. _pExecutor->blob(maxFldSize);
  577. i += 2;
  578. }
  579. recreatePersonBLOBTable();
  580. try
  581. {
  582. _pExecutor->blob(maxFldSize+1);
  583. fail ("must fail");
  584. }
  585. catch (DataException&) { }
  586. }
  587. void ODBCMySQLTest::testBLOBStmt()
  588. {
  589. if (!_pSession) fail ("Test not available.");
  590. for (int i = 0; i < 8;)
  591. {
  592. recreatePersonBLOBTable();
  593. _pSession->setFeature("autoBind", bindValues[i]);
  594. _pSession->setFeature("autoExtract", bindValues[i+1]);
  595. _pExecutor->blobStmt();
  596. i += 2;
  597. }
  598. }
  599. void ODBCMySQLTest::testFloat()
  600. {
  601. if (!_pSession) fail ("Test not available.");
  602. for (int i = 0; i < 8;)
  603. {
  604. recreateFloatsTable();
  605. _pSession->setFeature("autoBind", bindValues[i]);
  606. _pSession->setFeature("autoExtract", bindValues[i+1]);
  607. _pExecutor->floats();
  608. i += 2;
  609. }
  610. }
  611. void ODBCMySQLTest::testDouble()
  612. {
  613. if (!_pSession) fail ("Test not available.");
  614. for (int i = 0; i < 8;)
  615. {
  616. recreateFloatsTable();
  617. _pSession->setFeature("autoBind", bindValues[i]);
  618. _pSession->setFeature("autoExtract", bindValues[i+1]);
  619. _pExecutor->doubles();
  620. i += 2;
  621. }
  622. }
  623. void ODBCMySQLTest::testTuple()
  624. {
  625. if (!_pSession) fail ("Test not available.");
  626. for (int i = 0; i < 8;)
  627. {
  628. recreateTuplesTable();
  629. _pSession->setFeature("autoBind", bindValues[i]);
  630. _pSession->setFeature("autoExtract", bindValues[i+1]);
  631. _pExecutor->tuples();
  632. i += 2;
  633. }
  634. }
  635. void ODBCMySQLTest::testTupleVector()
  636. {
  637. if (!_pSession) fail ("Test not available.");
  638. for (int i = 0; i < 8;)
  639. {
  640. recreateTuplesTable();
  641. _pSession->setFeature("autoBind", bindValues[i]);
  642. _pSession->setFeature("autoExtract", bindValues[i+1]);
  643. _pExecutor->tupleVector();
  644. i += 2;
  645. }
  646. }
  647. void ODBCMySQLTest::testInternalExtraction()
  648. {
  649. if (!_pSession) fail ("Test not available.");
  650. for (int i = 0; i < 8;)
  651. {
  652. recreateVectorsTable();
  653. _pSession->setFeature("autoBind", bindValues[i]);
  654. _pSession->setFeature("autoExtract", bindValues[i+1]);
  655. _pExecutor->internalExtraction();
  656. i += 2;
  657. }
  658. }
  659. void ODBCMySQLTest::testInternalStorageType()
  660. {
  661. if (!_pSession) fail ("Test not available.");
  662. for (int i = 0; i < 8;)
  663. {
  664. recreateVectorsTable();
  665. _pSession->setFeature("autoBind", bindValues[i]);
  666. _pSession->setFeature("autoExtract", bindValues[i+1]);
  667. _pExecutor->internalStorageType();
  668. i += 2;
  669. }
  670. }
  671. void ODBCMySQLTest::testStoredProcedure()
  672. {
  673. //MySQL is currently buggy in this area:
  674. // http://bugs.mysql.com/bug.php?id=17898
  675. // http://bugs.mysql.com/bug.php?id=27632
  676. }
  677. void ODBCMySQLTest::testStoredFunction()
  678. {
  679. //MySQL is currently buggy in this area:
  680. // http://bugs.mysql.com/bug.php?id=17898
  681. // http://bugs.mysql.com/bug.php?id=27632
  682. }
  683. void ODBCMySQLTest::dropObject(const std::string& type, const std::string& name)
  684. {
  685. *_pSession << format("DROP %s IF EXISTS %s", type, name), now;
  686. }
  687. void ODBCMySQLTest::recreatePersonTable()
  688. {
  689. dropObject("TABLE", "Person");
  690. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
  691. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
  692. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
  693. }
  694. void ODBCMySQLTest::recreatePersonBLOBTable()
  695. {
  696. dropObject("TABLE", "Person");
  697. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
  698. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  699. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  700. }
  701. void ODBCMySQLTest::recreateIntsTable()
  702. {
  703. dropObject("TABLE", "Strings");
  704. try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
  705. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
  706. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
  707. }
  708. void ODBCMySQLTest::recreateStringsTable()
  709. {
  710. dropObject("TABLE", "Strings");
  711. try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
  712. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
  713. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
  714. }
  715. void ODBCMySQLTest::recreateFloatsTable()
  716. {
  717. dropObject("TABLE", "Strings");
  718. try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
  719. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
  720. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
  721. }
  722. void ODBCMySQLTest::recreateTuplesTable()
  723. {
  724. dropObject("TABLE", "Tuples");
  725. try { *_pSession << "CREATE TABLE Tuples "
  726. "(i0 INTEGER, i1 INTEGER, i2 INTEGER, i3 INTEGER, i4 INTEGER, i5 INTEGER, i6 INTEGER, "
  727. "i7 INTEGER, i8 INTEGER, i9 INTEGER, i10 INTEGER, i11 INTEGER, i12 INTEGER, i13 INTEGER,"
  728. "i14 INTEGER, i15 INTEGER, i16 INTEGER, i17 INTEGER, i18 INTEGER, i19 INTEGER)", now; }
  729. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
  730. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
  731. }
  732. void ODBCMySQLTest::recreateVectorsTable()
  733. {
  734. dropObject("TABLE", "Vectors");
  735. try { *_pSession << "CREATE TABLE Vectors (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
  736. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
  737. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
  738. }
  739. bool ODBCMySQLTest::canConnect(const std::string& driver, const std::string& dsn)
  740. {
  741. Utility::DriverMap::iterator itDrv = _drivers.begin();
  742. for (; itDrv != _drivers.end(); ++itDrv)
  743. {
  744. if (((itDrv->first).find(driver) != std::string::npos))
  745. {
  746. std::cout << "Driver found: " << itDrv->first
  747. << " (" << itDrv->second << ')' << std::endl;
  748. break;
  749. }
  750. }
  751. if (_drivers.end() == itDrv)
  752. {
  753. std::cout << driver << " driver NOT found, tests not available." << std::endl;
  754. return false;
  755. }
  756. Utility::DSNMap dataSources;
  757. Utility::dataSources(dataSources);
  758. Utility::DSNMap::iterator itDSN = dataSources.begin();
  759. for (; itDSN != dataSources.end(); ++itDSN)
  760. {
  761. if (itDSN->first == dsn && itDSN->second == driver)
  762. {
  763. std::cout << "DSN found: " << itDSN->first
  764. << " (" << itDSN->second << ')' << std::endl;
  765. format(_dbConnString, "DSN=%s", dsn);
  766. return true;
  767. }
  768. }
  769. // DSN not found, try connect without it
  770. format(_dbConnString, "DRIVER=%s;"
  771. "DATABASE=test;"
  772. "SERVER=localhost;"
  773. "UID=root;"
  774. "PWD=mysql;", driver);
  775. return true;
  776. }
  777. void ODBCMySQLTest::setUp()
  778. {
  779. }
  780. void ODBCMySQLTest::tearDown()
  781. {
  782. dropObject("TABLE", "Person");
  783. dropObject("TABLE", "Strings");
  784. dropObject("TABLE", "Tuples");
  785. }
  786. bool ODBCMySQLTest::init(const std::string& driver, const std::string& dsn)
  787. {
  788. Utility::drivers(_drivers);
  789. if (!canConnect(driver, dsn)) return false;
  790. ODBC::Connector::registerConnector();
  791. try
  792. {
  793. _pSession = new Session(ODBC::Connector::KEY, _dbConnString);
  794. }catch (ConnectionException& ex)
  795. {
  796. std::cout << ex.toString() << std::endl;
  797. return false;
  798. }
  799. if (_pSession && _pSession->isConnected())
  800. std::cout << "*** Connected to [" << driver << "] test database." << std::endl;
  801. _pExecutor = new SQLExecutor(driver + " SQL Executor", _pSession);
  802. return true;
  803. }
  804. CppUnit::Test* ODBCMySQLTest::suite()
  805. {
  806. #ifdef POCO_OS_FAMILY_WINDOWS
  807. if (init("MySQL ODBC 3.51 Driver", "PocoDataMySQLTest"))
  808. #else
  809. if (init("MySQL", "PocoDataMySQLTest"))
  810. #endif
  811. {
  812. CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest");
  813. CppUnit_addTest(pSuite, ODBCMySQLTest, testBareboneODBC);
  814. CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccess);
  815. CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexType);
  816. CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessVector);
  817. CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeVector);
  818. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertVector);
  819. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyVector);
  820. CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessList);
  821. CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeList);
  822. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertList);
  823. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyList);
  824. CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessDeque);
  825. CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeDeque);
  826. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertDeque);
  827. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyDeque);
  828. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulk);
  829. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulkVec);
  830. CppUnit_addTest(pSuite, ODBCMySQLTest, testLimit);
  831. CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitOnce);
  832. CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitPrepare);
  833. CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitZero);
  834. CppUnit_addTest(pSuite, ODBCMySQLTest, testPrepare);
  835. CppUnit_addTest(pSuite, ODBCMySQLTest, testSetSimple);
  836. CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplex);
  837. CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplexUnique);
  838. CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetSimple);
  839. CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetComplex);
  840. CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplex);
  841. CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplexUnique);
  842. CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiMapComplex);
  843. CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingle);
  844. CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleStep);
  845. CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleFail);
  846. CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitOk);
  847. CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitFail);
  848. CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedLimits);
  849. CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedIllegalLimits);
  850. CppUnit_addTest(pSuite, ODBCMySQLTest, testRange);
  851. CppUnit_addTest(pSuite, ODBCMySQLTest, testIllegalRange);
  852. CppUnit_addTest(pSuite, ODBCMySQLTest, testSingleSelect);
  853. CppUnit_addTest(pSuite, ODBCMySQLTest, testEmptyDB);
  854. CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOB);
  855. CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOBStmt);
  856. CppUnit_addTest(pSuite, ODBCMySQLTest, testFloat);
  857. CppUnit_addTest(pSuite, ODBCMySQLTest, testDouble);
  858. CppUnit_addTest(pSuite, ODBCMySQLTest, testTuple);
  859. CppUnit_addTest(pSuite, ODBCMySQLTest, testTupleVector);
  860. CppUnit_addTest(pSuite, ODBCMySQLTest, testStoredProcedure);
  861. CppUnit_addTest(pSuite, ODBCMySQLTest, testStoredFunction);
  862. CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalExtraction);
  863. CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalStorageType);
  864. return pSuite;
  865. }
  866. return 0;
  867. }