Skip to content

Commit 0eade9f

Browse files
committed
Adjust the libmysql.dll search path code
1 parent 2f894f4 commit 0eade9f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/mysql2.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
# This gives a chance to be flexible about the load path
88
# Or to bomb out with a clear error message instead of a linker crash
99
if RUBY_PLATFORM =~ /mswin|mingw/
10-
dll_search = [
11-
File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)).gsub('/', '\\'),
12-
File.expand_path('../libmysql.dll', File.dirname(__FILE__)).gsub('/', '\\'),
13-
'libmysql.dll' # This will use default / system library paths
14-
]
15-
16-
# If this environment variable is set, it overrides any other search paths
17-
dll_search = [ ENV['RUBY_MYSQL2_LIBMYSQL_DLL'].dup ] if ENV['RUBY_MYSQL2_LIBMYSQL_DLL']
10+
dll_path = if ENV['RUBY_MYSQL2_LIBMYSQL_DLL']
11+
# If this environment variable is set, it overrides any other paths
12+
# The user is advised to use backslashes not forward slashes
13+
ENV['RUBY_MYSQL2_LIBMYSQL_DLL'].dup
14+
elsif File.exist?(File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)))
15+
# Use vendor/libmysql.dll if it exists, convert slashes for Win32 LoadLibrary
16+
File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)).gsub('/', '\\')
17+
else
18+
# This will use default / system library paths
19+
'libmysql.dll'
20+
end
1821

1922
require 'Win32API'
2023
LoadLibrary = Win32API.new('Kernel32', 'LoadLibrary', ['P'], 'I')
21-
unless dll_search.any? { |dll| 0 != LoadLibrary.call(dll) }
22-
abort "Failed to load libmysql.dll from any of #{dll_search.inspect}"
24+
if 0 == LoadLibrary.call(dll_path)
25+
abort "Failed to load libmysql.dll from #{dll_path}"
2326
end
2427
end
2528

0 commit comments

Comments
 (0)