ODBCSQLiteTest.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. //
  2. // ODBCSQLiteTest.cpp
  3. //
  4. // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCSQLiteTest.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 "ODBCSQLiteTest.h"
  32. #include "CppUnit/TestCaller.h"
  33. #include "CppUnit/TestSuite.h"
  34. #include "Poco/String.h"
  35. #include "Poco/Format.h"
  36. #include "Poco/Exception.h"
  37. #include "Poco/Data/Common.h"
  38. #include "Poco/Data/BLOB.h"
  39. #include "Poco/Data/StatementImpl.h"
  40. #include "Poco/Data/ODBC/Connector.h"
  41. #include "Poco/Data/ODBC/Utility.h"
  42. #include "Poco/Data/ODBC/Diagnostics.h"
  43. #include "Poco/Data/ODBC/ODBCException.h"
  44. #include "Poco/Data/ODBC/ODBCStatementImpl.h"
  45. #include <sqltypes.h>
  46. #include <iostream>
  47. using namespace Poco::Data;
  48. using Poco::Data::ODBC::Utility;
  49. using Poco::Data::ODBC::ConnectionException;
  50. using Poco::Data::ODBC::StatementException;
  51. using Poco::Data::ODBC::StatementDiagnostics;
  52. using Poco::format;
  53. using Poco::NotFoundException;
  54. const bool ODBCSQLiteTest::bindValues[8] = {true, true, true, false, false, true, false, false};
  55. Poco::SharedPtr<Poco::Data::Session> ODBCSQLiteTest::_pSession = 0;
  56. Poco::SharedPtr<SQLExecutor> ODBCSQLiteTest::_pExecutor = 0;
  57. std::string ODBCSQLiteTest::_dbConnString;
  58. Poco::Data::ODBC::Utility::DriverMap ODBCSQLiteTest::_drivers;
  59. ODBCSQLiteTest::ODBCSQLiteTest(const std::string& name):
  60. CppUnit::TestCase(name)
  61. {
  62. }
  63. ODBCSQLiteTest::~ODBCSQLiteTest()
  64. {
  65. }
  66. void ODBCSQLiteTest::testBareboneODBC()
  67. {
  68. if (!_pSession) fail ("Test not available.");
  69. std::string tableCreateString = "CREATE TABLE Test "
  70. "(First VARCHAR(30),"
  71. "Second VARCHAR(30),"
  72. "Third BLOB,"
  73. "Fourth INTEGER,"
  74. "Fifth REAL)";
  75. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  76. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  77. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  78. _pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  79. }
  80. void ODBCSQLiteTest::testSimpleAccess()
  81. {
  82. if (!_pSession) fail ("Test not available.");
  83. std::string tableName("Person");
  84. std::string result;
  85. _pSession->setFeature("autoBind", false);
  86. recreatePersonTable();
  87. try { *_pSession << "SELECT name FROM sqlite_master WHERE tbl_name=?", into(result), use(tableName), now; }
  88. catch(StatementException& ex) { std::cout << ex.toString() << std::endl; }
  89. assert (result == tableName);
  90. for (int i = 0; i < 8;)
  91. {
  92. recreatePersonTable();
  93. _pSession->setFeature("autoBind", bindValues[i]);
  94. _pSession->setFeature("autoExtract", bindValues[i+1]);
  95. _pExecutor->simpleAccess();
  96. i += 2;
  97. }
  98. }
  99. void ODBCSQLiteTest::testComplexType()
  100. {
  101. if (!_pSession) fail ("Test not available.");
  102. for (int i = 0; i < 8;)
  103. {
  104. recreatePersonTable();
  105. _pSession->setFeature("autoBind", bindValues[i]);
  106. _pSession->setFeature("autoExtract", bindValues[i+1]);
  107. _pExecutor->complexType();
  108. i += 2;
  109. }
  110. }
  111. void ODBCSQLiteTest::testSimpleAccessVector()
  112. {
  113. if (!_pSession) fail ("Test not available.");
  114. for (int i = 0; i < 8;)
  115. {
  116. recreatePersonTable();
  117. _pSession->setFeature("autoBind", bindValues[i]);
  118. _pSession->setFeature("autoExtract", bindValues[i+1]);
  119. _pExecutor->simpleAccessVector();
  120. i += 2;
  121. }
  122. }
  123. void ODBCSQLiteTest::testComplexTypeVector()
  124. {
  125. if (!_pSession) fail ("Test not available.");
  126. for (int i = 0; i < 8;)
  127. {
  128. recreatePersonTable();
  129. _pSession->setFeature("autoBind", bindValues[i]);
  130. _pSession->setFeature("autoExtract", bindValues[i+1]);
  131. _pExecutor->complexTypeVector();
  132. i += 2;
  133. }
  134. }
  135. void ODBCSQLiteTest::testInsertVector()
  136. {
  137. if (!_pSession) fail ("Test not available.");
  138. for (int i = 0; i < 8;)
  139. {
  140. recreateStringsTable();
  141. _pSession->setFeature("autoBind", bindValues[i]);
  142. _pSession->setFeature("autoExtract", bindValues[i+1]);
  143. _pExecutor->insertVector();
  144. i += 2;
  145. }
  146. }
  147. void ODBCSQLiteTest::testInsertEmptyVector()
  148. {
  149. if (!_pSession) fail ("Test not available.");
  150. for (int i = 0; i < 8;)
  151. {
  152. recreateStringsTable();
  153. _pSession->setFeature("autoBind", bindValues[i]);
  154. _pSession->setFeature("autoExtract", bindValues[i+1]);
  155. _pExecutor->insertEmptyVector();
  156. i += 2;
  157. }
  158. }
  159. void ODBCSQLiteTest::testSimpleAccessList()
  160. {
  161. if (!_pSession) fail ("Test not available.");
  162. for (int i = 0; i < 8;)
  163. {
  164. recreatePersonTable();
  165. _pSession->setFeature("autoBind", bindValues[i]);
  166. _pSession->setFeature("autoExtract", bindValues[i+1]);
  167. _pExecutor->simpleAccessList();
  168. i += 2;
  169. }
  170. }
  171. void ODBCSQLiteTest::testComplexTypeList()
  172. {
  173. if (!_pSession) fail ("Test not available.");
  174. for (int i = 0; i < 8;)
  175. {
  176. recreatePersonTable();
  177. _pSession->setFeature("autoBind", bindValues[i]);
  178. _pSession->setFeature("autoExtract", bindValues[i+1]);
  179. _pExecutor->complexTypeList();
  180. i += 2;
  181. }
  182. }
  183. void ODBCSQLiteTest::testInsertList()
  184. {
  185. if (!_pSession) fail ("Test not available.");
  186. for (int i = 0; i < 8;)
  187. {
  188. recreateStringsTable();
  189. _pSession->setFeature("autoBind", bindValues[i]);
  190. _pSession->setFeature("autoExtract", bindValues[i+1]);
  191. _pExecutor->insertList();
  192. i += 2;
  193. }
  194. }
  195. void ODBCSQLiteTest::testInsertEmptyList()
  196. {
  197. if (!_pSession) fail ("Test not available.");
  198. for (int i = 0; i < 8;)
  199. {
  200. recreateStringsTable();
  201. _pSession->setFeature("autoBind", bindValues[i]);
  202. _pSession->setFeature("autoExtract", bindValues[i+1]);
  203. _pExecutor->insertEmptyList();
  204. i += 2;
  205. }
  206. }
  207. void ODBCSQLiteTest::testSimpleAccessDeque()
  208. {
  209. if (!_pSession) fail ("Test not available.");
  210. for (int i = 0; i < 8;)
  211. {
  212. recreatePersonTable();
  213. _pSession->setFeature("autoBind", bindValues[i]);
  214. _pSession->setFeature("autoExtract", bindValues[i+1]);
  215. _pExecutor->simpleAccessDeque();
  216. i += 2;
  217. }
  218. }
  219. void ODBCSQLiteTest::testComplexTypeDeque()
  220. {
  221. if (!_pSession) fail ("Test not available.");
  222. for (int i = 0; i < 8;)
  223. {
  224. recreatePersonTable();
  225. _pSession->setFeature("autoBind", bindValues[i]);
  226. _pSession->setFeature("autoExtract", bindValues[i+1]);
  227. _pExecutor->complexTypeDeque();
  228. i += 2;
  229. }
  230. }
  231. void ODBCSQLiteTest::testInsertDeque()
  232. {
  233. if (!_pSession) fail ("Test not available.");
  234. for (int i = 0; i < 8;)
  235. {
  236. recreateStringsTable();
  237. _pSession->setFeature("autoBind", bindValues[i]);
  238. _pSession->setFeature("autoExtract", bindValues[i+1]);
  239. _pExecutor->insertDeque();
  240. i += 2;
  241. }
  242. }
  243. void ODBCSQLiteTest::testInsertEmptyDeque()
  244. {
  245. if (!_pSession) fail ("Test not available.");
  246. for (int i = 0; i < 8;)
  247. {
  248. recreateStringsTable();
  249. _pSession->setFeature("autoBind", bindValues[i]);
  250. _pSession->setFeature("autoExtract", bindValues[i+1]);
  251. _pExecutor->insertEmptyDeque();
  252. i += 2;
  253. }
  254. }
  255. void ODBCSQLiteTest::testInsertSingleBulk()
  256. {
  257. if (!_pSession) fail ("Test not available.");
  258. for (int i = 0; i < 8;)
  259. {
  260. recreateIntsTable();
  261. _pSession->setFeature("autoBind", bindValues[i]);
  262. _pSession->setFeature("autoExtract", bindValues[i+1]);
  263. _pExecutor->insertSingleBulk();
  264. i += 2;
  265. }
  266. }
  267. void ODBCSQLiteTest::testInsertSingleBulkVec()
  268. {
  269. if (!_pSession) fail ("Test not available.");
  270. for (int i = 0; i < 8;)
  271. {
  272. recreateIntsTable();
  273. _pSession->setFeature("autoBind", bindValues[i]);
  274. _pSession->setFeature("autoExtract", bindValues[i+1]);
  275. _pExecutor->insertSingleBulkVec();
  276. i += 2;
  277. }
  278. }
  279. void ODBCSQLiteTest::testLimit()
  280. {
  281. if (!_pSession) fail ("Test not available.");
  282. for (int i = 0; i < 8;)
  283. {
  284. recreateIntsTable();
  285. _pSession->setFeature("autoBind", bindValues[i]);
  286. _pSession->setFeature("autoExtract", bindValues[i+1]);
  287. _pExecutor->limits();
  288. i += 2;
  289. }
  290. }
  291. void ODBCSQLiteTest::testLimitZero()
  292. {
  293. if (!_pSession) fail ("Test not available.");
  294. for (int i = 0; i < 8;)
  295. {
  296. recreateIntsTable();
  297. _pSession->setFeature("autoBind", bindValues[i]);
  298. _pSession->setFeature("autoExtract", bindValues[i+1]);
  299. _pExecutor->limitZero();
  300. i += 2;
  301. }
  302. }
  303. void ODBCSQLiteTest::testLimitOnce()
  304. {
  305. if (!_pSession) fail ("Test not available.");
  306. recreateIntsTable();
  307. _pExecutor->limitOnce();
  308. }
  309. void ODBCSQLiteTest::testLimitPrepare()
  310. {
  311. if (!_pSession) fail ("Test not available.");
  312. for (int i = 0; i < 8;)
  313. {
  314. recreateIntsTable();
  315. _pSession->setFeature("autoBind", bindValues[i]);
  316. _pSession->setFeature("autoExtract", bindValues[i+1]);
  317. _pExecutor->limitPrepare();
  318. i += 2;
  319. }
  320. }
  321. void ODBCSQLiteTest::testPrepare()
  322. {
  323. if (!_pSession) fail ("Test not available.");
  324. for (int i = 0; i < 8;)
  325. {
  326. recreateIntsTable();
  327. _pSession->setFeature("autoBind", bindValues[i]);
  328. _pSession->setFeature("autoExtract", bindValues[i+1]);
  329. _pExecutor->prepare();
  330. i += 2;
  331. }
  332. }
  333. void ODBCSQLiteTest::testSetSimple()
  334. {
  335. if (!_pSession) fail ("Test not available.");
  336. for (int i = 0; i < 8;)
  337. {
  338. recreatePersonTable();
  339. _pSession->setFeature("autoBind", bindValues[i]);
  340. _pSession->setFeature("autoExtract", bindValues[i+1]);
  341. _pExecutor->setSimple();
  342. i += 2;
  343. }
  344. }
  345. void ODBCSQLiteTest::testSetComplex()
  346. {
  347. if (!_pSession) fail ("Test not available.");
  348. for (int i = 0; i < 8;)
  349. {
  350. recreatePersonTable();
  351. _pSession->setFeature("autoBind", bindValues[i]);
  352. _pSession->setFeature("autoExtract", bindValues[i+1]);
  353. _pExecutor->setComplex();
  354. i += 2;
  355. }
  356. }
  357. void ODBCSQLiteTest::testSetComplexUnique()
  358. {
  359. if (!_pSession) fail ("Test not available.");
  360. for (int i = 0; i < 8;)
  361. {
  362. recreatePersonTable();
  363. _pSession->setFeature("autoBind", bindValues[i]);
  364. _pSession->setFeature("autoExtract", bindValues[i+1]);
  365. _pExecutor->setComplexUnique();
  366. i += 2;
  367. }
  368. }
  369. void ODBCSQLiteTest::testMultiSetSimple()
  370. {
  371. if (!_pSession) fail ("Test not available.");
  372. for (int i = 0; i < 8;)
  373. {
  374. recreatePersonTable();
  375. _pSession->setFeature("autoBind", bindValues[i]);
  376. _pSession->setFeature("autoExtract", bindValues[i+1]);
  377. _pExecutor->multiSetSimple();
  378. i += 2;
  379. }
  380. }
  381. void ODBCSQLiteTest::testMultiSetComplex()
  382. {
  383. if (!_pSession) fail ("Test not available.");
  384. for (int i = 0; i < 8;)
  385. {
  386. recreatePersonTable();
  387. _pSession->setFeature("autoBind", bindValues[i]);
  388. _pSession->setFeature("autoExtract", bindValues[i+1]);
  389. _pExecutor->multiSetComplex();
  390. i += 2;
  391. }
  392. }
  393. void ODBCSQLiteTest::testMapComplex()
  394. {
  395. if (!_pSession) fail ("Test not available.");
  396. for (int i = 0; i < 8;)
  397. {
  398. recreatePersonTable();
  399. _pSession->setFeature("autoBind", bindValues[i]);
  400. _pSession->setFeature("autoExtract", bindValues[i+1]);
  401. _pExecutor->mapComplex();
  402. i += 2;
  403. }
  404. }
  405. void ODBCSQLiteTest::testMapComplexUnique()
  406. {
  407. if (!_pSession) fail ("Test not available.");
  408. for (int i = 0; i < 8;)
  409. {
  410. recreatePersonTable();
  411. _pSession->setFeature("autoBind", bindValues[i]);
  412. _pSession->setFeature("autoExtract", bindValues[i+1]);
  413. _pExecutor->mapComplexUnique();
  414. i += 2;
  415. }
  416. }
  417. void ODBCSQLiteTest::testMultiMapComplex()
  418. {
  419. if (!_pSession) fail ("Test not available.");
  420. for (int i = 0; i < 8;)
  421. {
  422. recreatePersonTable();
  423. _pSession->setFeature("autoBind", bindValues[i]);
  424. _pSession->setFeature("autoExtract", bindValues[i+1]);
  425. _pExecutor->multiMapComplex();
  426. i += 2;
  427. }
  428. }
  429. void ODBCSQLiteTest::testSelectIntoSingle()
  430. {
  431. if (!_pSession) fail ("Test not available.");
  432. for (int i = 0; i < 8;)
  433. {
  434. recreatePersonTable();
  435. _pSession->setFeature("autoBind", bindValues[i]);
  436. _pSession->setFeature("autoExtract", bindValues[i+1]);
  437. _pExecutor->selectIntoSingle();
  438. i += 2;
  439. }
  440. }
  441. void ODBCSQLiteTest::testSelectIntoSingleStep()
  442. {
  443. if (!_pSession) fail ("Test not available.");
  444. for (int i = 0; i < 8;)
  445. {
  446. recreatePersonTable();
  447. _pSession->setFeature("autoBind", bindValues[i]);
  448. _pSession->setFeature("autoExtract", bindValues[i+1]);
  449. _pExecutor->selectIntoSingleStep();
  450. i += 2;
  451. }
  452. }
  453. void ODBCSQLiteTest::testSelectIntoSingleFail()
  454. {
  455. if (!_pSession) fail ("Test not available.");
  456. for (int i = 0; i < 8;)
  457. {
  458. recreatePersonTable();
  459. _pSession->setFeature("autoBind", bindValues[i]);
  460. _pSession->setFeature("autoExtract", bindValues[i+1]);
  461. _pExecutor->selectIntoSingleFail();
  462. i += 2;
  463. }
  464. }
  465. void ODBCSQLiteTest::testLowerLimitOk()
  466. {
  467. if (!_pSession) fail ("Test not available.");
  468. for (int i = 0; i < 8;)
  469. {
  470. recreatePersonTable();
  471. _pSession->setFeature("autoBind", bindValues[i]);
  472. _pSession->setFeature("autoExtract", bindValues[i+1]);
  473. _pExecutor->lowerLimitOk();
  474. i += 2;
  475. }
  476. }
  477. void ODBCSQLiteTest::testSingleSelect()
  478. {
  479. if (!_pSession) fail ("Test not available.");
  480. for (int i = 0; i < 8;)
  481. {
  482. recreatePersonTable();
  483. _pSession->setFeature("autoBind", bindValues[i]);
  484. _pSession->setFeature("autoExtract", bindValues[i+1]);
  485. _pExecutor->singleSelect();
  486. i += 2;
  487. }
  488. }
  489. void ODBCSQLiteTest::testLowerLimitFail()
  490. {
  491. if (!_pSession) fail ("Test not available.");
  492. for (int i = 0; i < 8;)
  493. {
  494. recreatePersonTable();
  495. _pSession->setFeature("autoBind", bindValues[i]);
  496. _pSession->setFeature("autoExtract", bindValues[i+1]);
  497. _pExecutor->lowerLimitFail();
  498. i += 2;
  499. }
  500. }
  501. void ODBCSQLiteTest::testCombinedLimits()
  502. {
  503. if (!_pSession) fail ("Test not available.");
  504. for (int i = 0; i < 8;)
  505. {
  506. recreatePersonTable();
  507. _pSession->setFeature("autoBind", bindValues[i]);
  508. _pSession->setFeature("autoExtract", bindValues[i+1]);
  509. _pExecutor->combinedLimits();
  510. i += 2;
  511. }
  512. }
  513. void ODBCSQLiteTest::testRange()
  514. {
  515. if (!_pSession) fail ("Test not available.");
  516. for (int i = 0; i < 8;)
  517. {
  518. recreatePersonTable();
  519. _pSession->setFeature("autoBind", bindValues[i]);
  520. _pSession->setFeature("autoExtract", bindValues[i+1]);
  521. _pExecutor->ranges();
  522. i += 2;
  523. }
  524. }
  525. void ODBCSQLiteTest::testCombinedIllegalLimits()
  526. {
  527. if (!_pSession) fail ("Test not available.");
  528. for (int i = 0; i < 8;)
  529. {
  530. recreatePersonTable();
  531. _pSession->setFeature("autoBind", bindValues[i]);
  532. _pSession->setFeature("autoExtract", bindValues[i+1]);
  533. _pExecutor->combinedIllegalLimits();
  534. i += 2;
  535. }
  536. }
  537. void ODBCSQLiteTest::testIllegalRange()
  538. {
  539. if (!_pSession) fail ("Test not available.");
  540. for (int i = 0; i < 8;)
  541. {
  542. recreatePersonTable();
  543. _pSession->setFeature("autoBind", bindValues[i]);
  544. _pSession->setFeature("autoExtract", bindValues[i+1]);
  545. _pExecutor->illegalRange();
  546. i += 2;
  547. }
  548. }
  549. void ODBCSQLiteTest::testEmptyDB()
  550. {
  551. if (!_pSession) fail ("Test not available.");
  552. for (int i = 0; i < 8;)
  553. {
  554. recreatePersonTable();
  555. _pSession->setFeature("autoBind", bindValues[i]);
  556. _pSession->setFeature("autoExtract", bindValues[i+1]);
  557. _pExecutor->emptyDB();
  558. i += 2;
  559. }
  560. }
  561. void ODBCSQLiteTest::testBLOB()
  562. {
  563. if (!_pSession) fail ("Test not available.");
  564. for (int i = 0; i < 8;)
  565. {
  566. recreatePersonBLOBTable();
  567. _pSession->setFeature("autoBind", bindValues[i]);
  568. _pSession->setFeature("autoExtract", bindValues[i+1]);
  569. _pExecutor->blob();
  570. i += 2;
  571. }
  572. }
  573. void ODBCSQLiteTest::testBLOBStmt()
  574. {
  575. if (!_pSession) fail ("Test not available.");
  576. for (int i = 0; i < 8;)
  577. {
  578. recreatePersonBLOBTable();
  579. _pSession->setFeature("autoBind", bindValues[i]);
  580. _pSession->setFeature("autoExtract", bindValues[i+1]);
  581. _pExecutor->blobStmt();
  582. i += 2;
  583. }
  584. }
  585. void ODBCSQLiteTest::testFloat()
  586. {
  587. if (!_pSession) fail ("Test not available.");
  588. for (int i = 0; i < 8;)
  589. {
  590. recreateFloatsTable();
  591. _pSession->setFeature("autoBind", bindValues[i]);
  592. _pSession->setFeature("autoExtract", bindValues[i+1]);
  593. _pExecutor->floats();
  594. i += 2;
  595. }
  596. }
  597. void ODBCSQLiteTest::testDouble()
  598. {
  599. if (!_pSession) fail ("Test not available.");
  600. for (int i = 0; i < 8;)
  601. {
  602. recreateFloatsTable();
  603. _pSession->setFeature("autoBind", bindValues[i]);
  604. _pSession->setFeature("autoExtract", bindValues[i+1]);
  605. _pExecutor->doubles();
  606. i += 2;
  607. }
  608. }
  609. void ODBCSQLiteTest::testTuple()
  610. {
  611. if (!_pSession) fail ("Test not available.");
  612. for (int i = 0; i < 8;)
  613. {
  614. recreateTuplesTable();
  615. _pSession->setFeature("autoBind", bindValues[i]);
  616. _pSession->setFeature("autoExtract", bindValues[i+1]);
  617. _pExecutor->tuples();
  618. i += 2;
  619. }
  620. }
  621. void ODBCSQLiteTest::testTupleVector()
  622. {
  623. if (!_pSession) fail ("Test not available.");
  624. for (int i = 0; i < 8;)
  625. {
  626. recreateTuplesTable();
  627. _pSession->setFeature("autoBind", bindValues[i]);
  628. _pSession->setFeature("autoExtract", bindValues[i+1]);
  629. _pExecutor->tupleVector();
  630. i += 2;
  631. }
  632. }
  633. void ODBCSQLiteTest::testInternalExtraction()
  634. {
  635. if (!_pSession) fail ("Test not available.");
  636. for (int i = 0; i < 8;)
  637. {
  638. recreateVectorsTable();
  639. _pSession->setFeature("autoBind", bindValues[i]);
  640. _pSession->setFeature("autoExtract", bindValues[i+1]);
  641. _pExecutor->internalExtraction();
  642. i += 2;
  643. }
  644. }
  645. void ODBCSQLiteTest::testInternalStorageType()
  646. {
  647. if (!_pSession) fail ("Test not available.");
  648. for (int i = 0; i < 8;)
  649. {
  650. recreateVectorsTable();
  651. _pSession->setFeature("autoBind", bindValues[i]);
  652. _pSession->setFeature("autoExtract", bindValues[i+1]);
  653. _pExecutor->internalStorageType();
  654. i += 2;
  655. }
  656. }
  657. void ODBCSQLiteTest::dropTable(const std::string& tableName)
  658. {
  659. try
  660. {
  661. *_pSession << format("DROP TABLE %s", tableName), now;
  662. }
  663. catch (StatementException& ex)
  664. {
  665. bool ignoreError = false;
  666. const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
  667. StatementDiagnostics::Iterator it = flds.begin();
  668. for (; it != flds.end(); ++it)
  669. {
  670. if (1 == it->_nativeError)//(no such table)
  671. {
  672. ignoreError = true;
  673. break;
  674. }
  675. }
  676. if (!ignoreError) throw;
  677. }
  678. }
  679. void ODBCSQLiteTest::recreatePersonTable()
  680. {
  681. dropTable("Person");
  682. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR2(30), FirstName VARCHAR2(30), Address VARCHAR2(30), Age INTEGER)", now; }
  683. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
  684. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
  685. }
  686. void ODBCSQLiteTest::recreatePersonBLOBTable()
  687. {
  688. dropTable("Person");
  689. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
  690. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  691. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  692. }
  693. void ODBCSQLiteTest::recreateIntsTable()
  694. {
  695. dropTable("Strings");
  696. try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
  697. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
  698. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
  699. }
  700. void ODBCSQLiteTest::recreateStringsTable()
  701. {
  702. dropTable("Strings");
  703. try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
  704. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
  705. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
  706. }
  707. void ODBCSQLiteTest::recreateFloatsTable()
  708. {
  709. dropTable("Strings");
  710. try { *_pSession << "CREATE TABLE Strings (str REAL)", now; }
  711. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
  712. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
  713. }
  714. void ODBCSQLiteTest::recreateTuplesTable()
  715. {
  716. dropTable("Tuples");
  717. try { *_pSession << "CREATE TABLE Tuples "
  718. "(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
  719. "int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
  720. "int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
  721. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
  722. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
  723. }
  724. void ODBCSQLiteTest::recreateVectorsTable()
  725. {
  726. dropTable("Vectors");
  727. try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 REAL, str0 VARCHAR)", now; }
  728. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
  729. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
  730. }
  731. bool ODBCSQLiteTest::canConnect(const std::string& driver, const std::string& dsn)
  732. {
  733. Utility::DriverMap::iterator itDrv = _drivers.begin();
  734. for (; itDrv != _drivers.end(); ++itDrv)
  735. {
  736. if (((itDrv->first).find(driver) != std::string::npos))
  737. {
  738. std::cout << "Driver found: " << itDrv->first
  739. << " (" << itDrv->second << ')' << std::endl;
  740. break;
  741. }
  742. }
  743. if (_drivers.end() == itDrv)
  744. {
  745. std::cout << driver << " driver NOT found, tests not available." << std::endl;
  746. return false;
  747. }
  748. Utility::DSNMap dataSources;
  749. Utility::dataSources(dataSources);
  750. Utility::DSNMap::iterator itDSN = dataSources.begin();
  751. for (; itDSN != dataSources.end(); ++itDSN)
  752. {
  753. if (itDSN->first == dsn && itDSN->second == driver)
  754. {
  755. std::cout << "DSN found: " << itDSN->first
  756. << " (" << itDSN->second << ')' << std::endl;
  757. format(_dbConnString, "DSN=%s", dsn);
  758. return true;
  759. }
  760. }
  761. // DSN not found, try connect without it
  762. format(_dbConnString, "Driver=%s;Database=dummy.db;", driver);
  763. return true;
  764. }
  765. void ODBCSQLiteTest::setUp()
  766. {
  767. }
  768. void ODBCSQLiteTest::tearDown()
  769. {
  770. dropTable("Person");
  771. dropTable("Strings");
  772. dropTable("Tuples");
  773. }
  774. bool ODBCSQLiteTest::init(const std::string& driver, const std::string& dsn)
  775. {
  776. Utility::drivers(_drivers);
  777. if (!canConnect(driver, dsn)) return false;
  778. ODBC::Connector::registerConnector();
  779. try
  780. {
  781. _pSession = new Session(ODBC::Connector::KEY, _dbConnString);
  782. }catch (ConnectionException& ex)
  783. {
  784. std::cout << ex.toString() << std::endl;
  785. return false;
  786. }
  787. if (_pSession && _pSession->isConnected())
  788. std::cout << "*** Connected to [" << driver << "] test database." << std::endl;
  789. _pExecutor = new SQLExecutor(driver + " SQL Executor", _pSession);
  790. return true;
  791. }
  792. CppUnit::Test* ODBCSQLiteTest::suite()
  793. {
  794. if (init("SQLite3 ODBC Driver", "PocoDataSQLiteTest"))
  795. {
  796. CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLiteTest");
  797. CppUnit_addTest(pSuite, ODBCSQLiteTest, testBareboneODBC);
  798. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccess);
  799. CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexType);
  800. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccessVector);
  801. CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexTypeVector);
  802. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertVector);
  803. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertEmptyVector);
  804. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccessList);
  805. CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexTypeList);
  806. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertList);
  807. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertEmptyList);
  808. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccessDeque);
  809. CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexTypeDeque);
  810. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertDeque);
  811. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertEmptyDeque);
  812. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertSingleBulk);
  813. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertSingleBulkVec);
  814. CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimit);
  815. CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitOnce);
  816. CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitPrepare);
  817. CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitZero);
  818. CppUnit_addTest(pSuite, ODBCSQLiteTest, testPrepare);
  819. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetSimple);
  820. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetComplex);
  821. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetComplexUnique);
  822. CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiSetSimple);
  823. CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiSetComplex);
  824. CppUnit_addTest(pSuite, ODBCSQLiteTest, testMapComplex);
  825. CppUnit_addTest(pSuite, ODBCSQLiteTest, testMapComplexUnique);
  826. CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiMapComplex);
  827. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingle);
  828. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingleStep);
  829. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingleFail);
  830. CppUnit_addTest(pSuite, ODBCSQLiteTest, testLowerLimitOk);
  831. CppUnit_addTest(pSuite, ODBCSQLiteTest, testLowerLimitFail);
  832. CppUnit_addTest(pSuite, ODBCSQLiteTest, testCombinedLimits);
  833. CppUnit_addTest(pSuite, ODBCSQLiteTest, testCombinedIllegalLimits);
  834. CppUnit_addTest(pSuite, ODBCSQLiteTest, testRange);
  835. CppUnit_addTest(pSuite, ODBCSQLiteTest, testIllegalRange);
  836. CppUnit_addTest(pSuite, ODBCSQLiteTest, testSingleSelect);
  837. CppUnit_addTest(pSuite, ODBCSQLiteTest, testEmptyDB);
  838. CppUnit_addTest(pSuite, ODBCSQLiteTest, testBLOB);
  839. CppUnit_addTest(pSuite, ODBCSQLiteTest, testBLOBStmt);
  840. CppUnit_addTest(pSuite, ODBCSQLiteTest, testFloat);
  841. CppUnit_addTest(pSuite, ODBCSQLiteTest, testDouble);
  842. CppUnit_addTest(pSuite, ODBCSQLiteTest, testTuple);
  843. CppUnit_addTest(pSuite, ODBCSQLiteTest, testTupleVector);
  844. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInternalExtraction);
  845. CppUnit_addTest(pSuite, ODBCSQLiteTest, testInternalStorageType);
  846. return pSuite;
  847. }
  848. return 0;
  849. }