ODBCPostgreSQLTest.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. //
  2. // ODBCPostgreSQLTest.cpp
  3. //
  4. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  5. // and Contributors.
  6. //
  7. // SPDX-License-Identifier: BSL-1.0
  8. //
  9. #include "ODBCPostgreSQLTest.h"
  10. #include "CppUnit/TestCaller.h"
  11. #include "CppUnit/TestSuite.h"
  12. #include "ODBCTest.h"
  13. #include "Poco/Format.h"
  14. #include "Poco/Any.h"
  15. #include "Poco/DynamicAny.h"
  16. #include "Poco/DateTime.h"
  17. #include "Poco/Data/ODBC/Diagnostics.h"
  18. #include "Poco/Data/ODBC/ODBCException.h"
  19. #include <iostream>
  20. using namespace Poco::Data::Keywords;
  21. using Poco::Data::DataException;
  22. using Poco::Data::ODBC::ConnectionException;
  23. using Poco::Data::ODBC::StatementException;
  24. using Poco::Data::ODBC::StatementDiagnostics;
  25. using Poco::format;
  26. using Poco::Any;
  27. using Poco::AnyCast;
  28. using Poco::DynamicAny;
  29. using Poco::DateTime;
  30. #ifdef POCO_ODBC_USE_MAMMOTH_NG
  31. #define POSTGRESQL_ODBC_DRIVER "Mammoth ODBCng Beta"
  32. #elif defined (POCO_ODBC_UNICODE)
  33. #ifdef POCO_PTR_IS_64_BIT
  34. #define POSTGRESQL_ODBC_DRIVER "PostgreSQL Unicode(x64)"
  35. #else
  36. #define POSTGRESQL_ODBC_DRIVER "PostgreSQL Unicode"
  37. #endif
  38. #define POSTGRESQL_DSN "PocoDataPgSQLTestW"
  39. #else
  40. #ifdef POCO_PTR_IS_64_BIT
  41. #define POSTGRESQL_ODBC_DRIVER "PostgreSQL ANSI(x64)"
  42. #else
  43. #define POSTGRESQL_ODBC_DRIVER "PostgreSQL ANSI"
  44. #endif
  45. #define POSTGRESQL_DSN "PocoDataPgSQLTest"
  46. #endif
  47. #if defined(POCO_OS_FAMILY_WINDOWS)
  48. #pragma message ("Using " POSTGRESQL_ODBC_DRIVER " driver.")
  49. #endif
  50. #define POSTGRESQL_SERVER POCO_ODBC_TEST_DATABASE_SERVER
  51. #define POSTGRESQL_PORT "5432"
  52. #define POSTGRESQL_DB "postgres"
  53. #define POSTGRESQL_UID "postgres"
  54. #define POSTGRESQL_PWD "poco"
  55. #define POSTGRESQL_VERSION "10"
  56. #ifdef POCO_OS_FAMILY_WINDOWS
  57. const std::string ODBCPostgreSQLTest::_libDir = "C:\\\\Program Files\\\\PostgreSQL\\\\pg" POSTGRESQL_VERSION "\\\\lib\\\\";
  58. #else
  59. const std::string ODBCPostgreSQLTest::_libDir = "/usr/local/pgsql/lib/";
  60. #endif
  61. ODBCTest::SessionPtr ODBCPostgreSQLTest::_pSession;
  62. ODBCTest::ExecPtr ODBCPostgreSQLTest::_pExecutor;
  63. std::string ODBCPostgreSQLTest::_driver = POSTGRESQL_ODBC_DRIVER;
  64. std::string ODBCPostgreSQLTest::_dsn = POSTGRESQL_DSN;
  65. std::string ODBCPostgreSQLTest::_uid = POSTGRESQL_UID;
  66. std::string ODBCPostgreSQLTest::_pwd = POSTGRESQL_PWD;
  67. std::string ODBCPostgreSQLTest::_connectString =
  68. "DRIVER=" POSTGRESQL_ODBC_DRIVER ";"
  69. "DATABASE=" POSTGRESQL_DB ";"
  70. "SERVER=" POSTGRESQL_SERVER ";"
  71. "PORT=" POSTGRESQL_PORT ";"
  72. "UID=" POSTGRESQL_UID ";"
  73. "PWD=" POSTGRESQL_PWD ";"
  74. "SSLMODE=prefer;"
  75. "LowerCaseIdentifier=0;"
  76. "UseServerSidePrepare=0;"
  77. "ByteaAsLongVarBinary=1;"
  78. "BI=0;"
  79. "TrueIsMinus1=0;"
  80. "DisallowPremature=0;"
  81. "UpdatableCursors=0;"
  82. "LFConversion=1;"
  83. "CancelAsFreeStmt=0;"
  84. "Parse=0;"
  85. "BoolsAsChar=1;"
  86. "UnknownsAsLongVarchar=0;"
  87. "TextAsLongVarchar=1;"
  88. "UseDeclareFetch=0;"
  89. "Ksqo=1;"
  90. "Optimizer=1;"
  91. "CommLog=0;"
  92. "Debug=0;"
  93. "MaxLongVarcharSize=8190;"
  94. "MaxVarcharSize=254;"
  95. "UnknownSizes=0;"
  96. "Socket=8192;"
  97. "Fetch=100;"
  98. "ConnSettings=;"
  99. "ShowSystemTables=0;"
  100. "RowVersioning=0;"
  101. "ShowOidColumn=0;"
  102. "FakeOidIndex=0;"
  103. "ReadOnly=0;";
  104. ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& name):
  105. ODBCTest(name, _pSession, _pExecutor, _dsn, _uid, _pwd, _connectString)
  106. {
  107. }
  108. ODBCPostgreSQLTest::~ODBCPostgreSQLTest()
  109. {
  110. }
  111. void ODBCPostgreSQLTest::testBareboneODBC()
  112. {
  113. std::string tableCreateString = "CREATE TABLE Test "
  114. "(First VARCHAR(30),"
  115. "Second VARCHAR(30),"
  116. "Third BYTEA,"
  117. "Fourth INTEGER,"
  118. "Fifth FLOAT,"
  119. "Sixth TIMESTAMP)";
  120. executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  121. executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  122. executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  123. executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  124. tableCreateString = "CREATE TABLE Test "
  125. "(First VARCHAR(30),"
  126. "Second VARCHAR(30),"
  127. "Third BYTEA,"
  128. "Fourth INTEGER,"
  129. "Fifth FLOAT,"
  130. "Sixth DATE)";
  131. executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL, false);
  132. executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND, false);
  133. executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL, false);
  134. executor().bareboneODBCTest(_connectString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND, false);
  135. //neither pSQL ODBC nor Mammoth drivers support multiple results properly
  136. /*
  137. tableCreateString = "CREATE TABLE Test "
  138. "(First VARCHAR(30),"
  139. "Second INTEGER,"
  140. "Third FLOAT)";
  141. executor().bareboneODBCMultiResultTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
  142. executor().bareboneODBCMultiResultTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
  143. executor().bareboneODBCMultiResultTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
  144. executor().bareboneODBCMultiResultTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
  145. */
  146. }
  147. void ODBCPostgreSQLTest::testBLOB()
  148. {
  149. const std::size_t maxFldSize = 1000000;
  150. session().setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
  151. recreatePersonBLOBTable();
  152. try
  153. {
  154. executor().blob(maxFldSize);
  155. fail ("must fail");
  156. }
  157. catch (DataException&)
  158. {
  159. session().setProperty("maxFieldSize", Poco::Any(maxFldSize));
  160. }
  161. for (int i = 0; i < 8;)
  162. {
  163. recreatePersonBLOBTable();
  164. session().setFeature("autoBind", bindValue(i));
  165. session().setFeature("autoExtract", bindValue(i+1));
  166. executor().blob(1000000);
  167. i += 2;
  168. }
  169. }
  170. void ODBCPostgreSQLTest::testStoredFunction()
  171. {
  172. configurePLPgSQL();
  173. std::string func("testStoredFunction()");
  174. for (int k = 0; k < 8;)
  175. {
  176. session().setFeature("autoBind", bindValue(k));
  177. session().setFeature("autoExtract", bindValue(k+1));
  178. dropObject("FUNCTION", "storedFunction()");
  179. try
  180. {
  181. session() << "CREATE FUNCTION storedFunction() RETURNS INTEGER AS '"
  182. "BEGIN "
  183. " return -1; "
  184. "END;'"
  185. "LANGUAGE 'plpgsql'", now;
  186. }
  187. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
  188. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
  189. int i = 0;
  190. session() << "{? = call storedFunction()}", out(i), now;
  191. assertTrue (-1 == i);
  192. dropObject("FUNCTION", "storedFunction()");
  193. try
  194. {
  195. session() << "CREATE FUNCTION storedFunction(INTEGER) RETURNS INTEGER AS '"
  196. "BEGIN "
  197. " RETURN $1 * $1; "
  198. "END;'"
  199. "LANGUAGE 'plpgsql'" , now;
  200. }
  201. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
  202. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
  203. i = 2;
  204. int result = 0;
  205. session() << "{? = call storedFunction(?)}", out(result), in(i), now;
  206. assertTrue (4 == result);
  207. dropObject("FUNCTION", "storedFunction(INTEGER)");
  208. dropObject("FUNCTION", "storedFunction(TIMESTAMP)");
  209. try
  210. {
  211. session() << "CREATE FUNCTION storedFunction(TIMESTAMP) RETURNS TIMESTAMP AS '"
  212. "BEGIN "
  213. " RETURN $1; "
  214. "END;'"
  215. "LANGUAGE 'plpgsql'" , now;
  216. }
  217. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
  218. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
  219. DateTime dtIn(1965, 6, 18, 5, 35, 1);
  220. DateTime dtOut;
  221. session() << "{? = call storedFunction(?)}", out(dtOut), in(dtIn), now;
  222. assertTrue (dtOut == dtIn);
  223. dropObject("FUNCTION", "storedFunction(TIMESTAMP)");
  224. dropObject("FUNCTION", "storedFunction(TEXT, TEXT)");
  225. try
  226. {
  227. session() << "CREATE FUNCTION storedFunction(TEXT,TEXT) RETURNS TEXT AS '"
  228. "BEGIN "
  229. " RETURN $1 || '', '' || $2 || ''!'';"
  230. "END;'"
  231. "LANGUAGE 'plpgsql'" , now;
  232. }
  233. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
  234. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
  235. std::string param1 = "Hello";
  236. std::string param2 = "world";
  237. std::string ret;
  238. try
  239. {
  240. session() << "{? = call storedFunction(?,?)}", out(ret), in(param1), in(param2), now;
  241. }
  242. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (func); }
  243. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (func); }
  244. assertTrue (ret == "Hello, world!");
  245. dropObject("FUNCTION", "storedFunction(TEXT, TEXT)");
  246. k += 2;
  247. }
  248. }
  249. void ODBCPostgreSQLTest::testStoredFunctionAny()
  250. {
  251. session() << "CREATE FUNCTION storedFunction(INTEGER) RETURNS INTEGER AS '"
  252. "BEGIN "
  253. " RETURN $1 * $1; "
  254. "END;'"
  255. "LANGUAGE 'plpgsql'" , now;
  256. for (int k = 0; k < 8;)
  257. {
  258. session().setFeature("autoBind", bindValue(k));
  259. session().setFeature("autoExtract", bindValue(k+1));
  260. Any i = 2;
  261. Any result = 0;
  262. session() << "{? = call storedFunction(?)}", out(result), in(i), now;
  263. assertTrue (4 == AnyCast<int>(result));
  264. k += 2;
  265. }
  266. dropObject("FUNCTION", "storedFunction(INTEGER)");
  267. }
  268. void ODBCPostgreSQLTest::testStoredFunctionDynamicAny()
  269. {
  270. session() << "CREATE FUNCTION storedFunction(INTEGER) RETURNS INTEGER AS '"
  271. "BEGIN "
  272. " RETURN $1 * $1; "
  273. "END;'"
  274. "LANGUAGE 'plpgsql'" , now;
  275. for (int k = 0; k < 8;)
  276. {
  277. session().setFeature("autoBind", bindValue(k));
  278. session().setFeature("autoExtract", bindValue(k+1));
  279. DynamicAny i = 2;
  280. DynamicAny result = 0;
  281. session() << "{? = call storedFunction(?)}", out(result), in(i), now;
  282. assertTrue (4 == result);
  283. k += 2;
  284. }
  285. dropObject("FUNCTION", "storedFunction(INTEGER)");
  286. }
  287. void ODBCPostgreSQLTest::configurePLPgSQL()
  288. {
  289. try
  290. {
  291. session() << format("CREATE FUNCTION plpgsql_call_handler () "
  292. "RETURNS OPAQUE "
  293. "AS '%splpgsql.dll' "
  294. "LANGUAGE 'C';", _libDir), now;
  295. session() << "CREATE LANGUAGE 'plpgsql' "
  296. "HANDLER plpgsql_call_handler "
  297. "LANCOMPILER 'PL/pgSQL'", now;
  298. }catch(StatementException& ex)
  299. {
  300. if (1 != ex.diagnostics().nativeError(0))
  301. throw;
  302. }
  303. return;
  304. }
  305. void ODBCPostgreSQLTest::dropObject(const std::string& type, const std::string& name)
  306. {
  307. try
  308. {
  309. session() << format("DROP %s %s", type, name), now;
  310. }
  311. catch (StatementException& ex)
  312. {
  313. bool ignoreError = false;
  314. const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
  315. StatementDiagnostics::Iterator it = flds.begin();
  316. for (; it != flds.end(); ++it)
  317. {
  318. if (1 == it->_nativeError)//(table does not exist)
  319. {
  320. ignoreError = true;
  321. break;
  322. }
  323. }
  324. if (!ignoreError) throw;
  325. }
  326. }
  327. void ODBCPostgreSQLTest::recreateNullableTable()
  328. {
  329. dropObject("TABLE", "NullableTest");
  330. try { *_pSession << "CREATE TABLE NullableTest (EmptyString VARCHAR(30) NULL, EmptyInteger INTEGER NULL, EmptyFloat FLOAT NULL , EmptyDateTime TIMESTAMP NULL)", now; }
  331. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
  332. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
  333. }
  334. void ODBCPostgreSQLTest::recreatePersonTable()
  335. {
  336. dropObject("TABLE", "Person");
  337. try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
  338. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
  339. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
  340. }
  341. void ODBCPostgreSQLTest::recreatePersonBLOBTable()
  342. {
  343. dropObject("TABLE", "Person");
  344. try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BYTEA)", now; }
  345. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  346. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
  347. }
  348. void ODBCPostgreSQLTest::recreatePersonDateTimeTable()
  349. {
  350. dropObject("TABLE", "Person");
  351. try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Born TIMESTAMP)", now; }
  352. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
  353. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTimeTable()"); }
  354. }
  355. void ODBCPostgreSQLTest::recreatePersonDateTable()
  356. {
  357. dropObject("TABLE", "Person");
  358. try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornDate DATE)", now; }
  359. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonDateTable()"); }
  360. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonDateTable()"); }
  361. }
  362. void ODBCPostgreSQLTest::recreatePersonTimeTable()
  363. {
  364. dropObject("TABLE", "Person");
  365. try { session() << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), BornTime TIME)", now; }
  366. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
  367. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTimeTable()"); }
  368. }
  369. void ODBCPostgreSQLTest::recreateIntsTable()
  370. {
  371. dropObject("TABLE", "Strings");
  372. try { session() << "CREATE TABLE Strings (str INTEGER)", now; }
  373. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
  374. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
  375. }
  376. void ODBCPostgreSQLTest::recreateStringsTable()
  377. {
  378. dropObject("TABLE", "Strings");
  379. try { session() << "CREATE TABLE Strings (str VARCHAR(30))", now; }
  380. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
  381. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
  382. }
  383. void ODBCPostgreSQLTest::recreateFloatsTable()
  384. {
  385. dropObject("TABLE", "Strings");
  386. try { session() << "CREATE TABLE Strings (str FLOAT)", now; }
  387. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
  388. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
  389. }
  390. void ODBCPostgreSQLTest::recreateTuplesTable()
  391. {
  392. dropObject("TABLE", "Tuples");
  393. try { session() << "CREATE TABLE Tuples "
  394. "(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
  395. "int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
  396. "int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
  397. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
  398. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
  399. }
  400. void ODBCPostgreSQLTest::recreateVectorsTable()
  401. {
  402. dropObject("TABLE", "Vectors");
  403. try { session() << "CREATE TABLE Vectors (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
  404. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
  405. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
  406. }
  407. void ODBCPostgreSQLTest::recreateAnysTable()
  408. {
  409. dropObject("TABLE", "Anys");
  410. try { session() << "CREATE TABLE Anys (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
  411. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateAnysTable()"); }
  412. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateAnysTable()"); }
  413. }
  414. void ODBCPostgreSQLTest::recreateNullsTable(const std::string& notNull)
  415. {
  416. dropObject("TABLE", "NullTest");
  417. try { session() << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
  418. notNull,
  419. notNull,
  420. notNull), now; }
  421. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
  422. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
  423. }
  424. void ODBCPostgreSQLTest::recreateBoolTable()
  425. {
  426. dropObject("TABLE", "BoolTest");
  427. try { session() << "CREATE TABLE BoolTest (b BOOLEAN)", now; }
  428. catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateBoolTable()"); }
  429. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateBoolTable()"); }
  430. }
  431. void ODBCPostgreSQLTest::recreateMiscTable()
  432. {
  433. dropObject("TABLE", "MiscTest");
  434. try
  435. {
  436. // Mammoth does not bind columns properly
  437. session() << "CREATE TABLE MiscTest "
  438. "(First VARCHAR(30),"
  439. "Second BYTEA,"
  440. "Third INTEGER,"
  441. "Fourth FLOAT,"
  442. "Fifth TIMESTAMP)", now;
  443. } catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateMiscTable()"); }
  444. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateMiscTable()"); }
  445. }
  446. void ODBCPostgreSQLTest::recreateLogTable()
  447. {
  448. dropObject("TABLE", "T_POCO_LOG");
  449. dropObject("TABLE", "T_POCO_LOG_ARCHIVE");
  450. try
  451. {
  452. std::string sql = "CREATE TABLE %s "
  453. "(Source VARCHAR,"
  454. "Name VARCHAR,"
  455. "ProcessId INTEGER,"
  456. "Thread VARCHAR, "
  457. "ThreadId INTEGER,"
  458. "Priority INTEGER,"
  459. "Text VARCHAR,"
  460. "DateTime TIMESTAMP)";
  461. session() << sql, "T_POCO_LOG", now;
  462. session() << sql, "T_POCO_LOG_ARCHIVE", now;
  463. } catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateLogTable()"); }
  464. catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateLogTable()"); }
  465. }
  466. void ODBCPostgreSQLTest::recreateUnicodeTable()
  467. {
  468. #if defined (POCO_ODBC_UNICODE)
  469. dropObject("TABLE", "UnicodeTable");
  470. try { session() << "CREATE TABLE UnicodeTable (str TEXT)", now; }
  471. catch (ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail("recreateUnicodeTable()"); }
  472. catch (StatementException& se){ std::cout << se.toString() << std::endl; fail("recreateUnicodeTable()"); }
  473. #endif
  474. }
  475. CppUnit::Test* ODBCPostgreSQLTest::suite()
  476. {
  477. if ((_pSession = init(_driver, _dsn, _uid, _pwd, _connectString)))
  478. {
  479. std::cout << "*** Connected to [" << _driver << "] test database." << std::endl;
  480. _pExecutor = new SQLExecutor(_driver + " SQL Executor", _pSession);
  481. CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest");
  482. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBareboneODBC);
  483. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testZeroRows);
  484. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccess);
  485. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexType);
  486. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessVector);
  487. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeVector);
  488. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSharedPtrComplexTypeVector);
  489. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testAutoPtrComplexTypeVector);
  490. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertVector);
  491. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyVector);
  492. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessList);
  493. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeList);
  494. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertList);
  495. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyList);
  496. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessDeque);
  497. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeDeque);
  498. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertDeque);
  499. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyDeque);
  500. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testAffectedRows);
  501. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulk);
  502. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulkVec);
  503. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimit);
  504. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitOnce);
  505. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitPrepare);
  506. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitZero);
  507. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testPrepare);
  508. //On Linux, PostgreSQL driver returns SQL_NEED_DATA on SQLExecute (see ODBCStatementImpl::bindImpl() )
  509. //this behavior is not expected and not handled for automatic binding
  510. #ifdef POCO_OS_FAMILY_WINDOWS
  511. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBulk);
  512. #endif
  513. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBulkPerformance);
  514. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetSimple);
  515. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplex);
  516. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplexUnique);
  517. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetSimple);
  518. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetComplex);
  519. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplex);
  520. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplexUnique);
  521. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiMapComplex);
  522. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingle);
  523. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleStep);
  524. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleFail);
  525. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitOk);
  526. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitFail);
  527. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedLimits);
  528. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedIllegalLimits);
  529. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testRange);
  530. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testIllegalRange);
  531. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSingleSelect);
  532. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testEmptyDB);
  533. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOB);
  534. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOBContainer);
  535. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOBStmt);
  536. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDate);
  537. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTime);
  538. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDateTime);
  539. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testFloat);
  540. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDouble);
  541. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTuple);
  542. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTupleVector);
  543. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalExtraction);
  544. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testFilter);
  545. //On Linux, PostgreSQL driver returns SQL_NEED_DATA on SQLExecute (see ODBCStatementImpl::bindImpl() )
  546. //this behavior is not expected and not handled for automatic binding
  547. #ifdef POCO_OS_FAMILY_WINDOWS
  548. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalBulkExtraction);
  549. #endif
  550. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalStorageType);
  551. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testStoredFunction);
  552. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testStoredFunctionAny);
  553. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testStoredFunctionDynamicAny);
  554. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testNull);
  555. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testRowIterator);
  556. #ifdef POCO_ODBC_USE_MAMMOTH_NG
  557. // psqlODBC driver returns string for bool fields
  558. // even when field is explicitly cast to boolean,
  559. // so this functionality seems to be untestable with it
  560. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testStdVectorBool);
  561. #endif
  562. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testAsync);
  563. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testAny);
  564. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDynamicAny);
  565. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultipleResults);
  566. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSQLChannel);
  567. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSQLLogger);
  568. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSessionTransaction);
  569. // (postgres bug?)
  570. // local session claims to be capable of reading uncommitted changes,
  571. // but fails to do so
  572. //CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransaction);
  573. //CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransactor);
  574. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testNullable);
  575. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testUnicode);
  576. CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testReconnect);
  577. return pSuite;
  578. }
  579. return 0;
  580. }