SF [2643953] Improve Data::Session connection

This commit is contained in:
Aleksandar Fabijanic
2009-02-27 03:14:53 +00:00
parent 9bef44cab6
commit 68a79674c1
50 changed files with 689 additions and 165 deletions

View File

@@ -507,6 +507,15 @@ void MySQLTest::testTransaction()
}
void MySQLTest::testReconnect()
{
if (!_pSession) fail ("Test not available.");
recreatePersonTable();
_pExecutor->reconnect();
}
void MySQLTest::testNullableInt()
{
if (!_pSession) fail ("Test not available.");
@@ -813,6 +822,7 @@ CppUnit::Test* MySQLTest::suite()
CppUnit_addTest(pSuite, MySQLTest, testTupleWithNullable);
CppUnit_addTest(pSuite, MySQLTest, testSessionTransaction);
CppUnit_addTest(pSuite, MySQLTest, testTransaction);
CppUnit_addTest(pSuite, MySQLTest, testReconnect);
return pSuite;
}

View File

@@ -116,6 +116,8 @@ public:
void testSessionTransaction();
void testTransaction();
void testReconnect();
void setUp();
void tearDown();

View File

@@ -476,7 +476,7 @@ void SQLExecutor::insertSingleBulk()
for (x = 0; x < 100; ++x)
{
int i = stmt.execute();
std::size_t i = stmt.execute();
assert (i == 0);
}
@@ -1803,3 +1803,44 @@ void SQLExecutor::transaction(const std::string& connect)
_pSession->setFeature("autoCommit", autoCommit);
}
void SQLExecutor::reconnect()
{
std::string funct = "reconnect()";
std::string lastName = "lastName";
std::string firstName("firstName");
std::string address("Address");
int age = 133132;
int count = 0;
std::string result;
try { (*_pSession) << "INSERT INTO PERSON VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(age), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
count = 0;
try { (*_pSession) << "SELECT COUNT(*) FROM PERSON", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assert (count == 1);
assert (_pSession->isConnected());
_pSession->close();
assert (!_pSession->isConnected());
try
{
(*_pSession) << "SELECT LastName FROM PERSON", into(result), now;
fail ("must fail");
}
catch(NotConnectedException&){ }
assert (!_pSession->isConnected());
_pSession->open();
assert (_pSession->isConnected());
try { (*_pSession) << "SELECT Age FROM PERSON", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail (funct); }
assert (count == age);
assert (_pSession->isConnected());
}

View File

@@ -113,6 +113,8 @@ public:
void sessionTransaction(const std::string& connect);
void transaction(const std::string& connect);
void reconnect();
private:
void setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti);