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+ }
0 commit comments