eliminate some gcc warnings, move register/unregister to be called only once

This commit is contained in:
Aleksandar Fabijanic 2007-05-18 18:37:11 +00:00
parent 0fdc7f42a7
commit 34697be9e4
7 changed files with 38 additions and 37 deletions

View File

@ -71,15 +71,16 @@ ODBCDB2Test::ODBCDB2Test(const std::string& 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)
{
ODBC::Connector::registerConnector();
try
{
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
@ -91,7 +92,8 @@ ODBCDB2Test::ODBCDB2Test(const std::string& name):
if (_pSession && _pSession->isConnected())
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
if (!_pExecutor) _pExecutor = new SQLExecutor("DB2 SQL Executor", _pSession);
if (!_pExecutor)
_pExecutor = new SQLExecutor("DB2 SQL Executor", _pSession);
}
else
if (!_pSession && !beenHere)
@ -103,7 +105,6 @@ ODBCDB2Test::ODBCDB2Test(const std::string& name):
ODBCDB2Test::~ODBCDB2Test()
{
ODBC::Connector::unregisterConnector();
}

View File

@ -71,15 +71,16 @@ ODBCMySQLTest::ODBCMySQLTest(const std::string& 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)
{
ODBC::Connector::registerConnector();
try
{
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
@ -91,7 +92,8 @@ ODBCMySQLTest::ODBCMySQLTest(const std::string& name):
if (_pSession && _pSession->isConnected())
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
if (!_pExecutor) _pExecutor = new SQLExecutor("MySQL SQL Executor", _pSession);
if (!_pExecutor)
_pExecutor = new SQLExecutor("MySQL SQL Executor", _pSession);
}
else
if (!_pSession && !beenHere)
@ -103,7 +105,6 @@ ODBCMySQLTest::ODBCMySQLTest(const std::string& name):
ODBCMySQLTest::~ODBCMySQLTest()
{
ODBC::Connector::unregisterConnector();
}

View File

@ -71,15 +71,16 @@ ODBCOracleTest::ODBCOracleTest(const std::string& 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)
{
ODBC::Connector::registerConnector();
try
{
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
@ -91,7 +92,8 @@ ODBCOracleTest::ODBCOracleTest(const std::string& name):
if (_pSession && _pSession->isConnected())
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
if (!_pExecutor) _pExecutor = new SQLExecutor("Oracle SQL Executor", _pSession);
if (!_pExecutor)
_pExecutor = new SQLExecutor("Oracle SQL Executor", _pSession);
}
else
if (!_pSession && !beenHere)
@ -103,7 +105,6 @@ ODBCOracleTest::ODBCOracleTest(const std::string& name):
ODBCOracleTest::~ODBCOracleTest()
{
ODBC::Connector::unregisterConnector();
}

View File

@ -71,15 +71,16 @@ ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& 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)
{
ODBC::Connector::registerConnector();
try
{
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
@ -91,7 +92,8 @@ ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& name):
if (_pSession && _pSession->isConnected())
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
if (!_pExecutor) _pExecutor = new SQLExecutor("PostgreSQL SQL Executor", _pSession);
if (!_pExecutor)
_pExecutor = new SQLExecutor("PostgreSQL SQL Executor", _pSession);
}
else
if (!_pSession && !beenHere)
@ -103,7 +105,6 @@ ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& name):
ODBCPostgreSQLTest::~ODBCPostgreSQLTest()
{
ODBC::Connector::unregisterConnector();
}
@ -130,12 +131,6 @@ void ODBCPostgreSQLTest::testSimpleAccess()
if (!_pSession) fail ("Test not available.");
std::string tableName("Person");
int count = 0;
recreatePersonTable();
//*_pSession << "SELECT count(*) FROM sys.all_all_tables WHERE table_name = upper(?)", into(count), use(tableName), now;
//assert (1 == count);
for (int i = 0; i < 8;)
{
@ -861,16 +856,18 @@ void ODBCPostgreSQLTest::checkODBCSetup()
break;
}
}
/*
if (!dsnFound)
{
std::cout << "PostgreSQL DSN NOT found, tests will fail." << std::endl;
return;
}
*/
}
if (!_pSession)
format(_dbConnString, "DSN=%s;", _dsn);
_dbConnString = "DRIVER={PostgreSQL ANSI};UID=postgres;PWD=postgres;SERVER=a-fabijanic.nucorsteel.com;Port=5432;Database=postgres";
//format(_dbConnString, "DSN=%s;", _dsn);
}

View File

