|
44 | 44 | #include "Poco/Data/Connector.h" |
45 | 45 |
|
46 | 46 |
|
| 47 | +// Note: to avoid static (de)initialization problems, |
| 48 | +// during connector automatic (un)registration, it is |
| 49 | +// best to have this as a macro. |
| 50 | +#define POCO_DATA_ODBC_CONNECTOR_NAME "odbc" |
| 51 | + |
| 52 | + |
47 | 53 | namespace Poco { |
48 | 54 | namespace Data { |
49 | 55 | namespace ODBC { |
@@ -83,11 +89,63 @@ class ODBC_API Connector: public Poco::Data::Connector |
83 | 89 |
|
84 | 90 | inline const std::string& Connector::name() const |
85 | 91 | { |
86 | | - return KEY; |
| 92 | + static const std::string n(POCO_DATA_ODBC_CONNECTOR_NAME); |
| 93 | + return n; |
87 | 94 | } |
88 | 95 |
|
89 | 96 |
|
90 | 97 | } } } // namespace Poco::Data::ODBC |
91 | 98 |
|
92 | 99 |
|
| 100 | +// |
| 101 | +// Automatic Connector registration |
| 102 | +// |
| 103 | + |
| 104 | +struct ODBC_API ODBCConnectorRegistrator |
| 105 | + /// Connector registering class. |
| 106 | + /// A global instance of this class is instantiated |
| 107 | + /// with sole purpose to automatically register the |
| 108 | + /// ODBC connector with central Poco Data registry. |
| 109 | +{ |
| 110 | + ODBCConnectorRegistrator() |
| 111 | + /// Calls Poco::Data::ODBC::registerConnector(); |
| 112 | + { |
| 113 | + Poco::Data::ODBC::Connector::registerConnector(); |
| 114 | + } |
| 115 | + |
| 116 | + ~ODBCConnectorRegistrator() |
| 117 | + /// Calls Poco::Data::ODBC::unregisterConnector(); |
| 118 | + { |
| 119 | + Poco::Data::ODBC::Connector::unregisterConnector(); |
| 120 | + } |
| 121 | +}; |
| 122 | + |
| 123 | + |
| 124 | +#if !defined(POCO_NO_AUTOMATIC_LIB_INIT) |
| 125 | + #if defined(POCO_OS_FAMILY_WINDOWS) |
| 126 | + extern "C" const struct ODBC_API ODBCConnectorRegistrator pocoODBCConnectorRegistrator; |
| 127 | + #if defined(ODBC_EXPORTS) |
| 128 | + #if defined(_WIN64) |
| 129 | + #define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s)) |
| 130 | + #elif defined(_WIN32) |
| 131 | + #define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s)) |
| 132 | + #endif |
| 133 | + #else // !ODBC_EXPORTS |
| 134 | + #if defined(_WIN64) |
| 135 | + #define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s)) |
| 136 | + #elif defined(_WIN32) |
| 137 | + #define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s)) |
| 138 | + #endif |
| 139 | + #endif // ODBC_EXPORTS |
| 140 | + #else // !POCO_OS_FAMILY_WINDOWS |
| 141 | + #define POCO_DATA_ODBC_FORCE_SYMBOL(s) extern "C" const struct ODBCConnectorRegistrator s; |
| 142 | + #endif // POCO_OS_FAMILY_WINDOWS |
| 143 | + POCO_DATA_ODBC_FORCE_SYMBOL(pocoODBCConnectorRegistrator) |
| 144 | +#endif // POCO_NO_AUTOMATIC_LIB_INIT |
| 145 | + |
| 146 | +// |
| 147 | +// End automatic Connector registration |
| 148 | +// |
| 149 | + |
| 150 | + |
93 | 151 | #endif // Data_ODBC_Connector_INCLUDED |
0 commit comments