ODBCMySQLTest.cpp 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. //
  2. // ODBCMySQLTest.cpp
  3. //
  4. // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCMySQLTest.cpp#5 $
  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. "Sixth DATETIME)";
  78. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  79. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  80. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  81. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  82. tableCreateString = "CREATE TABLE Test "
  83. "(First VARCHAR(30),"
  84. "Second VARCHAR(30),"
  85. "Third VARBINARY(30),"
  86. "Fourth INTEGER,"
  87. "Fifth FLOAT,"
  88. "Sixth DATE)";
  89. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL, false);
  90. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND, false);
  91. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL, false);
  92. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND, false);
  93. }
  94. void ODBCMySQLTest::testSimpleAccess()
  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->simpleAccess();
  103. i += 2;
  104. }
  105. }
  106. void ODBCMySQLTest::testComplexType()
  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->complexType();
  115. i += 2;
  116. }
  117. }
  118. void ODBCMySQLTest::testSimpleAccessVector()
  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->simpleAccessVector();
  127. i += 2;
  128. }
  129. }
  130. void ODBCMySQLTest::testComplexTypeVector()
  131. {
  132. if (!_pSession) fail ("Test not available.");
  133. for (int i = 0; i < 8;)
  134. {
  135. recreatePersonTable();
  136. _pSession->setFeature("autoBind", bindValues[i]);
  137. _pSession->setFeature("autoExtract", bindValues[i+1]);
  138. _pExecutor->complexTypeVector();
  139. i += 2;
  140. }
  141. }
  142. void ODBCMySQLTest::testInsertVector()
  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->insertVector();
  151. i += 2;
  152. }
  153. }
  154. void ODBCMySQLTest::testInsertEmptyVector()
  155. {
  156. if (!_pSession) fail ("Test not available.");
  157. for (int i = 0; i < 8;)
  158. {
  159. recreateStringsTable();
  160. _pSession->setFeature("autoBind", bindValues[i]);
  161. _pSession->setFeature("autoExtract", bindValues[i+1]);
  162. _pExecutor->insertEmptyVector();
  163. i += 2;
  164. }
  165. }
  166. void ODBCMySQLTest::testSimpleAccessList()
  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->simpleAccessList();
  175. i += 2;
  176. }
  177. }
  178. void ODBCMySQLTest::testComplexTypeList()
  179. {
  180. if (!_pSession) fail ("Test not available.");
  181. for (int i = 0; i < 8;)
  182. {
  183. recreatePersonTable();
  184. _pSession->setFeature("autoBind", bindValues[i]);
  185. _pSession->setFeature("autoExtract", bindValues[i+1]);
  186. _pExecutor->complexTypeList();
  187. i += 2;
  188. }
  189. }
  190. void ODBCMySQLTest::testInsertList()
  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->insertList();
  199. i += 2;
  200. }
  201. }
  202. void ODBCMySQLTest::testInsertEmptyList()
  203. {
  204. if (!_pSession) fail ("Test not available.");
  205. for (int i = 0; i < 8;)
  206. {
  207. recreateStringsTable();
  208. _pSession->setFeature("autoBind", bindValues[i]);
  209. _pSession->setFeature("autoExtract", bindValues[i+1]);
  210. _pExecutor->insertEmptyList();
  211. i += 2;
  212. }
  213. }
  214. void ODBCMySQLTest::testSimpleAccessDeque()
  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->simpleAccessDeque();
  223. i += 2;
  224. }
  225. }
  226. void ODBCMySQLTest::testComplexTypeDeque()
  227. {
  228. if (!_pSession) fail ("Test not available.");
  229. for (int i = 0; i < 8;)
  230. {
  231. recreatePersonTable();
  232. _pSession->setFeature("autoBind", bindValues[i]);
  233. _pSession->setFeature("autoExtract", bindValues[i+1]);
  234. _pExecutor->complexTypeDeque();
  235. i += 2;
  236. }
  237. }
  238. void ODBCMySQLTest::testInsertDeque()
  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->insertDeque();
  247. i += 2;
  248. }
  249. }
  250. void ODBCMySQLTest::testInsertEmptyDeque()
  251. {
  252. if (!_pSession) fail ("Test not available.");
  253. for (int i = 0; i < 8;)
  254. {
  255. recreateStringsTable();
  256. _pSession->setFeature("autoBind", bindValues[i]);
  257. _pSession->setFeature("autoExtract", bindValues[i+1]);
  258. _pExecutor->insertEmptyDeque();
  259. i += 2;
  260. }
  261. }
  262. void ODBCMySQLTest::testInsertSingleBulk()
  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->insertSingleBulk();
  271. i += 2;
  272. }
  273. }
  274. void ODBCMySQLTest::testInsertSingleBulkVec()
  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->insertSingleBulkVec();
  283. i += 2;
  284. }
  285. }
  286. void ODBCMySQLTest::testLimit()
  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->limits();
  295. i += 2;
  296. }
  297. }
  298. void ODBCMySQLTest::testLimitZero()
  299. {
  300. if (!_pSession) fail ("Test not available.");
  301. for (int i = 0; i < 8;)
  302. {
  303. recreateIntsTable();
  304. _pSession->setFeature("autoBind", bindValues[i]);
  305. _pSession->setFeature("autoExtract", bindValues[i+1]);
  306. _pExecutor->limitZero();
  307. i += 2;
  308. }
  309. }
  310. void ODBCMySQLTest::testLimitOnce()
  311. {
  312. if (!_pSession) fail ("Test not available.");
  313. recreateIntsTable();
  314. _pExecutor->limitOnce();
  315. }
  316. void ODBCMySQLTest::testLimitPrepare()
  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->limitPrepare();
  325. i += 2;
  326. }
  327. }
  328. void ODBCMySQLTest::testPrepare()
  329. {
  330. if (!_pSession) fail ("Test not available.");
  331. for (int i = 0; i < 8;)
  332. {
  333. recreateIntsTable();
  334. _pSession->setFeature("autoBind", bindValues[i]);
  335. _pSession->setFeature("autoExtract", bindValues[i+1]);
  336. _pExecutor->prepare();
  337. i += 2;
  338. }
  339. }
  340. void ODBCMySQLTest::testSetSimple()
  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->setSimple();
  349. i += 2;
  350. }
  351. }
  352. void ODBCMySQLTest::testSetComplex()
  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->setComplex();
  361. i += 2;
  362. }
  363. }
  364. void ODBCMySQLTest::testSetComplexUnique()
  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->setComplexUnique();
  373. i += 2;
  374. }
  375. }
  376. void ODBCMySQLTest::testMultiSetSimple()
  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->multiSetSimple();
  385. i += 2;
  386. }
  387. }
  388. void ODBCMySQLTest::testMultiSetComplex()
  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->multiSetComplex();
  397. i += 2;
  398. }
  399. }
  400. void ODBCMySQLTest::testMapComplex()
  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->mapComplex();
  409. i += 2;
  410. }
  411. }
  412. void ODBCMySQLTest::testMapComplexUnique()
  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->mapComplexUnique();
  421. i += 2;
  422. }
  423. }
  424. void ODBCMySQLTest::testMultiMapComplex()
  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->multiMapComplex();
  433. i += 2;
  434. }
  435. }
  436. void ODBCMySQLTest::testSelectIntoSingle()
  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->selectIntoSingle();
  445. i += 2;
  446. }
  447. }
  448. void ODBCMySQLTest::testSelectIntoSingleStep()
  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->selectIntoSingleStep();
  457. i += 2;
  458. }
  459. }
  460. void ODBCMySQLTest::testSelectIntoSingleFail()
  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->selectIntoSingleFail();
  469. i += 2;
  470. }
  471. }
  472. void ODBCMySQLTest::testLowerLimitOk()
  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->lowerLimitOk();
  481. i += 2;
  482. }
  483. }
  484. void ODBCMySQLTest::testSingleSelect()
  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->singleSelect();
  493. i += 2;
  494. }
  495. }
  496. void ODBCMySQLTest::testLowerLimitFail()
  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->lowerLimitFail();
  505. i += 2;
  506. }
  507. }
  508. void ODBCMySQLTest::testCombinedLimits()
  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->combinedLimits();
  517. i += 2;
  518. }
  519. }
  520. void ODBCMySQLTest::testRange()
  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->ranges();
  529. i += 2;
  530. }
  531. }
  532. void ODBCMySQLTest::testCombinedIllegalLimits()
  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->combinedIllegalLimits();
  541. i += 2;
  542. }
  543. }
  544. void ODBCMySQLTest::testIllegalRange()
  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->illegalRange();
  553. i += 2;
  554. }
  555. }
  556. void ODBCMySQLTest::testEmptyDB()
  557. {
  558. if (!_pSession) fail ("Test not available.");
  559. for (int i = 0; i < 8;)
  560. {
  561. recreatePersonTable();
  562. _pSession->setFeature("autoBind", bindValues[i]);
  563. _pSession->setFeature("autoExtract", bindValues[i+1]);
  564. _pExecutor->emptyDB();
  565. i += 2;
  566. }
  567. }
  568. void ODBCMySQLTest::testBLOB()
  569. {
  570. if (!_pSession) fail ("Test not available.");
  571. const std::size_t maxFldSize = 65534;
  572. _pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
  573. recreatePersonBLOBTable();
  574. try
  575. {
  576. _pExecutor->blob(maxFldSize);
  577. fail ("must fail");
  578. }
  579. catch (DataException&)
  580. {
  581. _pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
  582. }
  583. for (int i = 0; i < 8;)
  584. {
  585. recreatePersonBLOBTable();
  586. _pSession->setFeature("autoBind", bindValues[i]);
  587. _pSession->setFeature("autoExtract", bindValues[i+1]);
  588. _pExecutor->blob(maxFldSize);
  589. i += 2;
  590. }
  591. recreatePersonBLOBTable();
  592. try
  593. {
  594. _pExecutor->blob(maxFldSize+1);
  595. fail ("must fail");
  596. }
  597. catch (DataException&) { }
  598. }
  599. void ODBCMySQLTest::testBLOBStmt()
  600. {
  601. if (!_pSession) fail ("Test not available.");
  602. for (int i = 0; i < 8;)
  603. {
  604. recreatePersonBLOBTable();
  605. _pSession->setFeature("autoBind", bindValues[i]);
  606. _pSession->setFeature("autoExtract", bindValues[i+1]);
  607. _pExecutor->blobStmt();
  608. i += 2;
  609. }
  610. }
  611. void ODBCMySQLTest::testDateTime()
  612. {
  613. if (!_pSession) fail ("Test not available.");
  614. for (int i = 0; i < 8;)
  615. {
  616. recreatePersonDateTimeTable();
  617. _pSession->setFeature("autoBind", bindValues[i]);
  618. _pSession->setFeature("autoExtract", bindValues[i+1]);
  619. _pExecutor->dateTime();
  620. i += 2;
  621. }
  622. }
  623. void ODBCMySQLTest::testFloat()
  624. {
  625. if (!_pSession) fail ("Test not available.");
  626. for (int i = 0; i < 8;)
  627. {
  628. recreateFloatsTable();
  629. _pSession->setFeature("autoBind", bindValues[i]);
  630. _pSession->setFeature("autoExtract", bindValues[i+1]);
  631. _pExecutor->floats();
  632. i += 2;
  633. }
  634. }
  635. void ODBCMySQLTest::testDouble()
  636. {
  637. if (!_pSession) fail ("Test not available.");
  638. for (int i = 0; i < 8;)
  639. {
  640. recreateFloatsTable();
  641. _pSession->setFeature("autoBind", bindValues[i]);
  642. _pSession->setFeature("autoExtract", bindValues[i+1]);
  643. _pExecutor->doubles();
  644. i += 2;
  645. }
  646. }
  647. void ODBCMySQLTest::testTuple()
  648. {
  649. if (!_pSession) fail ("Test not available.");
  650. for (int i = 0; i < 8;)
  651. {
  652. recreateTuplesTable();
  653. _pSession->setFeature("autoBind", bindValues[i]);
  654. _pSession->setFeature("autoExtract", bindValues[i+1]);
  655. _pExecutor->tuples();
  656. i += 2;
  657. }
  658. }
  659. void ODBCMySQLTest::testTupleVector()
  660. {
  661. if (!_pSession) fail ("Test not available.");
  662. for (int i = 0; i < 8;)
  663. {
  664. recreateTuplesTable();
  665. _pSession->setFeature("autoBind", bindValues[i]);
  666. _pSession->setFeature("autoExtract", bindValues[i+1]);
  667. _pExecutor->tupleVector();
  668. i += 2;
  669. }
  670. }
  671. void ODBCMySQLTest::testInternalExtraction()
  672. {
  673. if (!_pSession) fail ("Test not available.");
  674. for (int i = 0; i < 8;)
  675. {
  676. recreateVectorsTable();
  677. _pSession->setFeature("autoBind", bindValues[i]);
  678. _pSession->setFeature("autoExtract", bindValues[i+1]);
  679. _pExecutor->internalExtraction();
  680. i += 2;
  681. }
  682. }
  683. void ODBCMySQLTest::testInternalStorageType()
  684. {
  685. if (!_pSession) fail ("Test not available.");
  686. for (int i = 0; i < 8;)
  687. {
  688. recreateVectorsTable();
  689. _pSession->setFeature("autoBind", bindValues[i]);
  690. _pSession->setFeature("autoExtract", bindValues[i+1]);
  691. _pExecutor->internalStorageType();
  692. i += 2;
  693. }
  694. }
  695. void ODBCMySQLTest::testNull()
  696. {
  697. if (!_pSession) fail ("Test not available.");
  698. // test for NOT NULL violation exception
  699. for (int i = 0; i < 8;)
  700. {
  701. recreateNullsTable("NOT NULL");
  702. _pSession->setFeature("autoBind", bindValues[i]);
  703. _pSession->setFeature("autoExtract", bindValues[i+1]);
  704. _pExecutor->notNulls("HYT00");
  705. i += 2;
  706. }
  707. // test for null insertion
  708. for (int i = 0; i < 8;)
  709. {
  710. recreateNullsTable();
  711. _pSession->setFeature("autoBind", bindValues[i]);
  712. _pSession->setFeature("autoExtract", bindValues[i+1]);
  713. _pExecutor->nulls();
  714. i += 2;
  715. }
  716. }
  717. void ODBCMySQLTest::testStoredProcedure()
  718. {
  719. //MySQL is currently buggy in this area:
  720. // http://bugs.mysql.com/bug.php?id=17898
  721. // http://bugs.mysql.com/bug.php?id=27632
  722. // Additionally, the standard ODBC stored procedure call syntax
  723. // {call storedProcedure(?)} is currently (3.51.12.00) not supported.
  724. // See http://bugs.mysql.com/bug.php?id=26535
  725. // Poco::Data support for MySQL ODBC is postponed until the above
  726. // issues are resolved.
  727. }
  728. void ODBCMySQLTest::testStoredFunction()
  729. {
  730. //MySQL is currently buggy in this area:
  731. // http://bugs.mysql.com/bug.php?id=17898
  732. // http://bugs.mysql.com/bug.php?id=27632
  733. // Additionally, the standard ODBC stored procedure call syntax
  734. // {call storedProcedure(?)} is currently (3.51.12.00) not supported.
  735. // See http://bugs.mysql.com/bug.php?id=26535
  736. // Poco::Data support for MySQL ODBC is postponed until the above
  737. // issues are resolved.
  738. }
  739. void ODBCMySQLTest::testRowIterator()
  740. {
  741. if (!_pSession) fail ("Test not available.");
  742. for (int i = 0; i < 8;)
  743. {
  744. recreateVectorsTable();
  745. _pSession->setFeature("autoBind", bindValues[i]);
  746. _pSession->setFeature("autoExtract", bindValues[i+1]);
  747. _pExecutor->rowIterator();
  748. i += 2;
  749. }
  750. }
  751. void ODBCMySQLTest::dropObject(const std::string& type, const std::string& name)
  752. {
  753. *_pSession << format("DROP %s IF EXISTS %s", type, name), now;
  754. }
  755. void ODBCMySQLTest::recreatePersonTable()
  756. {
  757. dropObject("TABLE", "Person");
  758. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
  759. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
  760. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
  761. }
  762. void ODBCMySQLTest::recreatePersonBLOBTable()
  763. {
  764. dropObject("TABLE", "Person");
  765. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
  766. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  767. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  768. }
  769. void ODBCMySQLTest::recreatePersonDateTimeTable()
  770. {
  771. dropObject("TABLE", "Person");
  772. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born DATETIME)", now; }
  773. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
  774. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
  775. }
  776. void ODBCMySQLTest::recreateIntsTable()
  777. {
  778. dropObject("TABLE", "Strings");
  779. try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
  780. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
  781. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
  782. }
  783. void ODBCMySQLTest::recreateStringsTable()
  784. {
  785. dropObject("TABLE", "Strings");
  786. try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
  787. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
  788. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
  789. }
  790. void ODBCMySQLTest::recreateFloatsTable()
  791. {
  792. dropObject("TABLE", "Strings");
  793. try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
  794. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
  795. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
  796. }
  797. void ODBCMySQLTest::recreateTuplesTable()
  798. {
  799. dropObject("TABLE", "Tuples");
  800. try { *_pSession << "CREATE TABLE Tuples "
  801. "(i0 INTEGER, i1 INTEGER, i2 INTEGER, i3 INTEGER, i4 INTEGER, i5 INTEGER, i6 INTEGER, "
  802. "i7 INTEGER, i8 INTEGER, i9 INTEGER, i10 INTEGER, i11 INTEGER, i12 INTEGER, i13 INTEGER,"
  803. "i14 INTEGER, i15 INTEGER, i16 INTEGER, i17 INTEGER, i18 INTEGER, i19 INTEGER)", now; }
  804. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
  805. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
  806. }
  807. void ODBCMySQLTest::recreateVectorsTable()
  808. {
  809. dropObject("TABLE", "Vectors");
  810. try { *_pSession << "CREATE TABLE Vectors (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
  811. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
  812. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
  813. }
  814. void ODBCMySQLTest::recreateNullsTable(const std::string& notNull)
  815. {
  816. dropObject("TABLE", "NullTest");
  817. try { *_pSession << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
  818. notNull,
  819. notNull,
  820. notNull), now; }
  821. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
  822. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
  823. }
  824. bool ODBCMySQLTest::canConnect(const std::string& driver, const std::string& dsn)
  825. {
  826. Utility::DriverMap::iterator itDrv = _drivers.begin();
  827. for (; itDrv != _drivers.end(); ++itDrv)
  828. {
  829. if (((itDrv->first).find(driver) != std::string::npos))
  830. {
  831. std::cout << "Driver found: " << itDrv->first
  832. << " (" << itDrv->second << ')' << std::endl;
  833. break;
  834. }
  835. }
  836. if (_drivers.end() == itDrv)
  837. {
  838. std::cout << driver << " driver NOT found, tests not available." << std::endl;
  839. return false;
  840. }
  841. Utility::DSNMap dataSources;
  842. Utility::dataSources(dataSources);
  843. Utility::DSNMap::iterator itDSN = dataSources.begin();
  844. for (; itDSN != dataSources.end(); ++itDSN)
  845. {
  846. if (itDSN->first == dsn && itDSN->second == driver)
  847. {
  848. std::cout << "DSN found: " << itDSN->first
  849. << " (" << itDSN->second << ')' << std::endl;
  850. format(_dbConnString, "DSN=%s", dsn);
  851. return true;
  852. }
  853. }
  854. // DSN not found, try connect without it
  855. format(_dbConnString, "DRIVER=%s;"
  856. "DATABASE=test;"
  857. "SERVER=localhost;"
  858. "UID=root;"
  859. "PWD=mysql;", driver);
  860. return true;
  861. }
  862. void ODBCMySQLTest::setUp()
  863. {
  864. }
  865. void ODBCMySQLTest::tearDown()
  866. {
  867. dropObject("TABLE", "Person");
  868. dropObject("TABLE", "Strings");
  869. dropObject("TABLE", "Tuples");
  870. }
  871. bool ODBCMySQLTest::init(const std::string& driver, const std::string& dsn)
  872. {
  873. Utility::drivers(_drivers);
  874. if (!canConnect(driver, dsn)) return false;
  875. ODBC::Connector::registerConnector();
  876. try
  877. {
  878. _pSession = new Session(ODBC::Connector::KEY, _dbConnString);
  879. }catch (ConnectionException& ex)
  880. {
  881. std::cout << ex.toString() << std::endl;
  882. return false;
  883. }
  884. if (_pSession && _pSession->isConnected())
  885. std::cout << "*** Connected to [" << driver << "] test database." << std::endl;
  886. _pExecutor = new SQLExecutor(driver + " SQL Executor", _pSession);
  887. return true;
  888. }
  889. CppUnit::Test* ODBCMySQLTest::suite()
  890. {
  891. #ifdef POCO_OS_FAMILY_WINDOWS
  892. if (init("MySQL ODBC 3.51 Driver", "PocoDataMySQLTest"))
  893. #else
  894. if (init("MySQL", "PocoDataMySQLTest"))
  895. #endif
  896. {
  897. CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest");
  898. CppUnit_addTest(pSuite, ODBCMySQLTest, testBareboneODBC);
  899. CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccess);
  900. CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexType);
  901. CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessVector);
  902. CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeVector);
  903. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertVector);
  904. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyVector);
  905. CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessList);
  906. CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeList);
  907. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertList);
  908. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyList);
  909. CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessDeque);
  910. CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeDeque);
  911. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertDeque);
  912. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyDeque);
  913. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulk);
  914. CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulkVec);
  915. CppUnit_addTest(pSuite, ODBCMySQLTest, testLimit);
  916. CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitOnce);
  917. CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitPrepare);
  918. CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitZero);
  919. CppUnit_addTest(pSuite, ODBCMySQLTest, testPrepare);
  920. CppUnit_addTest(pSuite, ODBCMySQLTest, testSetSimple);
  921. CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplex);
  922. CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplexUnique);
  923. CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetSimple);
  924. CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetComplex);
  925. CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplex);
  926. CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplexUnique);
  927. CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiMapComplex);
  928. CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingle);
  929. CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleStep);
  930. CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleFail);
  931. CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitOk);
  932. CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitFail);
  933. CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedLimits);
  934. CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedIllegalLimits);
  935. CppUnit_addTest(pSuite, ODBCMySQLTest, testRange);
  936. CppUnit_addTest(pSuite, ODBCMySQLTest, testIllegalRange);
  937. CppUnit_addTest(pSuite, ODBCMySQLTest, testSingleSelect);
  938. CppUnit_addTest(pSuite, ODBCMySQLTest, testEmptyDB);
  939. CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOB);
  940. CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOBStmt);
  941. CppUnit_addTest(pSuite, ODBCMySQLTest, testDateTime);
  942. CppUnit_addTest(pSuite, ODBCMySQLTest, testFloat);
  943. CppUnit_addTest(pSuite, ODBCMySQLTest, testDouble);
  944. CppUnit_addTest(pSuite, ODBCMySQLTest, testTuple);
  945. CppUnit_addTest(pSuite, ODBCMySQLTest, testTupleVector);
  946. CppUnit_addTest(pSuite, ODBCMySQLTest, testStoredProcedure);
  947. CppUnit_addTest(pSuite, ODBCMySQLTest, testStoredFunction);
  948. CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalExtraction);
  949. CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalStorageType);
  950. CppUnit_addTest(pSuite, ODBCMySQLTest, testNull);
  951. CppUnit_addTest(pSuite, ODBCMySQLTest, testRowIterator);
  952. return pSuite;
  953. }
  954. return 0;
  955. }