ODBCPostgreSQLTest.cpp 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. //
  2. // ODBCPostgreSQLTest.cpp
  3. //
  4. // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCPostgreSQLTest.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 "ODBCPostgreSQLTest.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 ODBCPostgreSQLTest::bindValues[8] = {true, true, true, false, false, true, false, false};
  57. Poco::SharedPtr<Poco::Data::Session> ODBCPostgreSQLTest::_pSession = 0;
  58. Poco::SharedPtr<SQLExecutor> ODBCPostgreSQLTest::_pExecutor = 0;
  59. std::string ODBCPostgreSQLTest::_dbConnString;
  60. Poco::Data::ODBC::Utility::DriverMap ODBCPostgreSQLTest::_drivers;
  61. ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& name):
  62. CppUnit::TestCase(name)
  63. {
  64. }
  65. ODBCPostgreSQLTest::~ODBCPostgreSQLTest()
  66. {
  67. }
  68. void ODBCPostgreSQLTest::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 BYTEA,"
  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 ODBCPostgreSQLTest::testSimpleAccess()
  83. {
  84. if (!_pSession) fail ("Test not available.");
  85. std::string tableName("Person");
  86. for (int i = 0; i < 8;)
  87. {
  88. recreatePersonTable();
  89. _pSession->setFeature("autoBind", bindValues[i]);
  90. _pSession->setFeature("autoExtract", bindValues[i+1]);
  91. _pExecutor->simpleAccess();
  92. i += 2;
  93. }
  94. }
  95. void ODBCPostgreSQLTest::testComplexType()
  96. {
  97. if (!_pSession) fail ("Test not available.");
  98. for (int i = 0; i < 8;)
  99. {
  100. recreatePersonTable();
  101. _pSession->setFeature("autoBind", bindValues[i]);
  102. _pSession->setFeature("autoExtract", bindValues[i+1]);
  103. _pExecutor->complexType();
  104. i += 2;
  105. }
  106. }
  107. void ODBCPostgreSQLTest::testSimpleAccessVector()
  108. {
  109. if (!_pSession) fail ("Test not available.");
  110. for (int i = 0; i < 8;)
  111. {
  112. recreatePersonTable();
  113. _pSession->setFeature("autoBind", bindValues[i]);
  114. _pSession->setFeature("autoExtract", bindValues[i+1]);
  115. _pExecutor->simpleAccessVector();
  116. i += 2;
  117. }
  118. }
  119. void ODBCPostgreSQLTest::testComplexTypeVector()
  120. {
  121. if (!_pSession) fail ("Test not available.");
  122. for (int i = 0; i < 8;)
  123. {
  124. recreatePersonTable();
  125. _pSession->setFeature("autoBind", bindValues[i]);
  126. _pSession->setFeature("autoExtract", bindValues[i+1]);
  127. _pExecutor->complexTypeVector();
  128. i += 2;
  129. }
  130. }
  131. void ODBCPostgreSQLTest::testInsertVector()
  132. {
  133. if (!_pSession) fail ("Test not available.");
  134. for (int i = 0; i < 8;)
  135. {
  136. recreateStringsTable();
  137. _pSession->setFeature("autoBind", bindValues[i]);
  138. _pSession->setFeature("autoExtract", bindValues[i+1]);
  139. _pExecutor->insertVector();
  140. i += 2;
  141. }
  142. }
  143. void ODBCPostgreSQLTest::testInsertEmptyVector()
  144. {
  145. if (!_pSession) fail ("Test not available.");
  146. for (int i = 0; i < 8;)
  147. {
  148. recreateStringsTable();
  149. _pSession->setFeature("autoBind", bindValues[i]);
  150. _pSession->setFeature("autoExtract", bindValues[i+1]);
  151. _pExecutor->insertEmptyVector();
  152. i += 2;
  153. }
  154. }
  155. void ODBCPostgreSQLTest::testSimpleAccessList()
  156. {
  157. if (!_pSession) fail ("Test not available.");
  158. for (int i = 0; i < 8;)
  159. {
  160. recreatePersonTable();
  161. _pSession->setFeature("autoBind", bindValues[i]);
  162. _pSession->setFeature("autoExtract", bindValues[i+1]);
  163. _pExecutor->simpleAccessList();
  164. i += 2;
  165. }
  166. }
  167. void ODBCPostgreSQLTest::testComplexTypeList()
  168. {
  169. if (!_pSession) fail ("Test not available.");
  170. for (int i = 0; i < 8;)
  171. {
  172. recreatePersonTable();
  173. _pSession->setFeature("autoBind", bindValues[i]);
  174. _pSession->setFeature("autoExtract", bindValues[i+1]);
  175. _pExecutor->complexTypeList();
  176. i += 2;
  177. }
  178. }
  179. void ODBCPostgreSQLTest::testInsertList()
  180. {
  181. if (!_pSession) fail ("Test not available.");
  182. for (int i = 0; i < 8;)
  183. {
  184. recreateStringsTable();
  185. _pSession->setFeature("autoBind", bindValues[i]);
  186. _pSession->setFeature("autoExtract", bindValues[i+1]);
  187. _pExecutor->insertList();
  188. i += 2;
  189. }
  190. }
  191. void ODBCPostgreSQLTest::testInsertEmptyList()
  192. {
  193. if (!_pSession) fail ("Test not available.");
  194. for (int i = 0; i < 8;)
  195. {
  196. recreateStringsTable();
  197. _pSession->setFeature("autoBind", bindValues[i]);
  198. _pSession->setFeature("autoExtract", bindValues[i+1]);
  199. _pExecutor->insertEmptyList();
  200. i += 2;
  201. }
  202. }
  203. void ODBCPostgreSQLTest::testSimpleAccessDeque()
  204. {
  205. if (!_pSession) fail ("Test not available.");
  206. for (int i = 0; i < 8;)
  207. {
  208. recreatePersonTable();
  209. _pSession->setFeature("autoBind", bindValues[i]);
  210. _pSession->setFeature("autoExtract", bindValues[i+1]);
  211. _pExecutor->simpleAccessDeque();
  212. i += 2;
  213. }
  214. }
  215. void ODBCPostgreSQLTest::testComplexTypeDeque()
  216. {
  217. if (!_pSession) fail ("Test not available.");
  218. for (int i = 0; i < 8;)
  219. {
  220. recreatePersonTable();
  221. _pSession->setFeature("autoBind", bindValues[i]);
  222. _pSession->setFeature("autoExtract", bindValues[i+1]);
  223. _pExecutor->complexTypeDeque();
  224. i += 2;
  225. }
  226. }
  227. void ODBCPostgreSQLTest::testInsertDeque()
  228. {
  229. if (!_pSession) fail ("Test not available.");
  230. for (int i = 0; i < 8;)
  231. {
  232. recreateStringsTable();
  233. _pSession->setFeature("autoBind", bindValues[i]);
  234. _pSession->setFeature("autoExtract", bindValues[i+1]);
  235. _pExecutor->insertDeque();
  236. i += 2;
  237. }
  238. }
  239. void ODBCPostgreSQLTest::testInsertEmptyDeque()
  240. {
  241. if (!_pSession) fail ("Test not available.");
  242. for (int i = 0; i < 8;)
  243. {
  244. recreateStringsTable();
  245. _pSession->setFeature("autoBind", bindValues[i]);
  246. _pSession->setFeature("autoExtract", bindValues[i+1]);
  247. _pExecutor->insertEmptyDeque();
  248. i += 2;
  249. }
  250. }
  251. void ODBCPostgreSQLTest::testInsertSingleBulk()
  252. {
  253. if (!_pSession) fail ("Test not available.");
  254. for (int i = 0; i < 8;)
  255. {
  256. recreateIntsTable();
  257. _pSession->setFeature("autoBind", bindValues[i]);
  258. _pSession->setFeature("autoExtract", bindValues[i+1]);
  259. _pExecutor->insertSingleBulk();
  260. i += 2;
  261. }
  262. }
  263. void ODBCPostgreSQLTest::testInsertSingleBulkVec()
  264. {
  265. if (!_pSession) fail ("Test not available.");
  266. for (int i = 0; i < 8;)
  267. {
  268. recreateIntsTable();
  269. _pSession->setFeature("autoBind", bindValues[i]);
  270. _pSession->setFeature("autoExtract", bindValues[i+1]);
  271. _pExecutor->insertSingleBulkVec();
  272. i += 2;
  273. }
  274. }
  275. void ODBCPostgreSQLTest::testLimit()
  276. {
  277. if (!_pSession) fail ("Test not available.");
  278. for (int i = 0; i < 8;)
  279. {
  280. recreateIntsTable();
  281. _pSession->setFeature("autoBind", bindValues[i]);
  282. _pSession->setFeature("autoExtract", bindValues[i+1]);
  283. _pExecutor->limits();
  284. i += 2;
  285. }
  286. }
  287. void ODBCPostgreSQLTest::testLimitZero()
  288. {
  289. if (!_pSession) fail ("Test not available.");
  290. for (int i = 0; i < 8;)
  291. {
  292. recreateIntsTable();
  293. _pSession->setFeature("autoBind", bindValues[i]);
  294. _pSession->setFeature("autoExtract", bindValues[i+1]);
  295. _pExecutor->limitZero();
  296. i += 2;
  297. }
  298. }
  299. void ODBCPostgreSQLTest::testLimitOnce()
  300. {
  301. if (!_pSession) fail ("Test not available.");
  302. recreateIntsTable();
  303. _pExecutor->limitOnce();
  304. }
  305. void ODBCPostgreSQLTest::testLimitPrepare()
  306. {
  307. if (!_pSession) fail ("Test not available.");
  308. for (int i = 0; i < 8;)
  309. {
  310. recreateIntsTable();
  311. _pSession->setFeature("autoBind", bindValues[i]);
  312. _pSession->setFeature("autoExtract", bindValues[i+1]);
  313. _pExecutor->limitPrepare();
  314. i += 2;
  315. }
  316. }
  317. void ODBCPostgreSQLTest::testPrepare()
  318. {
  319. if (!_pSession) fail ("Test not available.");
  320. for (int i = 0; i < 8;)
  321. {
  322. recreateIntsTable();
  323. _pSession->setFeature("autoBind", bindValues[i]);
  324. _pSession->setFeature("autoExtract", bindValues[i+1]);
  325. _pExecutor->prepare();
  326. i += 2;
  327. }
  328. }
  329. void ODBCPostgreSQLTest::testSetSimple()
  330. {
  331. if (!_pSession) fail ("Test not available.");
  332. for (int i = 0; i < 8;)
  333. {
  334. recreatePersonTable();
  335. _pSession->setFeature("autoBind", bindValues[i]);
  336. _pSession->setFeature("autoExtract", bindValues[i+1]);
  337. _pExecutor->setSimple();
  338. i += 2;
  339. }
  340. }
  341. void ODBCPostgreSQLTest::testSetComplex()
  342. {
  343. if (!_pSession) fail ("Test not available.");
  344. for (int i = 0; i < 8;)
  345. {
  346. recreatePersonTable();
  347. _pSession->setFeature("autoBind", bindValues[i]);
  348. _pSession->setFeature("autoExtract", bindValues[i+1]);
  349. _pExecutor->setComplex();
  350. i += 2;
  351. }
  352. }
  353. void ODBCPostgreSQLTest::testSetComplexUnique()
  354. {
  355. if (!_pSession) fail ("Test not available.");
  356. for (int i = 0; i < 8;)
  357. {
  358. recreatePersonTable();
  359. _pSession->setFeature("autoBind", bindValues[i]);
  360. _pSession->setFeature("autoExtract", bindValues[i+1]);
  361. _pExecutor->setComplexUnique();
  362. i += 2;
  363. }
  364. }
  365. void ODBCPostgreSQLTest::testMultiSetSimple()
  366. {
  367. if (!_pSession) fail ("Test not available.");
  368. for (int i = 0; i < 8;)
  369. {
  370. recreatePersonTable();
  371. _pSession->setFeature("autoBind", bindValues[i]);
  372. _pSession->setFeature("autoExtract", bindValues[i+1]);
  373. _pExecutor->multiSetSimple();
  374. i += 2;
  375. }
  376. }
  377. void ODBCPostgreSQLTest::testMultiSetComplex()
  378. {
  379. if (!_pSession) fail ("Test not available.");
  380. for (int i = 0; i < 8;)
  381. {
  382. recreatePersonTable();
  383. _pSession->setFeature("autoBind", bindValues[i]);
  384. _pSession->setFeature("autoExtract", bindValues[i+1]);
  385. _pExecutor->multiSetComplex();
  386. i += 2;
  387. }
  388. }
  389. void ODBCPostgreSQLTest::testMapComplex()
  390. {
  391. if (!_pSession) fail ("Test not available.");
  392. for (int i = 0; i < 8;)
  393. {
  394. recreatePersonTable();
  395. _pSession->setFeature("autoBind", bindValues[i]);
  396. _pSession->setFeature("autoExtract", bindValues[i+1]);
  397. _pExecutor->mapComplex();
  398. i += 2;
  399. }
  400. }
  401. void ODBCPostgreSQLTest::testMapComplexUnique()
  402. {
  403. if (!_pSession) fail ("Test not available.");
  404. for (int i = 0; i < 8;)
  405. {
  406. recreatePersonTable();
  407. _pSession->setFeature("autoBind", bindValues[i]);
  408. _pSession->setFeature("autoExtract", bindValues[i+1]);
  409. _pExecutor->mapComplexUnique();
  410. i += 2;
  411. }
  412. }
  413. void ODBCPostgreSQLTest::testMultiMapComplex()
  414. {
  415. if (!_pSession) fail ("Test not available.");
  416. for (int i = 0; i < 8;)
  417. {
  418. recreatePersonTable();
  419. _pSession->setFeature("autoBind", bindValues[i]);
  420. _pSession->setFeature("autoExtract", bindValues[i+1]);
  421. _pExecutor->multiMapComplex();
  422. i += 2;
  423. }
  424. }
  425. void ODBCPostgreSQLTest::testSelectIntoSingle()
  426. {
  427. if (!_pSession) fail ("Test not available.");
  428. for (int i = 0; i < 8;)
  429. {
  430. recreatePersonTable();
  431. _pSession->setFeature("autoBind", bindValues[i]);
  432. _pSession->setFeature("autoExtract", bindValues[i+1]);
  433. _pExecutor->selectIntoSingle();
  434. i += 2;
  435. }
  436. }
  437. void ODBCPostgreSQLTest::testSelectIntoSingleStep()
  438. {
  439. if (!_pSession) fail ("Test not available.");
  440. for (int i = 0; i < 8;)
  441. {
  442. recreatePersonTable();
  443. _pSession->setFeature("autoBind", bindValues[i]);
  444. _pSession->setFeature("autoExtract", bindValues[i+1]);
  445. _pExecutor->selectIntoSingleStep();
  446. i += 2;
  447. }
  448. }
  449. void ODBCPostgreSQLTest::testSelectIntoSingleFail()
  450. {
  451. if (!_pSession) fail ("Test not available.");
  452. for (int i = 0; i < 8;)
  453. {
  454. recreatePersonTable();
  455. _pSession->setFeature("autoBind", bindValues[i]);
  456. _pSession->setFeature("autoExtract", bindValues[i+1]);
  457. _pExecutor->selectIntoSingleFail();
  458. i += 2;
  459. }
  460. }
  461. void ODBCPostgreSQLTest::testLowerLimitOk()
  462. {
  463. if (!_pSession) fail ("Test not available.");
  464. for (int i = 0; i < 8;)
  465. {
  466. recreatePersonTable();
  467. _pSession->setFeature("autoBind", bindValues[i]);
  468. _pSession->setFeature("autoExtract", bindValues[i+1]);
  469. _pExecutor->lowerLimitOk();
  470. i += 2;
  471. }
  472. }
  473. void ODBCPostgreSQLTest::testSingleSelect()
  474. {
  475. if (!_pSession) fail ("Test not available.");
  476. for (int i = 0; i < 8;)
  477. {
  478. recreatePersonTable();
  479. _pSession->setFeature("autoBind", bindValues[i]);
  480. _pSession->setFeature("autoExtract", bindValues[i+1]);
  481. _pExecutor->singleSelect();
  482. i += 2;
  483. }
  484. }
  485. void ODBCPostgreSQLTest::testLowerLimitFail()
  486. {
  487. if (!_pSession) fail ("Test not available.");
  488. for (int i = 0; i < 8;)
  489. {
  490. recreatePersonTable();
  491. _pSession->setFeature("autoBind", bindValues[i]);
  492. _pSession->setFeature("autoExtract", bindValues[i+1]);
  493. _pExecutor->lowerLimitFail();
  494. i += 2;
  495. }
  496. }
  497. void ODBCPostgreSQLTest::testCombinedLimits()
  498. {
  499. if (!_pSession) fail ("Test not available.");
  500. for (int i = 0; i < 8;)
  501. {
  502. recreatePersonTable();
  503. _pSession->setFeature("autoBind", bindValues[i]);
  504. _pSession->setFeature("autoExtract", bindValues[i+1]);
  505. _pExecutor->combinedLimits();
  506. i += 2;
  507. }
  508. }
  509. void ODBCPostgreSQLTest::testRange()
  510. {
  511. if (!_pSession) fail ("Test not available.");
  512. for (int i = 0; i < 8;)
  513. {
  514. recreatePersonTable();
  515. _pSession->setFeature("autoBind", bindValues[i]);
  516. _pSession->setFeature("autoExtract", bindValues[i+1]);
  517. _pExecutor->ranges();
  518. i += 2;
  519. }
  520. }
  521. void ODBCPostgreSQLTest::testCombinedIllegalLimits()
  522. {
  523. if (!_pSession) fail ("Test not available.");
  524. for (int i = 0; i < 8;)
  525. {
  526. recreatePersonTable();
  527. _pSession->setFeature("autoBind", bindValues[i]);
  528. _pSession->setFeature("autoExtract", bindValues[i+1]);
  529. _pExecutor->combinedIllegalLimits();
  530. i += 2;
  531. }
  532. }
  533. void ODBCPostgreSQLTest::testIllegalRange()
  534. {
  535. if (!_pSession) fail ("Test not available.");
  536. for (int i = 0; i < 8;)
  537. {
  538. recreatePersonTable();
  539. _pSession->setFeature("autoBind", bindValues[i]);
  540. _pSession->setFeature("autoExtract", bindValues[i+1]);
  541. _pExecutor->illegalRange();
  542. i += 2;
  543. }
  544. }
  545. void ODBCPostgreSQLTest::testEmptyDB()
  546. {
  547. if (!_pSession) fail ("Test not available.");
  548. for (int i = 0; i < 8;)
  549. {
  550. recreatePersonTable();
  551. _pSession->setFeature("autoBind", bindValues[i]);
  552. _pSession->setFeature("autoExtract", bindValues[i+1]);
  553. _pExecutor->emptyDB();
  554. i += 2;
  555. }
  556. }
  557. void ODBCPostgreSQLTest::testBLOB()
  558. {
  559. if (!_pSession) fail ("Test not available.");
  560. const std::size_t maxFldSize = 1000000;
  561. _pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
  562. recreatePersonBLOBTable();
  563. try
  564. {
  565. _pExecutor->blob(maxFldSize);
  566. fail ("must fail");
  567. }
  568. catch (DataException&)
  569. {
  570. _pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
  571. }
  572. for (int i = 0; i < 8;)
  573. {
  574. recreatePersonBLOBTable();
  575. _pSession->setFeature("autoBind", bindValues[i]);
  576. _pSession->setFeature("autoExtract", bindValues[i+1]);
  577. _pExecutor->blob(1000000);
  578. i += 2;
  579. }
  580. }
  581. void ODBCPostgreSQLTest::testBLOBStmt()
  582. {
  583. if (!_pSession) fail ("Test not available.");
  584. for (int i = 0; i < 8;)
  585. {
  586. recreatePersonBLOBTable();
  587. _pSession->setFeature("autoBind", bindValues[i]);
  588. _pSession->setFeature("autoExtract", bindValues[i+1]);
  589. _pExecutor->blobStmt();
  590. i += 2;
  591. }
  592. }
  593. void ODBCPostgreSQLTest::testFloat()
  594. {
  595. if (!_pSession) fail ("Test not available.");
  596. for (int i = 0; i < 8;)
  597. {
  598. recreateFloatsTable();
  599. _pSession->setFeature("autoBind", bindValues[i]);
  600. _pSession->setFeature("autoExtract", bindValues[i+1]);
  601. _pExecutor->floats();
  602. i += 2;
  603. }
  604. }
  605. void ODBCPostgreSQLTest::testDouble()
  606. {
  607. if (!_pSession) fail ("Test not available.");
  608. for (int i = 0; i < 8;)
  609. {
  610. recreateFloatsTable();
  611. _pSession->setFeature("autoBind", bindValues[i]);
  612. _pSession->setFeature("autoExtract", bindValues[i+1]);
  613. _pExecutor->doubles();
  614. i += 2;
  615. }
  616. }
  617. void ODBCPostgreSQLTest::testTuple()
  618. {
  619. if (!_pSession) fail ("Test not available.");
  620. for (int i = 0; i < 8;)
  621. {
  622. recreateTuplesTable();
  623. _pSession->setFeature("autoBind", bindValues[i]);
  624. _pSession->setFeature("autoExtract", bindValues[i+1]);
  625. _pExecutor->tuples();
  626. i += 2;
  627. }
  628. }
  629. void ODBCPostgreSQLTest::testTupleVector()
  630. {
  631. if (!_pSession) fail ("Test not available.");
  632. for (int i = 0; i < 8;)
  633. {
  634. recreateTuplesTable();
  635. _pSession->setFeature("autoBind", bindValues[i]);
  636. _pSession->setFeature("autoExtract", bindValues[i+1]);
  637. _pExecutor->tupleVector();
  638. i += 2;
  639. }
  640. }
  641. void ODBCPostgreSQLTest::testInternalExtraction()
  642. {
  643. if (!_pSession) fail ("Test not available.");
  644. for (int i = 0; i < 8;)
  645. {
  646. recreateVectorsTable();
  647. _pSession->setFeature("autoBind", bindValues[i]);
  648. _pSession->setFeature("autoExtract", bindValues[i+1]);
  649. _pExecutor->internalExtraction();
  650. i += 2;
  651. }
  652. }
  653. void ODBCPostgreSQLTest::testInternalStorageType()
  654. {
  655. if (!_pSession) fail ("Test not available.");
  656. for (int i = 0; i < 8;)
  657. {
  658. recreateVectorsTable();
  659. _pSession->setFeature("autoBind", bindValues[i]);
  660. _pSession->setFeature("autoExtract", bindValues[i+1]);
  661. _pExecutor->internalStorageType();
  662. i += 2;
  663. }
  664. }
  665. void ODBCPostgreSQLTest::dropTable(const std::string& tableName)
  666. {
  667. try
  668. {
  669. *_pSession << format("DROP TABLE %s", tableName), now;
  670. }
  671. catch (StatementException& ex)
  672. {
  673. bool ignoreError = false;
  674. const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
  675. StatementDiagnostics::Iterator it = flds.begin();
  676. for (; it != flds.end(); ++it)
  677. {
  678. if (7 == it->_nativeError)//(table does not exist)
  679. {
  680. ignoreError = true;
  681. break;
  682. }
  683. }
  684. if (!ignoreError) throw;
  685. }
  686. }
  687. void ODBCPostgreSQLTest::recreatePersonTable()
  688. {
  689. dropTable("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 ODBCPostgreSQLTest::recreatePersonBLOBTable()
  695. {
  696. dropTable("Person");
  697. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BYTEA)", 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 ODBCPostgreSQLTest::recreateIntsTable()
  702. {
  703. dropTable("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 ODBCPostgreSQLTest::recreateStringsTable()
  709. {
  710. dropTable("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 ODBCPostgreSQLTest::recreateFloatsTable()
  716. {
  717. dropTable("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 ODBCPostgreSQLTest::recreateTuplesTable()
  723. {
  724. dropTable("Tuples");
  725. try { *_pSession << "CREATE TABLE Tuples "
  726. "(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
  727. "int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
  728. "int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 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 ODBCPostgreSQLTest::recreateVectorsTable()
  733. {
  734. dropTable("Vectors");
  735. try { *_pSession << "CREATE TABLE Vectors (int0 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 ODBCPostgreSQLTest::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=postgres;"
  772. "SERVER=localhost;"
  773. "PORT=5432;"
  774. "UID=postgres;"
  775. "PWD=postgres;"
  776. "SSLMODE=prefer;"
  777. "LowerCaseIdentifier=0;"
  778. "UseServerSidePrepare=0;"
  779. "ByteaAsLongVarBinary=1;"
  780. "BI=0;"
  781. "TrueIsMinus1=0;"
  782. "DisallowPremature=0;"
  783. "UpdatableCursors=0;"
  784. "LFConversion=1;"
  785. "CancelAsFreeStmt=0;"
  786. "Parse=0;"
  787. "BoolsAsChar=1;"
  788. "UnknownsAsLongVarchar=0;"
  789. "TextAsLongVarchar=1;"
  790. "UseDeclareFetch=0;"
  791. "Ksqo=1;"
  792. "Optimizer=1;"
  793. "CommLog=0;"
  794. "Debug=0;"
  795. "MaxLongVarcharSize=8190;"
  796. "MaxVarcharSize=254;"
  797. "UnknownSizes=0;"
  798. "Socket=8192;"
  799. "Fetch=100;"
  800. "ConnSettings=;"
  801. "ShowSystemTables=0;"
  802. "RowVersioning=0;"
  803. "ShowOidColumn=0;"
  804. "FakeOidIndex=0;"
  805. "ReadOnly=0;", driver);
  806. return true;
  807. }
  808. void ODBCPostgreSQLTest::setUp()
  809. {
  810. }
  811. void ODBCPostgreSQLTest::tearDown()
  812. {
  813. dropTable("Person");
  814. dropTable("Strings");
  815. dropTable("Tuples");
  816. }
  817. bool ODBCPostgreSQLTest::init(const std::string& driver, const std::string& dsn)
  818. {
  819. Utility::drivers(_drivers);
  820. if (!canConnect(driver, dsn)) return false;
  821. ODBC::Connector::registerConnector();
  822. try
  823. {
  824. _pSession = new Session(ODBC::Connector::KEY, _dbConnString);
  825. }catch (ConnectionException& ex)
  826. {
  827. std::cout << ex.toString() << std::endl;
  828. return false;
  829. }
  830. if (_pSession && _pSession->isConnected())
  831. std::cout << "*** Connected to [" << driver << "] test database." << std::endl;
  832. _pExecutor = new SQLExecutor(driver + " SQL Executor", _pSession);
  833. return true;
  834. }
  835. CppUnit::Test* ODBCPostgreSQLTest::suite()
  836. {
  837. if (init("PostgreSQL ANSI", "PocoDataPostgreSQLTest"))
  838. {
  839. CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest");
  840. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBareboneODBC);
  841. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccess);
  842. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexType);
  843. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessVector);
  844. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeVector);
  845. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertVector);
  846. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyVector);
  847. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessList);
  848. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeList);
  849. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertList);
  850. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyList);
  851. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessDeque);
  852. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeDeque);
  853. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertDeque);
  854. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyDeque);
  855. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulk);
  856. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulkVec);
  857. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimit);
  858. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitOnce);
  859. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitPrepare);
  860. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitZero);
  861. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testPrepare);
  862. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetSimple);
  863. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplex);
  864. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplexUnique);
  865. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetSimple);
  866. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetComplex);
  867. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplex);
  868. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplexUnique);
  869. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiMapComplex);
  870. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingle);
  871. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleStep);
  872. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleFail);
  873. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitOk);
  874. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitFail);
  875. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedLimits);
  876. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedIllegalLimits);
  877. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testRange);
  878. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testIllegalRange);
  879. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSingleSelect);
  880. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testEmptyDB);
  881. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOB);
  882. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOBStmt);
  883. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testFloat);
  884. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDouble);
  885. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTuple);
  886. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTupleVector);
  887. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalExtraction);
  888. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalStorageType);
  889. return pSuite;
  890. }
  891. return 0;
  892. }