Skip to content

Commit

Permalink
MySQL: added test sessionPoolAndUnicode (from #2801)
Browse files Browse the repository at this point in the history
  • Loading branch information
frwilckens committed Dec 14, 2023
1 parent f574617 commit f266504
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Data/MySQL/testsuite/src/MySQLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,15 @@ void MySQLTest::testTupleWithNullable()
}


void MySQLTest::testSessionPoolAndUnicode()
{
if (!_pSession) fail ("Test not available.");

recreateStringsTable();
_pExecutor->sessionPoolAndUnicode(_dbConnString);
}


void MySQLTest::dropTable(const std::string& tableName)
{
try { *_pSession << format("DROP TABLE IF EXISTS %s", tableName), now; }
Expand Down Expand Up @@ -993,6 +1002,6 @@ CppUnit::Test* MySQLTest::suite()
CppUnit_addTest(pSuite, MySQLTest, testSessionTransaction);
CppUnit_addTest(pSuite, MySQLTest, testTransaction);
CppUnit_addTest(pSuite, MySQLTest, testReconnect);

CppUnit_addTest(pSuite, MySQLTest, testSessionPoolAndUnicode);
return pSuite;
}
1 change: 1 addition & 0 deletions Data/MySQL/testsuite/src/MySQLTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class MySQLTest: public CppUnit::TestCase
void testTransaction();

void testReconnect();
void testSessionPoolAndUnicode();

void setUp();
void tearDown();
Expand Down
35 changes: 32 additions & 3 deletions Data/MySQL/testsuite/src/SQLExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Poco/Data/Time.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/RecordSet.h"
#include "Poco/Data/SessionPool.h"
#include "Poco/Data/Transaction.h"
#include "Poco/Data/MySQL/Connector.h"
#include "Poco/Data/MySQL/MySQLException.h"
Expand Down Expand Up @@ -1372,7 +1373,7 @@ void SQLExecutor::timestamp()
std::string firstName("Simpson");
std::string address("Springfield");
DateTime birthday(1980, 4, 1, 5, 45, 12, 354, 879);

int count = 0;
try { *_pSession << "INSERT INTO Person VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(birthday), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
Expand All @@ -1381,14 +1382,14 @@ void SQLExecutor::timestamp()
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assertTrue (count == 1);

DateTime bd;
assertTrue (bd != birthday);
try { *_pSession << "SELECT Birthday FROM Person", into(bd), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assertTrue (bd == birthday);

std::cout << std::endl << RecordSet(*_pSession, "SELECT * FROM Person");
}

Expand Down Expand Up @@ -2066,3 +2067,31 @@ void SQLExecutor::reconnect()
assertTrue (count == age);
assertTrue (_pSession->isConnected());
}


void SQLExecutor::sessionPoolAndUnicode(const std::string& connString)
{
std::string funct = "unicode()";
std::string text = "ěščřžťďůň";
std::string text2;

// Test uses session from SessionPool instead of _pSession to prove session
// obtained and returned into pool is valid.

// Min/Max 1 session - ensures that when get() is called, same session should be returned
Poco::SharedPtr<Poco::Data::SessionPool> sp = new Poco::Data::SessionPool(MySQL::Connector::KEY, connString, 1, 1);

{
Poco::Data::Session session = sp->get();
try { session << "INSERT INTO Strings VALUES (?)", use(text), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
} // parentheses to ensure session is returned into pool

Poco::Data::Session session2 = sp->get();
try { session2 << "SELECT str FROM Strings", into(text2), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }

assertTrue (text == text2);
}
3 changes: 2 additions & 1 deletion Data/MySQL/testsuite/src/SQLExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SQLExecutor: public CppUnit::TestCase
void longText();
#ifdef POCO_MYSQL_JSON
void json();
#endif
#endif
void unsignedInts();
void floats();
void doubles();
Expand All @@ -103,6 +103,7 @@ class SQLExecutor: public CppUnit::TestCase
void transaction(const std::string& connect);

void reconnect();
void sessionPoolAndUnicode(const std::string& connString);

private:
void setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti);
Expand Down

0 comments on commit f266504

Please sign in to comment.