Skip to content

Commit f266504

Browse files
committed
MySQL: added test sessionPoolAndUnicode (from #2801)
1 parent f574617 commit f266504

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

Data/MySQL/testsuite/src/MySQLTest.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,15 @@ void MySQLTest::testTupleWithNullable()
727727
}
728728

729729

730+
void MySQLTest::testSessionPoolAndUnicode()
731+
{
732+
if (!_pSession) fail ("Test not available.");
733+
734+
recreateStringsTable();
735+
_pExecutor->sessionPoolAndUnicode(_dbConnString);
736+
}
737+
738+
730739
void MySQLTest::dropTable(const std::string& tableName)
731740
{
732741
try { *_pSession << format("DROP TABLE IF EXISTS %s", tableName), now; }
@@ -993,6 +1002,6 @@ CppUnit::Test* MySQLTest::suite()
9931002
CppUnit_addTest(pSuite, MySQLTest, testSessionTransaction);
9941003
CppUnit_addTest(pSuite, MySQLTest, testTransaction);
9951004
CppUnit_addTest(pSuite, MySQLTest, testReconnect);
996-
1005+
CppUnit_addTest(pSuite, MySQLTest, testSessionPoolAndUnicode);
9971006
return pSuite;
9981007
}

Data/MySQL/testsuite/src/MySQLTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class MySQLTest: public CppUnit::TestCase
107107
void testTransaction();
108108

109109
void testReconnect();
110+
void testSessionPoolAndUnicode();
110111

111112
void setUp();
112113
void tearDown();

Data/MySQL/testsuite/src/SQLExecutor.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Poco/Data/Time.h"
2222
#include "Poco/Data/StatementImpl.h"
2323
#include "Poco/Data/RecordSet.h"
24+
#include "Poco/Data/SessionPool.h"
2425
#include "Poco/Data/Transaction.h"
2526
#include "Poco/Data/MySQL/Connector.h"
2627
#include "Poco/Data/MySQL/MySQLException.h"
@@ -1372,7 +1373,7 @@ void SQLExecutor::timestamp()
13721373
std::string firstName("Simpson");
13731374
std::string address("Springfield");
13741375
DateTime birthday(1980, 4, 1, 5, 45, 12, 354, 879);
1375-
1376+
13761377
int count = 0;
13771378
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
13781379
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
@@ -1381,14 +1382,14 @@ void SQLExecutor::timestamp()
13811382
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
13821383
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
13831384
assertTrue (count == 1);
1384-
1385+
13851386
DateTime bd;
13861387
assertTrue (bd != birthday);
13871388
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
13881389
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
13891390
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
13901391
assertTrue (bd == birthday);
1391-
1392+
13921393
std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
13931394
}
13941395

@@ -2066,3 +2067,31 @@ void SQLExecutor::reconnect()
20662067
assertTrue (count == age);
20672068
assertTrue (_pSession->isConnected());
20682069
}
2070+
2071+
2072+
void SQLExecutor::sessionPoolAndUnicode(const std::string& connString)
2073+
{
2074+
std::string funct = "unicode()";
2075+
std::string text = "ěščřžťďůň";
2076+
std::string text2;
2077+
2078+
// Test uses session from SessionPool instead of _pSession to prove session
2079+
// obtained and returned into pool is valid.
2080+
2081+
// Min/Max 1 session - ensures that when get() is called, same session should be returned
2082+
Poco::SharedPtr<Poco::Data::SessionPool> sp = new Poco::Data::SessionPool(MySQL::Connector::KEY, connString, 1, 1);
2083+
2084+
{
2085+
Poco::Data::Session session = sp->get();
2086+
try { session << "INSERT INTO Strings VALUES (?)", use(text), now; }
2087+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
2088+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
2089+
} // parentheses to ensure session is returned into pool
2090+
2091+
Poco::Data::Session session2 = sp->get();
2092+
try { session2 << "SELECT str FROM Strings", into(text2), now; }
2093+
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
2094+
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
2095+
2096+
assertTrue (text == text2);
2097+
}

Data/MySQL/testsuite/src/SQLExecutor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class SQLExecutor: public CppUnit::TestCase
8888
void longText();
8989
#ifdef POCO_MYSQL_JSON
9090
void json();
91-
#endif
91+
#endif
9292
void unsignedInts();
9393
void floats();
9494
void doubles();
@@ -103,6 +103,7 @@ class SQLExecutor: public CppUnit::TestCase
103103
void transaction(const std::string& connect);
104104

105105
void reconnect();
106+
void sessionPoolAndUnicode(const std::string& connString);
106107

107108
private:
108109
void setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti);

0 commit comments

Comments
 (0)