mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-27 17:09:20 +01:00
removed automatic Connector registration in ODBC and SQLite
This commit is contained in:
parent
ce4341e96b
commit
b3a503c13e
@ -24,12 +24,6 @@
|
||||
#include "Poco/Data/Connector.h"
|
||||
|
||||
|
||||
// Note: to avoid static (de)initialization problems,
|
||||
// during connector automatic (un)registration, it is
|
||||
// best to have this as a macro.
|
||||
#define POCO_DATA_ODBC_CONNECTOR_NAME "odbc"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
@ -40,7 +34,7 @@ class ODBC_API Connector: public Poco::Data::Connector
|
||||
{
|
||||
public:
|
||||
static const std::string KEY;
|
||||
/// Keyword for creating ODBC sessions
|
||||
/// Keyword for creating ODBC sessions.
|
||||
|
||||
Connector();
|
||||
/// Creates the Connector.
|
||||
@ -66,73 +60,13 @@ public:
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
|
||||
inline const std::string& Connector::name() const
|
||||
{
|
||||
static const std::string n(POCO_DATA_ODBC_CONNECTOR_NAME);
|
||||
return n;
|
||||
return KEY;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
//
|
||||
// Automatic Connector registration
|
||||
//
|
||||
|
||||
struct ODBC_API ODBCConnectorRegistrator
|
||||
/// Connector registering class.
|
||||
/// A global instance of this class is instantiated
|
||||
/// with sole purpose to automatically register the
|
||||
/// ODBC connector with central Poco Data registry.
|
||||
{
|
||||
ODBCConnectorRegistrator()
|
||||
/// Calls Poco::Data::ODBC::registerConnector();
|
||||
{
|
||||
Poco::Data::ODBC::Connector::registerConnector();
|
||||
}
|
||||
|
||||
~ODBCConnectorRegistrator()
|
||||
/// Calls Poco::Data::ODBC::unregisterConnector();
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::Data::ODBC::Connector::unregisterConnector();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIB_INIT)
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(__GNUC__)
|
||||
extern "C" const struct ODBC_API ODBCConnectorRegistrator pocoODBCConnectorRegistrator;
|
||||
#if defined(ODBC_EXPORTS)
|
||||
#if defined(_WIN64)
|
||||
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
|
||||
#elif defined(_WIN32)
|
||||
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
|
||||
#endif
|
||||
#else // !ODBC_EXPORTS
|
||||
#if defined(_WIN64)
|
||||
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
|
||||
#elif defined(_WIN32)
|
||||
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
|
||||
#endif
|
||||
#endif // ODBC_EXPORTS
|
||||
#else // !POCO_OS_FAMILY_WINDOWS
|
||||
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) extern "C" const struct ODBCConnectorRegistrator s;
|
||||
#endif // POCO_OS_FAMILY_WINDOWS
|
||||
POCO_DATA_ODBC_FORCE_SYMBOL(pocoODBCConnectorRegistrator)
|
||||
#endif // POCO_NO_AUTOMATIC_LIB_INIT
|
||||
|
||||
//
|
||||
// End automatic Connector registration
|
||||
//
|
||||
|
||||
|
||||
#endif // Data_ODBC_Connector_INCLUDED
|
||||
|
@ -19,15 +19,12 @@
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
|
||||
|
||||
const ODBCConnectorRegistrator pocoODBCConnectorRegistrator;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
const std::string Connector::KEY(POCO_DATA_ODBC_CONNECTOR_NAME);
|
||||
const std::string Connector::KEY("ODBC");
|
||||
|
||||
|
||||
Connector::Connector()
|
||||
@ -55,7 +52,7 @@ void Connector::registerConnector()
|
||||
|
||||
void Connector::unregisterConnector()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().remove(POCO_DATA_ODBC_CONNECTOR_NAME);
|
||||
Poco::Data::SessionFactory::instance().remove(KEY);
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,6 +14,17 @@
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "ODBCTestSuite.h"
|
||||
#include "Poco/Data/ODBC/Connector.h"
|
||||
|
||||
|
||||
CppUnitMain(ODBCTestSuite)
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
Poco::Data::ODBC::Connector::registerConnector();
|
||||
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < ac; ++i)
|
||||
args.push_back(std::string(av[i]));
|
||||
CppUnit::TestRunner runner;
|
||||
runner.addTest(#testCase, testCase::suite());
|
||||
return runner.run(args) ? 0 : 1;
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ Poco::Data::ODBC::Utility::DriverMap ODBCAccessTest::_drivers;
|
||||
ODBCAccessTest::ODBCAccessTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
Poco::Data::ODBC::Connector::registerConnector();
|
||||
}
|
||||
|
||||
|
||||
@ -185,7 +184,6 @@ bool ODBCAccessTest::init(const std::string& driver, const std::string& dsn)
|
||||
Utility::drivers(_drivers);
|
||||
if (!canConnect(driver, dsn)) return false;
|
||||
|
||||
Poco::Data::ODBC::Connector::registerConnector();
|
||||
try
|
||||
{
|
||||
_pSession = new Session(Poco::Data::ODBC::Connector::KEY, _dbConnString);
|
||||
|
@ -14,12 +14,15 @@
|
||||
|
||||
#include "WinTestRunner/WinTestRunner.h"
|
||||
#include "ODBCTestSuite.h"
|
||||
#include "Poco/Data/ODBC/Connector.h"
|
||||
|
||||
|
||||
class TestDriver: public CppUnit::WinTestRunnerApp
|
||||
{
|
||||
void TestMain()
|
||||
{
|
||||
Poco::Data::ODBC::Connector::registerConnector();
|
||||
|
||||
CppUnit::WinTestRunner runner;
|
||||
runner.addTest(ODBCTestSuite::suite());
|
||||
runner.run();
|
||||
|
@ -24,12 +24,6 @@
|
||||
#include "Poco/Data/Connector.h"
|
||||
|
||||
|
||||
// Note: to avoid static (de)initialization problems,
|
||||
// during connector automatic (un)registration, it is
|
||||
// best to have this as a macro.
|
||||
#define POCO_DATA_SQLITE_CONNECTOR_NAME "sqlite"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
@ -40,7 +34,7 @@ class SQLite_API Connector: public Poco::Data::Connector
|
||||
{
|
||||
public:
|
||||
static const std::string KEY;
|
||||
/// Keyword for creating SQLite sessions ("SQLite").
|
||||
/// Keyword for creating SQLite sessions ("sqlite").
|
||||
|
||||
Connector();
|
||||
/// Creates the Connector.
|
||||
@ -77,69 +71,11 @@ public:
|
||||
///
|
||||
inline const std::string& Connector::name() const
|
||||
{
|
||||
static const std::string n(POCO_DATA_SQLITE_CONNECTOR_NAME);
|
||||
return n;
|
||||
return KEY;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
//
|
||||
// Automatic Connector registration
|
||||
//
|
||||
|
||||
struct SQLite_API SQLiteConnectorRegistrator
|
||||
/// Connector registering class.
|
||||
/// A global instance of this class is instantiated
|
||||
/// with sole purpose to automatically register the
|
||||
/// SQLite connector with central Poco Data registry.
|
||||
{
|
||||
SQLiteConnectorRegistrator()
|
||||
/// Calls Poco::Data::SQLite::registerConnector();
|
||||
{
|
||||
Poco::Data::SQLite::Connector::registerConnector();
|
||||
}
|
||||
|
||||
~SQLiteConnectorRegistrator()
|
||||
/// Calls Poco::Data::SQLite::unregisterConnector();
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::Data::SQLite::Connector::unregisterConnector();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIB_INIT)
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(__GNUC__)
|
||||
extern "C" const struct SQLite_API SQLiteConnectorRegistrator pocoSQLiteConnectorRegistrator;
|
||||
#if defined(SQLite_EXPORTS)
|
||||
#if defined(_WIN64) || defined(_WIN32_WCE)
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
|
||||
#elif defined(_WIN32)
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
|
||||
#endif
|
||||
#else // !SQLite_EXPORTS
|
||||
#if defined(_WIN64) || defined(_WIN32_WCE)
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
|
||||
#elif defined(_WIN32)
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
|
||||
#endif
|
||||
#endif // SQLite_EXPORTS
|
||||
#else // !POCO_OS_FAMILY_WINDOWS
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) extern "C" const struct SQLiteConnectorRegistrator s;
|
||||
#endif // POCO_OS_FAMILY_WINDOWS
|
||||
POCO_DATA_SQLITE_FORCE_SYMBOL(pocoSQLiteConnectorRegistrator)
|
||||
#endif // POCO_NO_AUTOMATIC_LIB_INIT
|
||||
|
||||
//
|
||||
// End automatic Connector registration
|
||||
//
|
||||
|
||||
#endif // Data_SQLite_Connector_INCLUDED
|
||||
|
@ -24,15 +24,12 @@
|
||||
#endif
|
||||
|
||||
|
||||
const SQLiteConnectorRegistrator pocoSQLiteConnectorRegistrator;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const std::string Connector::KEY(POCO_DATA_SQLITE_CONNECTOR_NAME);
|
||||
const std::string Connector::KEY("sqlite");
|
||||
|
||||
|
||||
Connector::Connector()
|
||||
@ -60,7 +57,7 @@ void Connector::registerConnector()
|
||||
|
||||
void Connector::unregisterConnector()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().remove(POCO_DATA_SQLITE_CONNECTOR_NAME);
|
||||
Poco::Data::SessionFactory::instance().remove(KEY);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "Poco/Data/SQLite/Connector.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/Notifier.h"
|
||||
#include "Poco/Data/SQLite/Connector.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/Data/TypeHandler.h"
|
||||
#include "Poco/Nullable.h"
|
||||
@ -241,11 +242,13 @@ int SQLiteTest::_deleteCounter;
|
||||
|
||||
SQLiteTest::SQLiteTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
Poco::Data::SQLite::Connector::registerConnector();
|
||||
}
|
||||
|
||||
|
||||
SQLiteTest::~SQLiteTest()
|
||||
{
|
||||
Poco::Data::SQLite::Connector::unregisterConnector();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user