ODBCDB2Test.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. //
  2. // ODBCDB2Test.cpp
  3. //
  4. // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCDB2Test.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 "ODBCDB2Test.h"
  32. #include "CppUnit/TestCaller.h"
  33. #include "CppUnit/TestSuite.h"
  34. #include "Poco/String.h"
  35. #include "Poco/Format.h"
  36. #include "Poco/Any.h"
  37. #include "Poco/DynamicAny.h"
  38. #include "Poco/Tuple.h"
  39. #include "Poco/Exception.h"
  40. #include "Poco/Data/BLOB.h"
  41. #include "Poco/Data/StatementImpl.h"
  42. #include "Poco/Data/ODBC/Connector.h"
  43. #include "Poco/Data/ODBC/Utility.h"
  44. #include "Poco/Data/ODBC/Diagnostics.h"
  45. #include "Poco/Data/ODBC/ODBCException.h"
  46. #include "Poco/Data/ODBC/ODBCStatementImpl.h"
  47. #include <sqltypes.h>
  48. #include <iostream>
  49. using namespace Poco::Data::Keywords;
  50. using Poco::Data::DataException;
  51. using Poco::Data::ODBC::Utility;
  52. using Poco::Data::ODBC::ConnectionException;
  53. using Poco::Data::ODBC::StatementException;
  54. using Poco::Data::ODBC::StatementDiagnostics;
  55. using Poco::format;
  56. using Poco::Tuple;
  57. using Poco::Any;
  58. using Poco::AnyCast;
  59. using Poco::DynamicAny;
  60. using Poco::NotFoundException;
  61. #define DB2_ODBC_DRIVER "IBM DB2 ODBC DRIVER - DB2COPY1"
  62. #define DB2_DSN "PocoDataDB2Test"
  63. #define DB2_SERVER POCO_ODBC_TEST_DATABASE_SERVER
  64. #define DB2_PORT "50000"
  65. #define DB2_DB "POCOTEST"
  66. #define DB2_UID "db2admin"
  67. #define DB2_PWD "db2admin"
  68. ODBCTest::SessionPtr ODBCDB2Test::_pSession;
  69. ODBCTest::ExecPtr ODBCDB2Test::_pExecutor;
  70. std::string ODBCDB2Test::_driver = DB2_ODBC_DRIVER;
  71. std::string ODBCDB2Test::_dsn = DB2_DSN;
  72. std::string ODBCDB2Test::_uid = DB2_UID;
  73. std::string ODBCDB2Test::_pwd = DB2_PWD;
  74. std::string ODBCDB2Test::_connectString = "Driver=" DB2_ODBC_DRIVER ";"
  75. "Database=" DB2_DB ";"
  76. "Hostname=" DB2_SERVER ";"
  77. "Port=" DB2_PORT ";"
  78. "Protocol=TCPIP;"
  79. "Uid=" DB2_UID ";"
  80. "Pwd=" DB2_PWD ";";
  81. ODBCDB2Test::ODBCDB2Test(const std::string& name):
  82. ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
  83. {
  84. }
  85. ODBCDB2Test::~ODBCDB2Test()
  86. {
  87. }
  88. void ODBCDB2Test::testBareboneODBC()
  89. {
  90. if (!_pSession) fail ("Test not available.");
  91. std::string tableCreateString = "CREATE TABLE Test "
  92. "(First VARCHAR(30),"
  93. "Second VARCHAR(30),"
  94. "Third BLOB,"
  95. "Fourth INTEGER,"
  96. "Fifth FLOAT,"
  97. "Sixth TIMESTAMP)";
  98. _pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  99. _pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  100. _pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  101. _pExecutor->bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  102. tableCreateString = "CREATE TABLE Test "
  103. "(First VARCHAR(30),"
  104. "Second INTEGER,"
  105. "Third FLOAT)";
  106. _pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  107. _pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  108. _pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  109. _pExecutor->bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  110. }
  111. void ODBCDB2Test::testBLOB()
  112. {
  113. if (!_pSession) fail ("Test not available.");
  114. const std::size_t maxFldSize = 1000000;
  115. _pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
  116. recreatePersonBLOBTable();
  117. try
  118. {
  119. _pExecutor->blob(maxFldSize);
  120. fail ("must fail");
  121. }
  122. catch (DataException&)
  123. {
  124. _pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
  125. }
  126. for (int i = 0; i < 8;)
  127. {
  128. recreatePersonBLOBTable();
  129. _pSession->setFeature("autoBind", bindValue(i));
  130. _pSession->setFeature("autoExtract", bindValue(i+1));
  131. _pExecutor->blob(maxFldSize);
  132. i += 2;
  133. }
  134. recreatePersonBLOBTable();
  135. try
  136. {
  137. _pExecutor->blob(maxFldSize+1);
  138. fail ("must fail");
  139. }
  140. catch (DataException&) { }
  141. }
  142. void ODBCDB2Test::testStoredProcedure()
  143. {
  144. if (!_pSession) fail ("Test not available.");
  145. for (int k = 0; k < 8;)
  146. {
  147. _pSession->setFeature("autoBind", bindValue(k));
  148. _pSession->setFeature("autoExtract", bindValue(k+1));
  149. dropObject("PROCEDURE", "storedProcedure");
  150. *_pSession << "CREATE PROCEDURE storedProcedure(OUT outParam INTEGER) "
  151. "BEGIN "
  152. " SET outParam = -1; "
  153. "END" , now;
  154. int i = 0;
  155. *_pSession << "{call storedProcedure(?)}", out(i), now;
  156. assert(-1 == i);
  157. dropObject("PROCEDURE", "storedProcedure");
  158. *_pSession << "CREATE PROCEDURE storedProcedure(inParam INTEGER, OUT outParam INTEGER) "
  159. "BEGIN "
  160. " SET outParam = inParam*inParam; "
  161. "END" , now;
  162. i = 2;
  163. int j = 0;
  164. *_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
  165. assert(4 == j);
  166. dropObject("PROCEDURE", "storedProcedure");
  167. *_pSession << "CREATE PROCEDURE storedProcedure(INOUT ioParam INTEGER) "
  168. "BEGIN "
  169. " SET ioParam = ioParam*ioParam; "
  170. "END" , now;
  171. i = 2;
  172. *_pSession << "{call storedProcedure(?)}", io(i), now;
  173. assert(4 == i);
  174. dropObject("PROCEDURE", "storedProcedure");
  175. //TIMESTAMP is not supported as stored procedure parameter in DB2
  176. //(SQL0182N An expression with a datetime value or a labeled duration is not valid.)
  177. *_pSession << "CREATE PROCEDURE storedProcedure(inParam VARCHAR(1000), OUT outParam VARCHAR(1000)) "
  178. "BEGIN "
  179. " SET outParam = inParam; "
  180. "END" , now;
  181. std::string inParam =
  182. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  183. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  184. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  185. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  186. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  187. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  188. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  189. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  190. "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  191. std::string outParam;
  192. *_pSession << "{call storedProcedure(?,?)}", in(inParam), out(outParam), now;
  193. assert(inParam == outParam);
  194. dropObject("PROCEDURE", "storedProcedure");
  195. k += 2;
  196. }
  197. }
  198. void ODBCDB2Test::testStoredProcedureAny()
  199. {
  200. if (!_pSession) fail ("Test not available.");
  201. for (int k = 0; k < 8;)
  202. {
  203. _pSession->setFeature("autoBind", bindValue(k));
  204. _pSession->setFeature("autoExtract", bindValue(k+1));
  205. Any i = 2;
  206. Any j = 0;
  207. *_pSession << "CREATE PROCEDURE storedProcedure(inParam INTEGER, OUT outParam INTEGER) "
  208. "BEGIN "
  209. " SET outParam = inParam*inParam; "
  210. "END" , now;
  211. *_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
  212. assert(4 == AnyCast<int>(j));
  213. *_pSession << "DROP PROCEDURE storedProcedure;", now;
  214. *_pSession << "CREATE PROCEDURE storedProcedure(INOUT ioParam INTEGER) "
  215. "BEGIN "
  216. " SET ioParam = ioParam*ioParam; "
  217. "END" , now;
  218. i = 2;
  219. *_pSession << "{call storedProcedure(?)}", io(i), now;
  220. assert(4 == AnyCast<int>(i));
  221. dropObject("PROCEDURE", "storedProcedure");
  222. k += 2;
  223. }
  224. }
  225. void ODBCDB2Test::testStoredProcedureDynamicAny()
  226. {
  227. if (!_pSession) fail ("Test not available.");
  228. for (int k = 0; k < 8;)
  229. {
  230. _pSession->setFeature("autoBind", bindValue(k));
  231. DynamicAny i = 2;
  232. DynamicAny j = 0;
  233. *_pSession << "CREATE PROCEDURE storedProcedure(inParam INTEGER, OUT outParam INTEGER) "
  234. "BEGIN "
  235. " SET outParam = inParam*inParam; "
  236. "END" , now;
  237. *_pSession << "{call storedProcedure(?, ?)}", in(i), out(j), now;
  238. assert(4 == j);
  239. *_pSession << "DROP PROCEDURE storedProcedure;", now;
  240. *_pSession << "CREATE PROCEDURE storedProcedure(INOUT ioParam INTEGER) "
  241. "BEGIN "
  242. " SET ioParam = ioParam*ioParam; "
  243. "END" , now;
  244. i = 2;
  245. *_pSession << "{call storedProcedure(?)}", io(i), now;
  246. assert(4 == i);
  247. dropObject("PROCEDURE", "storedProcedure");
  248. k += 2;
  249. }
  250. }
  251. void ODBCDB2Test::testStoredFunction()
  252. {
  253. if (!_pSession) fail ("Test not available.");
  254. for (int k = 0; k < 8;)
  255. {
  256. _pSession->setFeature("autoBind", bindValue(k));
  257. _pSession->setFeature("autoExtract", bindValue(k+1));
  258. dropObject("PROCEDURE", "storedFunction");
  259. *_pSession << "CREATE PROCEDURE storedFunction() "
  260. "BEGIN "
  261. " RETURN -1; "
  262. "END" , now;
  263. int i = 0;
  264. *_pSession << "{? = call storedFunction()}", out(i), now;
  265. assert(-1 == i);
  266. dropObject("PROCEDURE", "storedFunction");
  267. *_pSession << "CREATE PROCEDURE storedFunction(inParam INTEGER) "
  268. "BEGIN "
  269. " RETURN inParam*inParam; "
  270. "END" , now;
  271. i = 2;
  272. int result = 0;
  273. *_pSession << "{? = call storedFunction(?)}", out(result), in(i), now;
  274. assert(4 == result);
  275. dropObject("PROCEDURE", "storedFunction");
  276. *_pSession << "CREATE PROCEDURE storedFunction(inParam INTEGER, OUT outParam INTEGER) "
  277. "BEGIN "
  278. " SET outParam = inParam*inParam; "
  279. " RETURN outParam; "
  280. "END" , now;
  281. i = 2;
  282. int j = 0;
  283. result = 0;
  284. *_pSession << "{? = call storedFunction(?, ?)}", out(result), in(i), out(j), now;
  285. assert(4 == j);
  286. assert(j == result);
  287. dropObject("PROCEDURE", "storedFunction");
  288. *_pSession << "CREATE PROCEDURE storedFunction(INOUT param1 INTEGER, INOUT param2 INTEGER) "
  289. "BEGIN "
  290. " DECLARE temp INTEGER;"
  291. " SET temp = param1; "
  292. " SET param1 = param2; "
  293. " SET param2 = temp; "
  294. " RETURN param1 + param2; "
  295. "END" , now;
  296. i = 1;
  297. j = 2;
  298. result = 0;
  299. *_pSession << "{? = call storedFunction(?, ?)}", out(result), io(i), io(j), now;
  300. assert(1 == j);
  301. assert(2 == i);
  302. assert(3 == result);
  303. Tuple<int, int> params(1, 2);
  304. assert(1 == params.get<0>());
  305. assert(2 == params.get<1>());
  306. result = 0;
  307. *_pSession << "{? = call storedFunction(?, ?)}", out(result), io(params), now;
  308. assert(1 == params.get<1>());
  309. assert(2 == params.get<0>());
  310. assert(3 == result);
  311. dropObject("PROCEDURE", "storedFunction");
  312. _pSession->setFeature("autoBind", true);
  313. *_pSession << "CREATE PROCEDURE storedFunction(inParam VARCHAR(10), OUT outParam VARCHAR(10)) "
  314. "BEGIN "
  315. " SET outParam = inParam; "
  316. " RETURN LENGTH(outParam);"//DB2 allows only integer as return type
  317. "END" , now;
  318. std::string inParam = "123456789";
  319. std::string outParam;
  320. int ret;
  321. *_pSession << "{? = call storedFunction(?,?)}", out(ret), in(inParam), out(outParam), now;
  322. assert(inParam == outParam);
  323. assert(ret == inParam.size());
  324. dropObject("PROCEDURE", "storedFunction");
  325. k += 2;
  326. }
  327. }
  328. void ODBCDB2Test::dropObject(const std::string& type, const std::string& name)
  329. {
  330. try
  331. {
  332. *_pSession << format("DROP %s %s", type, name), now;
  333. }
  334. catch (StatementException& ex)
  335. {
  336. bool ignoreError = false;
  337. const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
  338. StatementDiagnostics::Iterator it = flds.begin();
  339. for (; it != flds.end(); ++it)
  340. {
  341. if (-204 == it->_nativeError)//(table does not exist)
  342. {
  343. ignoreError = true;
  344. break;
  345. }
  346. }
  347. if (!ignoreError) throw;
  348. }
  349. }
  350. void ODBCDB2Test::recreatePersonTable()
  351. {
  352. dropObject("TABLE", "Person");
  353. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
  354. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
  355. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
  356. }
  357. void ODBCDB2Test::recreatePersonBLOBTable()
  358. {
  359. dropObject("TABLE", "Person");
  360. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
  361. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  362. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  363. }
  364. void ODBCDB2Test::recreatePersonDateTable()
  365. {
  366. dropObject("TABLE", "Person");
  367. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornDate DATE)", now; }
  368. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTable()"); }
  369. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTable()"); }
  370. }
  371. void ODBCDB2Test::recreatePersonTimeTable()
  372. {
  373. dropObject("TABLE", "Person");
  374. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornTime TIME)", now; }
  375. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
  376. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
  377. }
  378. void ODBCDB2Test::recreatePersonDateTimeTable()
  379. {
  380. dropObject("TABLE", "Person");
  381. try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born TIMESTAMP)", now; }
  382. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
  383. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
  384. }
  385. void ODBCDB2Test::recreateIntsTable()
  386. {
  387. dropObject("TABLE", "Strings");
  388. try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
  389. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
  390. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
  391. }
  392. void ODBCDB2Test::recreateStringsTable()
  393. {
  394. dropObject("TABLE", "Strings");
  395. try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
  396. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
  397. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
  398. }
  399. void ODBCDB2Test::recreateFloatsTable()
  400. {
  401. dropObject("TABLE", "Strings");
  402. try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
  403. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
  404. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
  405. }
  406. void ODBCDB2Test::recreateTuplesTable()
  407. {
  408. dropObject("TABLE", "Tuples");
  409. try { *_pSession << "CREATE TABLE Tuples "
  410. "(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
  411. "int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
  412. "int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
  413. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
  414. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
  415. }
  416. void ODBCDB2Test::recreateVectorsTable()
  417. {
  418. dropObject("TABLE", "Vectors");
  419. try { *_pSession << "CREATE TABLE Vectors (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
  420. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
  421. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
  422. }
  423. void ODBCDB2Test::recreateAnysTable()
  424. {
  425. dropObject("TABLE", "Anys");
  426. try { *_pSession << "CREATE TABLE Anys (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
  427. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
  428. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
  429. }
  430. void ODBCDB2Test::recreateNullsTable(const std::string& notNull)
  431. {
  432. dropObject("TABLE", "NullTest");
  433. try { *_pSession << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
  434. notNull,
  435. notNull,
  436. notNull), now; }
  437. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
  438. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
  439. }
  440. void ODBCDB2Test::recreateMiscTable()
  441. {
  442. dropObject("TABLE", "MiscTest");
  443. try
  444. {
  445. session() << "CREATE TABLE MiscTest "
  446. "(First VARCHAR(30),"
  447. "Second BLOB,"
  448. "Third INTEGER,"
  449. "Fourth FLOAT,"
  450. "Fifth TIMESTAMP)", now;
  451. } catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateMiscTable()"); }
  452. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateMiscTable()"); }
  453. }
  454. void ODBCDB2Test::recreateLogTable()
  455. {
  456. dropObject("TABLE", "T_POCO_LOG");
  457. dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
  458. try
  459. {
  460. std::string sql = "CREATE TABLE %s "
  461. "(Source VARCHAR(100),"
  462. "Name VARCHAR(100),"
  463. "ProcessId INTEGER,"
  464. "Thread VARCHAR(100), "
  465. "ThreadId INTEGER,"
  466. "Priority INTEGER,"
  467. "Text VARCHAR(100),"
  468. "DateTime TIMESTAMP)";
  469. session() << sql, "T_POCO_LOG", now;
  470. session() << sql, "T_POCO_LOG_ARCHIVE", now;
  471. } catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
  472. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
  473. }
  474. CppUnit::Test* ODBCDB2Test::suite()
  475. {
  476. if (_pSession = init(_driver, _dsn, _uid, _pwd, _connectString))
  477. {
  478. std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
  479. _pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
  480. CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test");
  481. CppUnit_addTest(pSuite, ODBCDB2Test, testBareboneODBC);
  482. CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccess);
  483. CppUnit_addTest(pSuite, ODBCDB2Test, testComplexType);
  484. CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessVector);
  485. CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeVector);
  486. CppUnit_addTest(pSuite, ODBCDB2Test, testInsertVector);
  487. CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyVector);
  488. CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessList);
  489. CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeList);
  490. CppUnit_addTest(pSuite, ODBCDB2Test, testInsertList);
  491. CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyList);
  492. CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessDeque);
  493. CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeDeque);
  494. CppUnit_addTest(pSuite, ODBCDB2Test, testInsertDeque);
  495. CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyDeque);
  496. CppUnit_addTest(pSuite, ODBCDB2Test, testAffectedRows);
  497. CppUnit_addTest(pSuite, ODBCDB2Test, testInsertSingleBulk);
  498. CppUnit_addTest(pSuite, ODBCDB2Test, testInsertSingleBulkVec);
  499. CppUnit_addTest(pSuite, ODBCDB2Test, testLimit);
  500. CppUnit_addTest(pSuite, ODBCDB2Test, testLimitOnce);
  501. CppUnit_addTest(pSuite, ODBCDB2Test, testLimitPrepare);
  502. CppUnit_addTest(pSuite, ODBCDB2Test, testLimitZero);
  503. CppUnit_addTest(pSuite, ODBCDB2Test, testPrepare);
  504. CppUnit_addTest(pSuite, ODBCDB2Test, testBulk);
  505. CppUnit_addTest(pSuite, ODBCDB2Test, testBulkPerformance);
  506. CppUnit_addTest(pSuite, ODBCDB2Test, testSetSimple);
  507. CppUnit_addTest(pSuite, ODBCDB2Test, testSetComplex);
  508. CppUnit_addTest(pSuite, ODBCDB2Test, testSetComplexUnique);
  509. CppUnit_addTest(pSuite, ODBCDB2Test, testMultiSetSimple);
  510. CppUnit_addTest(pSuite, ODBCDB2Test, testMultiSetComplex);
  511. CppUnit_addTest(pSuite, ODBCDB2Test, testMapComplex);
  512. CppUnit_addTest(pSuite, ODBCDB2Test, testMapComplexUnique);
  513. CppUnit_addTest(pSuite, ODBCDB2Test, testMultiMapComplex);
  514. CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingle);
  515. CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingleStep);
  516. CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingleFail);
  517. CppUnit_addTest(pSuite, ODBCDB2Test, testLowerLimitOk);
  518. CppUnit_addTest(pSuite, ODBCDB2Test, testLowerLimitFail);
  519. CppUnit_addTest(pSuite, ODBCDB2Test, testCombinedLimits);
  520. CppUnit_addTest(pSuite, ODBCDB2Test, testCombinedIllegalLimits);
  521. CppUnit_addTest(pSuite, ODBCDB2Test, testRange);
  522. CppUnit_addTest(pSuite, ODBCDB2Test, testIllegalRange);
  523. CppUnit_addTest(pSuite, ODBCDB2Test, testSingleSelect);
  524. CppUnit_addTest(pSuite, ODBCDB2Test, testEmptyDB);
  525. CppUnit_addTest(pSuite, ODBCDB2Test, testBLOB);
  526. CppUnit_addTest(pSuite, ODBCDB2Test, testBLOBContainer);
  527. CppUnit_addTest(pSuite, ODBCDB2Test, testBLOBStmt);
  528. CppUnit_addTest(pSuite, ODBCDB2Test, testDate);
  529. CppUnit_addTest(pSuite, ODBCDB2Test, testTime);
  530. CppUnit_addTest(pSuite, ODBCDB2Test, testDateTime);
  531. CppUnit_addTest(pSuite, ODBCDB2Test, testFloat);
  532. CppUnit_addTest(pSuite, ODBCDB2Test, testDouble);
  533. CppUnit_addTest(pSuite, ODBCDB2Test, testTuple);
  534. CppUnit_addTest(pSuite, ODBCDB2Test, testTupleVector);
  535. CppUnit_addTest(pSuite, ODBCDB2Test, testInternalExtraction);
  536. CppUnit_addTest(pSuite, ODBCDB2Test, testInternalBulkExtraction);
  537. CppUnit_addTest(pSuite, ODBCDB2Test, testInternalStorageType);
  538. CppUnit_addTest(pSuite, ODBCDB2Test, testStoredProcedure);
  539. CppUnit_addTest(pSuite, ODBCDB2Test, testStoredProcedureAny);
  540. CppUnit_addTest(pSuite, ODBCDB2Test, testStoredProcedureDynamicAny);
  541. CppUnit_addTest(pSuite, ODBCDB2Test, testStoredFunction);
  542. CppUnit_addTest(pSuite, ODBCDB2Test, testNull);
  543. CppUnit_addTest(pSuite, ODBCDB2Test, testRowIterator);
  544. CppUnit_addTest(pSuite, ODBCDB2Test, testAsync);
  545. CppUnit_addTest(pSuite, ODBCDB2Test, testAny);
  546. CppUnit_addTest(pSuite, ODBCDB2Test, testDynamicAny);
  547. CppUnit_addTest(pSuite, ODBCDB2Test, testMultipleResults);
  548. CppUnit_addTest(pSuite, ODBCDB2Test, testSQLChannel);
  549. CppUnit_addTest(pSuite, ODBCDB2Test, testSQLLogger);
  550. return pSuite;
  551. }
  552. return 0;
  553. }