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

@@ -681,6 +681,7 @@ CppUnit::Test* ODBCDB2Test::suite()
CppUnit_addTest(pSuite, ODBCDB2Test, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCDB2Test, testTransaction);
CppUnit_addTest(pSuite, ODBCDB2Test, testTransactor);
CppUnit_addTest(pSuite, ODBCDB2Test, testReconnect);
return pSuite;
}

View File

@@ -497,6 +497,7 @@ CppUnit::Test* ODBCMySQLTest::suite()
CppUnit_addTest(pSuite, ODBCMySQLTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransaction);
CppUnit_addTest(pSuite, ODBCMySQLTest, testTransactor);
CppUnit_addTest(pSuite, ODBCMySQLTest, testReconnect);
return pSuite;
}

View File

@@ -922,6 +922,7 @@ CppUnit::Test* ODBCOracleTest::suite()
CppUnit_addTest(pSuite, ODBCOracleTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCOracleTest, testTransaction);
CppUnit_addTest(pSuite, ODBCOracleTest, testTransactor);
CppUnit_addTest(pSuite, ODBCOracleTest, testReconnect);
return pSuite;
}

View File

@@ -659,6 +659,7 @@ CppUnit::Test* ODBCPostgreSQLTest::suite()
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransaction);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTransactor);
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testReconnect);
return pSuite;
}

View File

@@ -809,6 +809,7 @@ CppUnit::Test* ODBCSQLServerTest::suite()
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransactor);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testReconnect);
return pSuite;
}

View File

@@ -400,6 +400,7 @@ CppUnit::Test* ODBCSQLiteTest::suite()
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testTransaction);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testTransactor);
CppUnit_addTest(pSuite, ODBCSQLiteTest, testReconnect);
return pSuite;
}

View File

@@ -47,12 +47,14 @@
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
#include "Poco/Data/DataException.h"
#include <sqltypes.h>
#include <iostream>
using namespace Poco::Data::Keywords;
using Poco::Data::Session;
using Poco::Data::ConnectionFailedException;
using Poco::Data::CLOB;
using Poco::Data::ODBC::Utility;
using Poco::Data::ODBC::ODBCException;
@@ -1187,6 +1189,23 @@ void ODBCTest::testTransactor()
}
void ODBCTest::testReconnect()
{
if (!_pSession) fail ("Test not available.");
std::string tableName("Person");
for (int i = 0; i < 8;)
{
recreatePersonTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->reconnect();
i += 2;
}
}
bool ODBCTest::canConnect(const std::string& driver,
std::string& dsn,
std::string& uid,
@@ -1262,9 +1281,9 @@ ODBCTest::SessionPtr ODBCTest::init(const std::string& driver,
try
{
return new Session(Poco::Data::ODBC::Connector::KEY, dbConnString);
}catch (ConnectionException& ex)
}catch (ConnectionFailedException& ex)
{
std::cout << ex.toString() << std::endl;
std::cout << ex.displayText() << std::endl;
return 0;
}
}

View File

@@ -167,6 +167,8 @@ public:
virtual void testTransaction();
virtual void testTransactor();
virtual void testReconnect();
protected:
typedef Poco::Data::ODBC::Utility::DriverMap Drivers;

View File

@@ -85,6 +85,7 @@ using Poco::Data::CLOB;
using Poco::Data::Date;
using Poco::Data::Time;
using Poco::Data::Transaction;
using Poco::Data::NotConnectedException;
using Poco::Data::ODBC::Utility;
using Poco::Data::ODBC::Preparator;
using Poco::Data::ODBC::ConnectionException;
@@ -3763,3 +3764,44 @@ void SQLExecutor::transactor()
session().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 { session() << "INSERT INTO PERSON VALUES (?,?,?,?)", use(lastName), use(firstName), use(address), use(age), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
count = 0;
try { session() << "SELECT COUNT(*) FROM PERSON", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (count == 1);
assert (session().isConnected());
session().close();
assert (!session().isConnected());
try
{
session() << "SELECT LastName FROM PERSON", into(result), now;
fail ("must fail");
}
catch(NotConnectedException&){ }
assert (!session().isConnected());
session().open();
assert (session().isConnected());
try { session() << "SELECT Age FROM PERSON", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
assert (count == age);
assert (session().isConnected());
}

View File

@@ -518,6 +518,8 @@ public:
void transaction(const std::string& connect);
void transactor();
void reconnect();
private:
static const std::string MULTI_INSERT;
static const std::string MULTI_SELECT;