ODBCSQLServerTest.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. //
  2. // ODBCSQLServerTest.cpp
  3. //
  4. // $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCSQLServerTest.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 "ODBCSQLServerTest.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/DateTime.h"
  40. #include "Poco/Data/RecordSet.h"
  41. #include "Poco/Data/ODBC/Diagnostics.h"
  42. #include "Poco/Data/ODBC/ODBCException.h"
  43. #include "Poco/Data/ODBC/ODBCStatementImpl.h"
  44. #include <iostream>
  45. using namespace Poco::Data::Keywords;
  46. using Poco::Data::DataException;
  47. using Poco::Data::Statement;
  48. using Poco::Data::RecordSet;
  49. using Poco::Data::BLOB;
  50. using Poco::Data::ODBC::Utility;
  51. using Poco::Data::ODBC::ConnectionException;
  52. using Poco::Data::ODBC::StatementException;
  53. using Poco::Data::ODBC::StatementDiagnostics;
  54. using Poco::format;
  55. using Poco::Tuple;
  56. using Poco::Any;
  57. using Poco::AnyCast;
  58. using Poco::DynamicAny;
  59. using Poco::DateTime;
  60. #ifdef POCO_OS_FAMILY_WINDOWS
  61. #ifdef POCO_ODBC_USE_SQL_NATIVE
  62. #define MS_SQL_SERVER_ODBC_DRIVER "SQL Native Client"
  63. #else
  64. #define MS_SQL_SERVER_ODBC_DRIVER "SQL Server"
  65. #endif
  66. #else
  67. #define MS_SQL_SERVER_ODBC_DRIVER "FreeTDS"
  68. #endif
  69. #define MS_SQL_SERVER_DSN "PocoDataSQLServerTest"
  70. #define MS_SQL_SERVER_SERVER POCO_ODBC_TEST_DATABASE_SERVER
  71. #define MS_SQL_SERVER_PORT "1433"
  72. #define MS_SQL_SERVER_DB "test"
  73. #define MS_SQL_SERVER_UID "test"
  74. #define MS_SQL_SERVER_PWD "test"
  75. ODBCTest::SessionPtr ODBCSQLServerTest::_pSession;
  76. ODBCTest::ExecPtr ODBCSQLServerTest::_pExecutor;
  77. std::string ODBCSQLServerTest::_driver = MS_SQL_SERVER_ODBC_DRIVER;
  78. std::string ODBCSQLServerTest::_dsn = MS_SQL_SERVER_DSN;
  79. std::string ODBCSQLServerTest::_uid = MS_SQL_SERVER_UID;
  80. std::string ODBCSQLServerTest::_pwd = MS_SQL_SERVER_PWD;
  81. std::string ODBCSQLServerTest::_db = MS_SQL_SERVER_DB;
  82. std::string ODBCSQLServerTest::_connectString = "DRIVER=" MS_SQL_SERVER_ODBC_DRIVER ";"
  83. "UID=" MS_SQL_SERVER_UID ";"
  84. "PWD=" MS_SQL_SERVER_PWD ";"
  85. "DATABASE=" MS_SQL_SERVER_DB ";"
  86. "SERVER=" MS_SQL_SERVER_SERVER ";"
  87. "PORT=" MS_SQL_SERVER_PORT ";";
  88. ODBCSQLServerTest::ODBCSQLServerTest(const std::string& name):
  89. ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
  90. {
  91. }
  92. ODBCSQLServerTest::~ODBCSQLServerTest()
  93. {
  94. }
  95. void ODBCSQLServerTest::testBareboneODBC()
  96. {
  97. std::string tableCreateString = "CREATE TABLE Test "
  98. "(First VARCHAR(30),"
  99. "Second VARCHAR(30),"
  100. "Third VARBINARY(30),"
  101. "Fourth INTEGER,"
  102. "Fifth FLOAT,"
  103. "Sixth DATETIME)";
  104. executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  105. executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  106. executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  107. executor().bareboneODBCTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  108. tableCreateString = "CREATE TABLE Test "
  109. "(First VARCHAR(30),"
  110. "Second INTEGER,"
  111. "Third FLOAT)";
  112. executor().bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  113. executor().bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  114. executor().bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  115. executor().bareboneODBCMultiResultTest(dbConnString(), tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  116. }
  117. void ODBCSQLServerTest::testBLOB()
  118. {
  119. const std::size_t maxFldSize = 250000;
  120. session().setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
  121. recreatePersonBLOBTable();
  122. try
  123. {
  124. executor().blob(maxFldSize);
  125. fail ("must fail");
  126. }
  127. catch (DataException&)
  128. {
  129. session().setProperty("maxFieldSize", Poco::Any(maxFldSize));
  130. }
  131. for (int i = 0; i < 8;)
  132. {
  133. recreatePersonBLOBTable();
  134. session().setFeature("autoBind", bindValue(i));
  135. session().setFeature("autoExtract", bindValue(i+1));
  136. executor().blob(maxFldSize);
  137. i += 2;
  138. }
  139. recreatePersonBLOBTable();
  140. try
  141. {
  142. executor().blob(maxFldSize+1);
  143. fail ("must fail");
  144. }
  145. catch (DataException&) { }
  146. }
  147. void ODBCSQLServerTest::testNull()
  148. {
  149. // test for NOT NULL violation exception
  150. for (int i = 0; i < 8;)
  151. {
  152. recreateNullsTable("NOT NULL");
  153. session().setFeature("autoBind", bindValue(i));
  154. session().setFeature("autoExtract", bindValue(i+1));
  155. executor().notNulls("23000");
  156. i += 2;
  157. }
  158. // test for null insertion
  159. for (int i = 0; i < 8;)
  160. {
  161. recreateNullsTable();
  162. session().setFeature("autoBind", bindValue(i));
  163. session().setFeature("autoExtract", bindValue(i+1));
  164. executor().nulls();
  165. i += 2;
  166. }
  167. }
  168. void ODBCSQLServerTest::testBulk()
  169. {
  170. if (!_pSession) fail ("Test not available.");
  171. _pSession->setFeature("autoBind", true);
  172. _pSession->setFeature("autoExtract", true);
  173. recreateMiscTable();
  174. _pExecutor->doBulkWithBool<std::vector<int>,
  175. std::vector<std::string>,
  176. std::vector<BLOB>,
  177. std::vector<double>,
  178. std::vector<DateTime>,
  179. std::vector<bool> >(100);
  180. recreateMiscTable();
  181. _pExecutor->doBulkWithBool<std::deque<int>,
  182. std::deque<std::string>,
  183. std::deque<BLOB>,
  184. std::deque<double>,
  185. std::deque<DateTime>,
  186. std::deque<bool> >(100);
  187. recreateMiscTable();
  188. _pExecutor->doBulkWithBool<std::list<int>,
  189. std::list<std::string>,
  190. std::list<BLOB>,
  191. std::list<double>,
  192. std::list<DateTime>,
  193. std::list<bool> >(100);
  194. }
  195. void ODBCSQLServerTest::testStoredProcedure()
  196. {
  197. for (int k = 0; k < 8;)
  198. {
  199. session().setFeature("autoBind", bindValue(k));
  200. session().setFeature("autoExtract", bindValue(k+1));
  201. dropObject("PROCEDURE", "storedProcedure");
  202. session() << "CREATE PROCEDURE storedProcedure(@outParam int OUTPUT) AS "
  203. "BEGIN "
  204. "SET @outParam = -1; "
  205. "END;"
  206. , now;
  207. int i = 0;
  208. session() << "{call storedProcedure(?)}", out(i), now;
  209. assert(-1 == i);
  210. dropObject("PROCEDURE", "storedProcedure");
  211. session() << "CREATE PROCEDURE storedProcedure(@inParam int, @outParam int OUTPUT) AS "
  212. "BEGIN "
  213. "SET @outParam = @inParam*@inParam; "
  214. "END;"
  215. , now;
  216. i = 2;
  217. int j = 0;
  218. session() << "{call storedProcedure(?, ?)}", in(i), out(j), now;
  219. assert(4 == j);
  220. dropObject("PROCEDURE", "storedProcedure");
  221. session() << "CREATE PROCEDURE storedProcedure(@ioParam int OUTPUT) AS "
  222. "BEGIN "
  223. "SET @ioParam = @ioParam*@ioParam; "
  224. "END;"
  225. , now;
  226. i = 2;
  227. session() << "{call storedProcedure(?)}", io(i), now;
  228. assert(4 == i);
  229. dropObject("PROCEDURE", "storedProcedure");
  230. session() << "CREATE PROCEDURE storedProcedure(@ioParam DATETIME OUTPUT) AS "
  231. "BEGIN "
  232. " SET @ioParam = @ioParam + 1; "
  233. "END;" , now;
  234. DateTime dt(1965, 6, 18, 5, 35, 1);
  235. session() << "{call storedProcedure(?)}", io(dt), now;
  236. assert(19 == dt.day());
  237. dropObject("PROCEDURE", "storedProcedure");
  238. k += 2;
  239. }
  240. /*TODO - currently fails with following error:
  241. [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid parameter
  242. 2 (''): Data type 0x23 is a deprecated large object, or LOB, but is marked as output parameter.
  243. Deprecated types are not supported as output parameters. Use current large object types instead.
  244. session().setFeature("autoBind", true);
  245. session() << "CREATE PROCEDURE storedProcedure(@inParam VARCHAR(MAX), @outParam VARCHAR(MAX) OUTPUT) AS "
  246. "BEGIN "
  247. "SET @outParam = @inParam; "
  248. "END;"
  249. , now;
  250. std::string inParam = "123";
  251. std::string outParam;
  252. try{
  253. session() << "{call storedProcedure(?, ?)}", in(inParam), out(outParam), now;
  254. }catch(StatementException& ex){std::cout << ex.toString();}
  255. assert(outParam == inParam);
  256. dropObject("PROCEDURE", "storedProcedure");
  257. */
  258. }
  259. void ODBCSQLServerTest::testCursorStoredProcedure()
  260. {
  261. for (int k = 0; k < 8;)
  262. {
  263. session().setFeature("autoBind", bindValue(k));
  264. session().setFeature("autoExtract", bindValue(k+1));
  265. recreatePersonTable();
  266. typedef Tuple<std::string, std::string, std::string, int> Person;
  267. std::vector<Person> people;
  268. people.push_back(Person("Simpson", "Homer", "Springfield", 42));
  269. people.push_back(Person("Simpson", "Bart", "Springfield", 12));
  270. people.push_back(Person("Simpson", "Lisa", "Springfield", 10));
  271. session() << "INSERT INTO Person VALUES (?, ?, ?, ?)", use(people), now;
  272. dropObject("PROCEDURE", "storedCursorProcedure");
  273. session() << "CREATE PROCEDURE storedCursorProcedure(@ageLimit int) AS "
  274. "BEGIN "
  275. " SELECT * "
  276. " FROM Person "
  277. " WHERE Age < @ageLimit "
  278. " ORDER BY Age DESC; "
  279. "END;"
  280. , now;
  281. people.clear();
  282. int age = 13;
  283. session() << "{call storedCursorProcedure(?)}", in(age), into(people), now;
  284. assert (2 == people.size());
  285. assert (Person("Simpson", "Bart", "Springfield", 12) == people[0]);
  286. assert (Person("Simpson", "Lisa", "Springfield", 10) == people[1]);
  287. Statement stmt = ((session() << "{call storedCursorProcedure(?)}", in(age), now));
  288. RecordSet rs(stmt);
  289. assert (rs["LastName"] == "Simpson");
  290. assert (rs["FirstName"] == "Bart");
  291. assert (rs["Address"] == "Springfield");
  292. assert (rs["Age"] == 12);
  293. dropObject("TABLE", "Person");
  294. dropObject("PROCEDURE", "storedCursorProcedure");
  295. k += 2;
  296. }
  297. }
  298. void ODBCSQLServerTest::testStoredProcedureAny()
  299. {
  300. for (int k = 0; k < 8;)
  301. {
  302. session().setFeature("autoBind", bindValue(k));
  303. session().setFeature("autoExtract", bindValue(k+1));
  304. Any i = 2;
  305. Any j = 0;
  306. session() << "CREATE PROCEDURE storedProcedure(@inParam int, @outParam int OUTPUT) AS "
  307. "BEGIN "
  308. "SET @outParam = @inParam*@inParam; "
  309. "END;"
  310. , now;
  311. session() << "{call storedProcedure(?, ?)}", in(i), out(j), now;
  312. assert(4 == AnyCast<int>(j));
  313. session() << "DROP PROCEDURE storedProcedure;", now;
  314. session() << "CREATE PROCEDURE storedProcedure(@ioParam int OUTPUT) AS "
  315. "BEGIN "
  316. "SET @ioParam = @ioParam*@ioParam; "
  317. "END;"
  318. , now;
  319. i = 2;
  320. session() << "{call storedProcedure(?)}", io(i), now;
  321. assert(4 == AnyCast<int>(i));
  322. dropObject("PROCEDURE", "storedProcedure");
  323. k += 2;
  324. }
  325. }
  326. void ODBCSQLServerTest::testStoredProcedureDynamicAny()
  327. {
  328. for (int k = 0; k < 8;)
  329. {
  330. session().setFeature("autoBind", bindValue(k));
  331. DynamicAny i = 2;
  332. DynamicAny j = 0;
  333. session() << "CREATE PROCEDURE storedProcedure(@inParam int, @outParam int OUTPUT) AS "
  334. "BEGIN "
  335. "SET @outParam = @inParam*@inParam; "
  336. "END;"
  337. , now;
  338. session() << "{call storedProcedure(?, ?)}", in(i), out(j), now;
  339. assert(4 == j);
  340. session() << "DROP PROCEDURE storedProcedure;", now;
  341. session() << "CREATE PROCEDURE storedProcedure(@ioParam int OUTPUT) AS "
  342. "BEGIN "
  343. "SET @ioParam = @ioParam*@ioParam; "
  344. "END;"
  345. , now;
  346. i = 2;
  347. session() << "{call storedProcedure(?)}", io(i), now;
  348. assert(4 == i);
  349. dropObject("PROCEDURE", "storedProcedure");
  350. k += 2;
  351. }
  352. }
  353. void ODBCSQLServerTest::testStoredFunction()
  354. {
  355. for (int k = 0; k < 8;)
  356. {
  357. session().setFeature("autoBind", bindValue(k));
  358. session().setFeature("autoExtract", bindValue(k+1));
  359. dropObject("PROCEDURE", "storedFunction");
  360. session() << "CREATE PROCEDURE storedFunction AS "
  361. "BEGIN "
  362. "DECLARE @retVal int;"
  363. "SET @retVal = -1;"
  364. "RETURN @retVal;"
  365. "END;"
  366. , now;
  367. int i = 0;
  368. session() << "{? = call storedFunction}", out(i), now;
  369. assert(-1 == i);
  370. dropObject("PROCEDURE", "storedFunction");
  371. session() << "CREATE PROCEDURE storedFunction(@inParam int) AS "
  372. "BEGIN "
  373. "RETURN @inParam*@inParam;"
  374. "END;"
  375. , now;
  376. i = 2;
  377. int result = 0;
  378. session() << "{? = call storedFunction(?)}", out(result), in(i), now;
  379. assert(4 == result);
  380. dropObject("PROCEDURE", "storedFunction");
  381. session() << "CREATE PROCEDURE storedFunction(@inParam int, @outParam int OUTPUT) AS "
  382. "BEGIN "
  383. "SET @outParam = @inParam*@inParam;"
  384. "RETURN @outParam;"
  385. "END"
  386. , now;
  387. i = 2;
  388. int j = 0;
  389. result = 0;
  390. session() << "{? = call storedFunction(?, ?)}", out(result), in(i), out(j), now;
  391. assert(4 == j);
  392. assert(j == result);
  393. dropObject("PROCEDURE", "storedFunction");
  394. session() << "CREATE PROCEDURE storedFunction(@param1 int OUTPUT,@param2 int OUTPUT) AS "
  395. "BEGIN "
  396. "DECLARE @temp int; "
  397. "SET @temp = @param1;"
  398. "SET @param1 = @param2;"
  399. "SET @param2 = @temp;"
  400. "RETURN @param1 + @param2; "
  401. "END"
  402. , now;
  403. i = 1;
  404. j = 2;
  405. result = 0;
  406. session() << "{? = call storedFunction(?, ?)}", out(result), io(i), io(j), now;
  407. assert(1 == j);
  408. assert(2 == i);
  409. assert(3 == result);
  410. Tuple<int, int> params(1, 2);
  411. assert(1 == params.get<0>());
  412. assert(2 == params.get<1>());
  413. result = 0;
  414. session() << "{? = call storedFunction(?, ?)}", out(result), io(params), now;
  415. assert(1 == params.get<1>());
  416. assert(2 == params.get<0>());
  417. assert(3 == result);
  418. dropObject("PROCEDURE", "storedFunction");
  419. k += 2;
  420. }
  421. }
  422. void ODBCSQLServerTest::dropObject(const std::string& type, const std::string& name)
  423. {
  424. try
  425. {
  426. session() << format("DROP %s %s", type, name), now;
  427. }
  428. catch (StatementException& ex)
  429. {
  430. bool ignoreError = false;
  431. const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
  432. StatementDiagnostics::Iterator it = flds.begin();
  433. for (; it != flds.end(); ++it)
  434. {
  435. if (3701 == it->_nativeError)//(table does not exist)
  436. {
  437. ignoreError = true;
  438. break;
  439. }
  440. }
  441. if (!ignoreError) throw;
  442. }
  443. }
  444. void ODBCSQLServerTest::recreatePersonTable()
  445. {
  446. dropObject("TABLE", "Person");
  447. try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
  448. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
  449. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
  450. }
  451. void ODBCSQLServerTest::recreatePersonBLOBTable()
  452. {
  453. dropObject("TABLE", "Person");
  454. try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image VARBINARY(MAX))", now; }
  455. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  456. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  457. }
  458. void ODBCSQLServerTest::recreatePersonDateTimeTable()
  459. {
  460. dropObject("TABLE", "Person");
  461. try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born DATETIME)", now; }
  462. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
  463. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
  464. }
  465. void ODBCSQLServerTest::recreateIntsTable()
  466. {
  467. dropObject("TABLE", "Strings");
  468. try { session() << "CREATE TABLE Strings (str INTEGER)", now; }
  469. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
  470. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
  471. }
  472. void ODBCSQLServerTest::recreateStringsTable()
  473. {
  474. dropObject("TABLE", "Strings");
  475. try { session() << "CREATE TABLE Strings (str VARCHAR(30))", now; }
  476. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
  477. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
  478. }
  479. void ODBCSQLServerTest::recreateFloatsTable()
  480. {
  481. dropObject("TABLE", "Strings");
  482. try { session() << "CREATE TABLE Strings (str FLOAT)", now; }
  483. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
  484. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
  485. }
  486. void ODBCSQLServerTest::recreateTuplesTable()
  487. {
  488. dropObject("TABLE", "Tuples");
  489. try { session() << "CREATE TABLE Tuples "
  490. "(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
  491. "int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
  492. "int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
  493. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
  494. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
  495. }
  496. void ODBCSQLServerTest::recreateVectorTable()
  497. {
  498. dropObject("TABLE", "Vector");
  499. try { session() << "CREATE TABLE Vector (i0 INTEGER)", now; }
  500. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorTable()"); }
  501. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorTable()"); }
  502. }
  503. void ODBCSQLServerTest::recreateVectorsTable()
  504. {
  505. dropObject("TABLE", "Vectors");
  506. try { session() << "CREATE TABLE Vectors (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
  507. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
  508. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
  509. }
  510. void ODBCSQLServerTest::recreateAnysTable()
  511. {
  512. dropObject("TABLE", "Anys");
  513. try { session() << "CREATE TABLE Anys (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
  514. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
  515. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
  516. }
  517. void ODBCSQLServerTest::recreateNullsTable(const std::string& notNull)
  518. {
  519. dropObject("TABLE", "NullTest");
  520. try { session() << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
  521. notNull,
  522. notNull,
  523. notNull), now; }
  524. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
  525. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
  526. }
  527. void ODBCSQLServerTest::recreateBoolTable()
  528. {
  529. dropObject("TABLE", "BoolTest");
  530. try { session() << "CREATE TABLE BoolTest (b BIT)", now; }
  531. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateBoolTable()"); }
  532. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateBoolTable()"); }
  533. }
  534. void ODBCSQLServerTest::recreateMiscTable()
  535. {
  536. dropObject("TABLE", "MiscTest");
  537. try
  538. {
  539. session() << "CREATE TABLE MiscTest "
  540. "(First VARCHAR(30),"
  541. "Second VARBINARY(30),"
  542. "Third INTEGER,"
  543. "Fourth FLOAT,"
  544. "Fifth DATETIME,"
  545. "Sixth BIT)", now;
  546. } catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateMiscTable()"); }
  547. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateMiscTable()"); }
  548. }
  549. void ODBCSQLServerTest::recreateLogTable()
  550. {
  551. dropObject("TABLE", "T_POCO_LOG");
  552. dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
  553. try
  554. {
  555. std::string sql = "CREATE TABLE %s "
  556. "(Source VARCHAR(max),"
  557. "Name VARCHAR(max),"
  558. "ProcessId INTEGER,"
  559. "Thread VARCHAR(max), "
  560. "ThreadId INTEGER,"
  561. "Priority INTEGER,"
  562. "Text VARCHAR(max),"
  563. "DateTime DATETIME)";
  564. session() << sql, "T_POCO_LOG", now;
  565. session() << sql, "T_POCO_LOG_ARCHIVE", now;
  566. } catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
  567. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
  568. }
  569. CppUnit::Test* ODBCSQLServerTest::suite()
  570. {
  571. if (_pSession = init(_driver, _dsn, _uid, _pwd, _connectString, _db))
  572. {
  573. std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
  574. _pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
  575. CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLServerTest");
  576. CppUnit_addTest(pSuite, ODBCSQLServerTest, testBareboneODBC);
  577. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccess);
  578. CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexType);
  579. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccessVector);
  580. CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexTypeVector);
  581. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertVector);
  582. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertEmptyVector);
  583. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccessList);
  584. CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexTypeList);
  585. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertList);
  586. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertEmptyList);
  587. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccessDeque);
  588. CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexTypeDeque);
  589. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertDeque);
  590. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertEmptyDeque);
  591. CppUnit_addTest(pSuite, ODBCSQLServerTest, testAffectedRows);
  592. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertSingleBulk);
  593. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertSingleBulkVec);
  594. CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimit);
  595. CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitOnce);
  596. CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitPrepare);
  597. CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitZero);
  598. CppUnit_addTest(pSuite, ODBCSQLServerTest, testPrepare);
  599. CppUnit_addTest(pSuite, ODBCSQLServerTest, testBulk);
  600. CppUnit_addTest(pSuite, ODBCSQLServerTest, testBulkPerformance);
  601. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetSimple);
  602. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetComplex);
  603. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetComplexUnique);
  604. CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiSetSimple);
  605. CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiSetComplex);
  606. CppUnit_addTest(pSuite, ODBCSQLServerTest, testMapComplex);
  607. CppUnit_addTest(pSuite, ODBCSQLServerTest, testMapComplexUnique);
  608. CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiMapComplex);
  609. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingle);
  610. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingleStep);
  611. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingleFail);
  612. CppUnit_addTest(pSuite, ODBCSQLServerTest, testLowerLimitOk);
  613. CppUnit_addTest(pSuite, ODBCSQLServerTest, testLowerLimitFail);
  614. CppUnit_addTest(pSuite, ODBCSQLServerTest, testCombinedLimits);
  615. CppUnit_addTest(pSuite, ODBCSQLServerTest, testCombinedIllegalLimits);
  616. CppUnit_addTest(pSuite, ODBCSQLServerTest, testRange);
  617. CppUnit_addTest(pSuite, ODBCSQLServerTest, testIllegalRange);
  618. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSingleSelect);
  619. CppUnit_addTest(pSuite, ODBCSQLServerTest, testEmptyDB);
  620. CppUnit_addTest(pSuite, ODBCSQLServerTest, testBLOB);
  621. CppUnit_addTest(pSuite, ODBCSQLServerTest, testBLOBContainer);
  622. CppUnit_addTest(pSuite, ODBCSQLServerTest, testBLOBStmt);
  623. CppUnit_addTest(pSuite, ODBCSQLServerTest, testDateTime);
  624. CppUnit_addTest(pSuite, ODBCSQLServerTest, testFloat);
  625. CppUnit_addTest(pSuite, ODBCSQLServerTest, testDouble);
  626. CppUnit_addTest(pSuite, ODBCSQLServerTest, testTuple);
  627. CppUnit_addTest(pSuite, ODBCSQLServerTest, testTupleVector);
  628. CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredProcedure);
  629. CppUnit_addTest(pSuite, ODBCSQLServerTest, testCursorStoredProcedure);
  630. CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredProcedureAny);
  631. CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredProcedureDynamicAny);
  632. CppUnit_addTest(pSuite, ODBCSQLServerTest, testStoredFunction);
  633. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInternalExtraction);
  634. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInternalBulkExtraction);
  635. CppUnit_addTest(pSuite, ODBCSQLServerTest, testInternalStorageType);
  636. CppUnit_addTest(pSuite, ODBCSQLServerTest, testNull);
  637. CppUnit_addTest(pSuite, ODBCSQLServerTest, testRowIterator);
  638. CppUnit_addTest(pSuite, ODBCSQLServerTest, testStdVectorBool);
  639. CppUnit_addTest(pSuite, ODBCSQLServerTest, testAsync);
  640. CppUnit_addTest(pSuite, ODBCSQLServerTest, testAny);
  641. CppUnit_addTest(pSuite, ODBCSQLServerTest, testDynamicAny);
  642. CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultipleResults);
  643. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSQLChannel);
  644. CppUnit_addTest(pSuite, ODBCSQLServerTest, testSQLLogger);
  645. return pSuite;
  646. }
  647. return 0;
  648. }