mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 02:06:04 +02:00
Tests tidy-up, DSN-less connections, preparation ODBCColumn pos fix
This commit is contained in:
@@ -314,7 +314,7 @@ inline std::size_t Preparation::maxDataSize(std::size_t pos) const
|
||||
|
||||
try
|
||||
{
|
||||
sz = ODBCColumn(_rStmt, pos).length();
|
||||
sz = ODBCColumn(_rStmt, pos-1).length();
|
||||
}
|
||||
catch (StatementException&)
|
||||
{
|
||||
|
||||
@@ -58,43 +58,13 @@ using Poco::NotFoundException;
|
||||
|
||||
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCAccessTest::_pSession = 0;
|
||||
std::string ODBCAccessTest::_dsn = "PocoDataAccessTest";
|
||||
std::string ODBCAccessTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCAccessTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCAccessTest::_dataSources;
|
||||
|
||||
|
||||
ODBCAccessTest::ODBCAccessTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
ODBC::Connector::registerConnector();
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. Access tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
//N.B. Access driver does not suport check for connection.
|
||||
if (_pSession) std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. Access tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -169,57 +139,39 @@ void ODBCAccessTest::recreatePersonTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCAccessTest::checkODBCSetup()
|
||||
bool ODBCAccessTest::checkODBCSetup(const std::string& dbName)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("Microsoft Access Driver") != std::string::npos))
|
||||
if (((itDrv->first).find(dbName) != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
if (_drivers.end() == itDrv)
|
||||
{
|
||||
std::cout << "Driver NOT found, will throw." << std::endl;
|
||||
throw NotFoundException("Microsoft Access ODBC driver.");
|
||||
std::cout << dbName << " driver NOT found, tests not available." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("Microsoft Access Driver") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_dbConnString = "DRIVER=Microsoft Access Driver (*.mdb);"
|
||||
"UID=admin;"
|
||||
"UserCommitSync=Yes;"
|
||||
"Threads=3;"
|
||||
"SafeTransactions=0;"
|
||||
"PageTimeout=5;"
|
||||
"MaxScanRows=8;"
|
||||
"MaxBufferSize=2048;"
|
||||
"FIL=MS Access;"
|
||||
"DriverId=25;"
|
||||
"DefaultDir=C:\\;"
|
||||
"DBQ=C:\\test.mdb;";
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "Access DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;Uid=Admin;Pwd=;", _dsn);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +186,31 @@ void ODBCAccessTest::tearDown()
|
||||
}
|
||||
|
||||
|
||||
bool ODBCAccessTest::init(const std::string& dbName)
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
if (!checkODBCSetup()) return false;
|
||||
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(ODBC::Connector::KEY, _dbConnString);
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << ex.toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//N.B. Access driver does not suport check for connection.
|
||||
std::cout << "*** Connected to " << dbName << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCAccessTest::suite()
|
||||
{
|
||||
if (init())
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCAccessTest");
|
||||
|
||||
@@ -242,3 +218,6 @@ CppUnit::Test* ODBCAccessTest::suite()
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -64,13 +64,13 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
|
||||
static bool init(const std::string& dbName = "Microsoft Access Driver");
|
||||
static bool checkODBCSetup(const std::string& dbName = "Microsoft Access Driver");
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
bool _owner;
|
||||
|
||||
@@ -60,46 +60,13 @@ using Poco::NotFoundException;
|
||||
const bool ODBCDB2Test::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCDB2Test::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCDB2Test::_pExecutor = 0;
|
||||
std::string ODBCDB2Test::_dsn = "PocoDataDB2Test";
|
||||
std::string ODBCDB2Test::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCDB2Test::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCDB2Test::_dataSources;
|
||||
|
||||
|
||||
ODBCDB2Test::ODBCDB2Test(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. DB2 tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor)
|
||||
_pExecutor = new SQLExecutor("DB2 SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. DB2 tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -832,57 +799,28 @@ void ODBCDB2Test::recreateVectorsTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::checkODBCSetup()
|
||||
bool ODBCDB2Test::checkODBCSetup(const std::string& dbName)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("IBM DB2") != std::string::npos))
|
||||
if (((itDrv->first).find(dbName) != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
if (_drivers.end() == itDrv)
|
||||
{
|
||||
std::cout << "DB2 driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
std::cout << dbName << " driver NOT found, tests not available." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("IBM DB2") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_dbConnString = "DSN=PocoDataDB2Test;Uid=db2admin;Pwd=db2admin;";
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "DB2 DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;Uid=db2admin;Pwd=db2admin;", _dsn);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -898,7 +836,33 @@ void ODBCDB2Test::tearDown()
|
||||
}
|
||||
|
||||
|
||||
bool ODBCDB2Test::init(const std::string& dbName)
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
if (!checkODBCSetup()) return false;
|
||||
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(ODBC::Connector::KEY, _dbConnString);
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << ex.toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << dbName << " test database." << std::endl;
|
||||
|
||||
_pExecutor = new SQLExecutor(dbName + " SQL Executor", _pSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCDB2Test::suite()
|
||||
{
|
||||
if (init())
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test");
|
||||
|
||||
@@ -945,3 +909,6 @@ CppUnit::Test* ODBCDB2Test::suite()
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,6 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
@@ -121,9 +120,10 @@ private:
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static bool init(const std::string& dbName = "IBM DB2");
|
||||
static bool checkODBCSetup(const std::string& dbName = "IBM DB2");
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
|
||||
@@ -60,46 +60,13 @@ using Poco::NotFoundException;
|
||||
const bool ODBCMySQLTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCMySQLTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCMySQLTest::_pExecutor = 0;
|
||||
std::string ODBCMySQLTest::_dsn = "PocoDataMySQLTest";
|
||||
std::string ODBCMySQLTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCMySQLTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCMySQLTest::_dataSources;
|
||||
|
||||
|
||||
ODBCMySQLTest::ODBCMySQLTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. MySQL tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor)
|
||||
_pExecutor = new SQLExecutor("MySQL SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. MySQL tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,16 +97,6 @@ void ODBCMySQLTest::testSimpleAccess()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
int count = 0;
|
||||
|
||||
//recreatePersonTable();
|
||||
|
||||
//try { *_pSession << "SELECT count(*) FROM sys.tables WHERE name = 'Person'", into(count), use(tableName), now; }
|
||||
//catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
//catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
|
||||
//assert (1 == count);
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
@@ -831,57 +788,32 @@ void ODBCMySQLTest::recreateVectorsTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::checkODBCSetup()
|
||||
bool ODBCMySQLTest::checkODBCSetup(const std::string& dbName)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("MySQL") != std::string::npos))
|
||||
if (((itDrv->first).find(dbName) != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
if (_drivers.end() == itDrv)
|
||||
{
|
||||
std::cout << "MySQL driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
std::cout << dbName << " driver NOT found, tests not available." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("MySQL") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_dbConnString = "DRIVER=MySQL ODBC 3.51 Driver;"
|
||||
"DATABASE=test;"
|
||||
"SERVER=localhost;"
|
||||
"UID=root;"
|
||||
"PWD=mysql;";
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "SQL Server DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;", _dsn);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -897,7 +829,33 @@ void ODBCMySQLTest::tearDown()
|
||||
}
|
||||
|
||||
|
||||
bool ODBCMySQLTest::init(const std::string& dbName)
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
if (!checkODBCSetup()) return false;
|
||||
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(ODBC::Connector::KEY, _dbConnString);
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << ex.toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << dbName << " test database." << std::endl;
|
||||
|
||||
_pExecutor = new SQLExecutor(dbName + " SQL Executor", _pSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCMySQLTest::suite()
|
||||
{
|
||||
if (init())
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest");
|
||||
|
||||
@@ -944,3 +902,6 @@ CppUnit::Test* ODBCMySQLTest::suite()
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,6 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
@@ -123,9 +122,10 @@ private:
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static bool checkODBCSetup(const std::string& dbName = "MySQL");
|
||||
static bool init(const std::string& dbName = "MySQL");
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
|
||||
@@ -60,46 +60,13 @@ using Poco::NotFoundException;
|
||||
const bool ODBCOracleTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCOracleTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCOracleTest::_pExecutor = 0;
|
||||
std::string ODBCOracleTest::_dsn = "PocoDataOracleTest";
|
||||
std::string ODBCOracleTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCOracleTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCOracleTest::_dataSources;
|
||||
|
||||
|
||||
ODBCOracleTest::ODBCOracleTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. Oracle tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor)
|
||||
_pExecutor = new SQLExecutor("Oracle SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. Oracle tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -829,58 +796,28 @@ void ODBCOracleTest::recreateVectorsTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::checkODBCSetup()
|
||||
bool ODBCOracleTest::checkODBCSetup(const std::string& dbName)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("Oracle") != std::string::npos) &&
|
||||
((itDrv->first).find("Microsoft") == std::string::npos))
|
||||
if (((itDrv->first).find(dbName) != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
if (_drivers.end() == itDrv)
|
||||
{
|
||||
std::cout << "Oracle driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
std::cout << dbName << " driver NOT found, tests not available." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("Oracle") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_dbConnString = "DSN=PocoDataOracleTest;Uid=Scott;Pwd=Tiger;";
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "Oracle DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;Uid=Scott;Pwd=Tiger;", _dsn);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -896,7 +833,33 @@ void ODBCOracleTest::tearDown()
|
||||
}
|
||||
|
||||
|
||||
bool ODBCOracleTest::init(const std::string& dbName)
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
if (!checkODBCSetup()) return false;
|
||||
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(ODBC::Connector::KEY, _dbConnString);
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << ex.toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << dbName << " test database." << std::endl;
|
||||
|
||||
_pExecutor = new SQLExecutor(dbName + " SQL Executor", _pSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCOracleTest::suite()
|
||||
{
|
||||
if (init())
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCOracleTest");
|
||||
|
||||
@@ -943,3 +906,6 @@ CppUnit::Test* ODBCOracleTest::suite()
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,6 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
@@ -122,9 +121,10 @@ private:
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static bool checkODBCSetup(const std::string& dbName = "Oracle");
|
||||
static bool init(const std::string& dbName = "Oracle");
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
|
||||
@@ -60,46 +60,13 @@ using Poco::NotFoundException;
|
||||
const bool ODBCPostgreSQLTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCPostgreSQLTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCPostgreSQLTest::_pExecutor = 0;
|
||||
std::string ODBCPostgreSQLTest::_dsn = "PocoDataPgSQLTest";
|
||||
std::string ODBCPostgreSQLTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCPostgreSQLTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCPostgreSQLTest::_dataSources;
|
||||
|
||||
|
||||
ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. PostgreSQL tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor)
|
||||
_pExecutor = new SQLExecutor("PostgreSQL SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. PostgreSQL tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -815,57 +782,63 @@ void ODBCPostgreSQLTest::recreateVectorsTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::checkODBCSetup()
|
||||
bool ODBCPostgreSQLTest::checkODBCSetup(const std::string& dbName)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("PostgreSQL") != std::string::npos))
|
||||
if (((itDrv->first).find(dbName) != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
if (_drivers.end() == itDrv)
|
||||
{
|
||||
std::cout << "PostgreSQL driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
std::cout << dbName << " driver NOT found, tests not available." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("PostgreSQL") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_dbConnString = "DRIVER=PostgreSQL ANSI;"
|
||||
"DATABASE=postgres;"
|
||||
"SERVER=localhost;"
|
||||
"PORT=5432;"
|
||||
"UID=postgres;"
|
||||
"PWD=postgres;"
|
||||
"SSLMODE=prefer;"
|
||||
"LowerCaseIdentifier=0;"
|
||||
"UseServerSidePrepare=0;"
|
||||
"ByteaAsLongVarBinary=1;"
|
||||
"BI=0;"
|
||||
"TrueIsMinus1=0;"
|
||||
"DisallowPremature=0;"
|
||||
"UpdatableCursors=0;"
|
||||
"LFConversion=1;"
|
||||
"CancelAsFreeStmt=0;"
|
||||
"Parse=0;"
|
||||
"BoolsAsChar=1;"
|
||||
"UnknownsAsLongVarchar=0;"
|
||||
"TextAsLongVarchar=1;"
|
||||
"UseDeclareFetch=0;"
|
||||
"Ksqo=1;"
|
||||
"Optimizer=1;"
|
||||
"CommLog=0;"
|
||||
"Debug=0;"
|
||||
"MaxLongVarcharSize=8190;"
|
||||
"MaxVarcharSize=254;"
|
||||
"UnknownSizes=0;"
|
||||
"Socket=8192;"
|
||||
"Fetch=100;"
|
||||
"ConnSettings=;"
|
||||
"ShowSystemTables=0;"
|
||||
"RowVersioning=0;"
|
||||
"ShowOidColumn=0;"
|
||||
"FakeOidIndex=0;"
|
||||
"ReadOnly=0;";
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "PostgreSQL DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;", _dsn);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -881,7 +854,33 @@ void ODBCPostgreSQLTest::tearDown()
|
||||
}
|
||||
|
||||
|
||||
bool ODBCPostgreSQLTest::init(const std::string& dbName)
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
if (!checkODBCSetup()) return false;
|
||||
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(ODBC::Connector::KEY, _dbConnString);
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << ex.toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << dbName << " test database." << std::endl;
|
||||
|
||||
_pExecutor = new SQLExecutor(dbName + " SQL Executor", _pSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCPostgreSQLTest::suite()
|
||||
{
|
||||
if (init())
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest");
|
||||
|
||||
@@ -928,3 +927,6 @@ CppUnit::Test* ODBCPostgreSQLTest::suite()
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,6 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
@@ -123,9 +122,10 @@ private:
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static bool init(const std::string& dbName = "PostgreSQL");
|
||||
static bool checkODBCSetup(const std::string& dbName = "PostgreSQL");
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
|
||||
@@ -60,47 +60,14 @@ using Poco::NotFoundException;
|
||||
const bool ODBCSQLServerTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCSQLServerTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCSQLServerTest::_pExecutor = 0;
|
||||
std::string ODBCSQLServerTest::_dsn = "PocoDataSQLServerTest";
|
||||
std::string ODBCSQLServerTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCSQLServerTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCSQLServerTest::_dataSources;
|
||||
|
||||
|
||||
ODBCSQLServerTest::ODBCSQLServerTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. SQL Server tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor)
|
||||
_pExecutor = new SQLExecutor("SQLServer SQL Executor", _pSession);
|
||||
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. SQL Server tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -842,58 +809,32 @@ void ODBCSQLServerTest::recreateVectorsTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::checkODBCSetup()
|
||||
bool ODBCSQLServerTest::checkODBCSetup(const std::string& dbName)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("SQL Server") != std::string::npos))
|
||||
if (((itDrv->first).find(dbName) != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
if (_drivers.end() == itDrv)
|
||||
{
|
||||
std::cout << "SQL Server driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
std::cout << dbName << " driver NOT found, tests not available." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
(((itDSN->second).find("SQL Server") != std::string::npos) ||
|
||||
((itDSN->second).find("SQL Native Client") != std::string::npos)))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_dbConnString = "DRIVER=SQL Server;"
|
||||
"UID=test;"
|
||||
"PWD=test;"
|
||||
"DATABASE=test;"
|
||||
"SERVER=(local);";
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "SQL Server DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;Uid=test;Pwd=test;", _dsn);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -909,7 +850,33 @@ void ODBCSQLServerTest::tearDown()
|
||||
}
|
||||
|
||||
|
||||
bool ODBCSQLServerTest::init(const std::string& dbName)
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
if (!checkODBCSetup()) return false;
|
||||
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(ODBC::Connector::KEY, _dbConnString);
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << ex.toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << dbName << " test database." << std::endl;
|
||||
|
||||
_pExecutor = new SQLExecutor(dbName + " SQL Executor", _pSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCSQLServerTest::suite()
|
||||
{
|
||||
if (init())
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLServerTest");
|
||||
|
||||
@@ -956,3 +923,6 @@ CppUnit::Test* ODBCSQLServerTest::suite()
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,6 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
@@ -125,9 +124,10 @@ private:
|
||||
void recreateVectorTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static bool checkODBCSetup(const std::string& dbName = "SQL Server");
|
||||
static bool init(const std::string& dbName = "SQL Server");
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
|
||||
@@ -67,36 +67,6 @@ Poco::Data::ODBC::Utility::DriverMap ODBCSQLiteTest::_drivers;
|
||||
ODBCSQLiteTest::ODBCSQLiteTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (_drivers.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
checkODBCSetup();
|
||||
}
|
||||
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. SQLite tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dbConnString << std::endl;
|
||||
if (!_pExecutor)
|
||||
_pExecutor = new SQLExecutor("SQLite SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. SQLite tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -808,37 +778,28 @@ void ODBCSQLiteTest::recreateVectorsTable()
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::checkODBCSetup()
|
||||
bool ODBCSQLiteTest::checkODBCSetup(const std::string& dbName)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
beenHere = true;
|
||||
bool driverFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDriver = _drivers.begin();
|
||||
for (; itDriver != _drivers.end(); ++itDriver)
|
||||
if (((itDrv->first).find(dbName) != std::string::npos))
|
||||
{
|
||||
if (((itDriver->first).find("SQLite3") != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDriver->first
|
||||
<< " (" << itDriver->second << ')' << std::endl;
|
||||
|
||||
driverFound = true;
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
if (_drivers.end() == itDrv)
|
||||
{
|
||||
std::cout << "SQLite3 driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << dbName << " driver NOT found, tests not available." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
_dbConnString = "Driver=SQLite3 ODBC Driver;Database=dummy.db;";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -854,7 +815,33 @@ void ODBCSQLiteTest::tearDown()
|
||||
}
|
||||
|
||||
|
||||
bool ODBCSQLiteTest::init(const std::string& dbName)
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
if (!checkODBCSetup()) return false;
|
||||
|
||||
ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(ODBC::Connector::KEY, _dbConnString);
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << ex.toString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << dbName << " test database." << std::endl;
|
||||
|
||||
_pExecutor = new SQLExecutor(dbName + " SQL Executor", _pSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCSQLiteTest::suite()
|
||||
{
|
||||
if (init())
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLiteTest");
|
||||
|
||||
@@ -901,3 +888,6 @@ CppUnit::Test* ODBCSQLiteTest::suite()
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,6 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
@@ -121,6 +120,9 @@ private:
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static bool checkODBCSetup(const std::string& dbName = "SQLite3");
|
||||
static bool init(const std::string& dbName = "SQLite3");
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
|
||||
@@ -38,14 +38,15 @@
|
||||
#include "ODBCSQLiteTest.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "ODBCAccessTest.h"
|
||||
#include "ODBCSQLServerTest.h"
|
||||
#endif
|
||||
#include "ODBCSQLServerTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* ODBCTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCTestSuite");
|
||||
|
||||
//!FIXME
|
||||
// WARNING!
|
||||
// On Win XP Pro:
|
||||
//
|
||||
// 1) The PostgreSQL connection fails if attempted after DB2 w/ following error:
|
||||
@@ -54,20 +55,26 @@ CppUnit::Test* ODBCTestSuite::suite()
|
||||
// message="Specified driver could not be loaded due to system error 127 (PostgreSQL ANSI)."
|
||||
// nativeError=160
|
||||
// System error 127 is "The specified procedure could not be found."
|
||||
// Workaround is to connect to PostgreSQL prior to connecting to DB2.
|
||||
//
|
||||
// 2) When Oracle test is loaded after DB2, the test application does not exit cleanly.
|
||||
// All tests pass, though.
|
||||
//
|
||||
// Workaround is to connect to DB2 after connecting to PostgreSQL and Oracle.
|
||||
// The reason causing these errors is not known.
|
||||
|
||||
addTest(pSuite, ODBCOracleTest::suite());
|
||||
addTest(pSuite, ODBCPostgreSQLTest::suite());
|
||||
addTest(pSuite, ODBCDB2Test::suite());
|
||||
addTest(pSuite, ODBCMySQLTest::suite());
|
||||
addTest(pSuite, ODBCSQLiteTest::suite());
|
||||
addTest(pSuite, ODBCAccessTest::suite());
|
||||
addTest(pSuite, ODBCSQLServerTest::suite());
|
||||
|
||||
pSuite->addTest(ODBCOracleTest::suite());
|
||||
pSuite->addTest(ODBCPostgreSQLTest::suite());
|
||||
pSuite->addTest(ODBCDB2Test::suite());
|
||||
pSuite->addTest(ODBCMySQLTest::suite());
|
||||
pSuite->addTest(ODBCSQLiteTest::suite());
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
pSuite->addTest(ODBCAccessTest::suite());
|
||||
pSuite->addTest(ODBCSQLServerTest::suite());
|
||||
#endif
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
|
||||
void ODBCTestSuite::addTest(CppUnit::TestSuite* pSuite, CppUnit::Test* pT)
|
||||
{
|
||||
if (pSuite && pT) pSuite->addTest(pT);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ class ODBCTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
static void addTest(CppUnit::TestSuite* pSuite, CppUnit::Test* pT);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -518,7 +518,6 @@ void SQLExecutor::complexType()
|
||||
assert (count == 2);
|
||||
|
||||
Person c1;
|
||||
Person c2;
|
||||
try { *_pSession << "SELECT * FROM PERSON WHERE LastName = 'LN1'", into(c1), now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
|
||||
|
||||
Reference in New Issue
Block a user