@ -71,15 +71,16 @@ ODBCSQLServerTest::ODBCSQLServerTest(const std::string& 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)
{
ODBC::Connector::registerConnector();
try
{
_pSession = new Session(SessionFactory::instance().create(ODBC::Connector::KEY, _dbConnString));
@ -91,7 +92,9 @@ ODBCSQLServerTest::ODBCSQLServerTest(const std::string& name):
if (_pSession && _pSession->isConnected())
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
if (!_pExecutor) _pExecutor = new SQLExecutor("SQLServer SQL Executor", _pSession);
if (!_pExecutor)
_pExecutor = new SQLExecutor("SQLServer SQL Executor", _pSession);
}
else
if (!_pSession && !beenHere)
@ -103,7 +106,6 @@ ODBCSQLServerTest::ODBCSQLServerTest(const std::string& name):
ODBCSQLServerTest::~ODBCSQLServerTest()
{
ODBC::Connector::unregisterConnector();
}

View File

@ -69,14 +69,15 @@ ODBCSQLiteTest::ODBCSQLiteTest(const std::string& name):
{
static bool beenHere = false;
ODBC::Connector::registerConnector();
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));
@ -88,7 +89,8 @@ ODBCSQLiteTest::ODBCSQLiteTest(const std::string& name):
if (_pSession && _pSession->isConnected())
std::cout << "*** Connected to " << _dbConnString << std::endl;
if (!_pExecutor) _pExecutor = new SQLExecutor("SQLite SQL Executor", _pSession);
if (!_pExecutor)
_pExecutor = new SQLExecutor("SQLite SQL Executor", _pSession);
}
else
if (!_pSession && !beenHere)
@ -100,7 +102,6 @@ ODBCSQLiteTest::ODBCSQLiteTest(const std::string& name):
ODBCSQLiteTest::~ODBCSQLiteTest()
{
ODBC::Connector::unregisterConnector();
}

View File

@ -169,6 +169,7 @@ SQLExecutor::SQLExecutor(const std::string& name, Poco::Data::Session* pSession)
SQLExecutor::~SQLExecutor()
{
ODBC::Connector::unregisterConnector();
}
@ -231,7 +232,7 @@ void SQLExecutor::bareboneODBCTest(const std::string& dbConnString,
float fifth = 1.5;
SQLLEN li = SQL_NTS;
SQLINTEGER size = (SQLINTEGER) str[0].size();
if (SQLExecutor::PB_AT_EXEC == bindMode)
li = SQL_LEN_DATA_AT_EXEC(size);
@ -275,7 +276,7 @@ void SQLExecutor::bareboneODBCTest(const std::string& dbConnString,
SQL_LONGVARBINARY,
(SQLUINTEGER) size,
0,
(SQLPOINTER) str[2].c_str(),
(SQLPOINTER) str[2].data(),
size,
&li);
assert (SQL_SUCCEEDED(rc));
@ -338,7 +339,7 @@ void SQLExecutor::bareboneODBCTest(const std::string& dbConnString,
rc = SQLPrepare(hstmt, pStr, (SQLINTEGER) sql.length());
assert (SQL_SUCCEEDED(rc));
char chr[3][5] = { 0 };
char chr[3][5] = {{ 0 }};
SQLLEN lengths[5] = { 0 };
fourth = 0;
fifth = 0.0f;
@ -460,6 +461,8 @@ void SQLExecutor::bareboneODBCTest(const std::string& dbConnString,
// Environment end
rc = SQLFreeHandle(SQL_HANDLE_ENV, henv);
assert (SQL_SUCCEEDED(rc));
std::cout << "barebone end" << std::endl;
}
@ -629,7 +632,6 @@ void SQLExecutor::insertEmptyVector()
{
std::string funct = "insertEmptyVector()";
std::vector<std::string> str;
int count = 100;
try
{
@ -749,7 +751,6 @@ void SQLExecutor::limits()
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
int count = 0;
std::vector<int> retData;
try { *_pSession << "SELECT * FROM Strings", into(retData), limit(50), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
@ -775,7 +776,6 @@ void SQLExecutor::limitZero()
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
int count = 0;
std::vector<int> retData;
try { *_pSession << "SELECT * FROM Strings", into(retData), limit(0), now; }// stupid test, but at least we shouldn't crash
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
@ -797,7 +797,6 @@ void SQLExecutor::limitOnce()
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
int count = 0;
std::vector<int> retData;
Statement stmt = (*_pSession << "SELECT * FROM Strings", into(retData), limit(50), now);
assert (!stmt.done());
@ -829,7 +828,6 @@ void SQLExecutor::limitPrepare()
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
int count = 0;
std::vector<int> retData;
Statement stmt = (*_pSession << "SELECT * FROM Strings", into(retData), limit(50));
assert (retData.size() == 0);
@ -847,7 +845,7 @@ void SQLExecutor::limitPrepare()
try { stmt.execute(); }// will restart execution!
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
size_t s = retData.size();
assert (!stmt.done());
assert (retData.size() == 150);
for (int x = 0; x < 150; ++x)
@ -1644,7 +1642,7 @@ void SQLExecutor::internalExtraction()
s = rset.value("cnt", 0).convert<std::string>();
assert ("4" == s);
try { const Column<int>& col1 = rset.column<int>(100); fail ("must fail"); }
try { rset.column<int>(100); fail ("must fail"); }
catch (RangeException&) { }
try { rset.value<std::string>(0,0); fail ("must fail"); }
@ -1653,7 +1651,7 @@ void SQLExecutor::internalExtraction()
stmt = (*_pSession << "DELETE FROM Vectors", now);
rset = stmt;
try { const Column<int>& col1 = rset.column<int>(0); fail ("must fail"); }
try { rset.column<int>(0); fail ("must fail"); }
catch (RangeException&) { }
}
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }