File tree Expand file tree Collapse file tree 3 files changed +51
-6
lines changed Expand file tree Collapse file tree 3 files changed +51
-6
lines changed Original file line number Diff line number Diff line change @@ -576,6 +576,7 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
576
576
*/
577
577
578
578
{
579
+ sql::SQLString plugin_dir;
579
580
it = properties.find (OPT_PLUGIN_DIR);
580
581
581
582
if (it != properties.end ()) {
@@ -584,12 +585,28 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
584
585
} catch (sql::InvalidArgumentException&) {
585
586
throw sql::InvalidArgumentException (" Wrong type passed for pluginDir expected sql::SQLString" );
586
587
}
587
- if (p_s) {
588
- proxy->options (sql::mysql::MYSQL_PLUGIN_DIR, *p_s);
589
- }
590
- else {
591
- throw sql::InvalidArgumentException (" No string value passed for pluginDir" );
592
- }
588
+ }
589
+ #if (_WIN32 && CONCPP_BUILD_SHARED)
590
+ else {
591
+ /*
592
+ Note: For DLL in Windows we will try to set the plugin directory
593
+ based on driver_dll_path.
594
+ */
595
+ plugin_dir = driver_dll_path;
596
+ #ifdef _DEBUG
597
+ // Debug dll is placed inside debug subdirectory
598
+ plugin_dir.append (" ..\\ " );
599
+ #endif
600
+ plugin_dir.append (" plugin" );
601
+ p_s = &plugin_dir;
602
+ }
603
+ #endif
604
+
605
+ if (p_s) {
606
+ proxy->options (sql::mysql::MYSQL_PLUGIN_DIR, *p_s);
607
+ } else if (it != properties.end ()) {
608
+ // Throw only when OPT_PLUGIN_DIR is used, but no value is given
609
+ throw sql::InvalidArgumentException (" No string value passed for pluginDir" );
593
610
}
594
611
}
595
612
Original file line number Diff line number Diff line change 36
36
#include " cppconn/connection.h"
37
37
#include < memory>
38
38
39
+ #if (_WIN32 && CONCPP_BUILD_SHARED)
40
+ extern std::string driver_dll_path;
41
+ #endif
42
+
39
43
namespace sql
40
44
{
41
45
namespace mysql
Original file line number Diff line number Diff line change 29
29
*/
30
30
31
31
32
+ #ifdef _WIN32
33
+ #include < Windows.h>
34
+ #endif
32
35
33
36
#include " mysql_connection.h"
34
37
#include " version_info.h"
@@ -187,6 +190,27 @@ void MySQL_Driver::setCallBack(sql::Fido_Callback& cb)
187
190
188
191
} /* namespace sql */
189
192
193
+ #if (_WIN32 && CONCPP_BUILD_SHARED)
194
+ std::string driver_dll_path;
195
+
196
+ BOOL WINAPI DllMain (
197
+ _In_ HINSTANCE hmodule,
198
+ _In_ DWORD,
199
+ _In_ LPVOID
200
+ )
201
+ {
202
+ /*
203
+ For Windows DLL we will store the current module path to allow detecting
204
+ directories with the plugins and dependencies.
205
+ */
206
+ char _driver_dll_path[1024 ] = { 0 };
207
+ GetModuleFileNameA (hmodule, _driver_dll_path, sizeof (_driver_dll_path));
208
+ driver_dll_path = _driver_dll_path;
209
+ driver_dll_path = driver_dll_path.substr (0 , driver_dll_path.find_last_of (' \\ ' ) + 1 );
210
+ return true ;
211
+ }
212
+ #endif
213
+
190
214
/*
191
215
* Local variables:
192
216
* tab-width: 4
You can’t perform that action at this time.
0 commit comments