mysql2 0.4.6 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,15 +2,9 @@ module Mysql2
2
2
  class Statement
3
3
  include Enumerable
4
4
 
5
- if Thread.respond_to?(:handle_interrupt)
6
- def execute(*args)
7
- Thread.handle_interrupt(::Mysql2::Util::TimeoutError => :never) do
8
- _execute(*args)
9
- end
10
- end
11
- else
12
- def execute(*args)
13
- _execute(*args)
5
+ def execute(*args, **kwargs)
6
+ Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do
7
+ _execute(*args, **kwargs)
14
8
  end
15
9
  end
16
10
  end
@@ -1,3 +1,3 @@
1
1
  module Mysql2
2
- VERSION = "0.4.6"
2
+ VERSION = "0.5.2".freeze
3
3
  end
data/lib/mysql2.rb CHANGED
@@ -1,7 +1,5 @@
1
- # encoding: UTF-8
2
1
  require 'date'
3
2
  require 'bigdecimal'
4
- require 'rational' unless RUBY_VERSION >= '1.9.2'
5
3
 
6
4
  # Load libmysql.dll before requiring mysql2/mysql2.so
7
5
  # This gives a chance to be flexible about the load path
@@ -13,16 +11,20 @@ if RUBY_PLATFORM =~ /mswin|mingw/
13
11
  ENV['RUBY_MYSQL2_LIBMYSQL_DLL']
14
12
  elsif File.exist?(File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)))
15
13
  # Use vendor/libmysql.dll if it exists, convert slashes for Win32 LoadLibrary
16
- File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)).tr('/', '\\')
14
+ File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__))
15
+ elsif defined?(RubyInstaller)
16
+ # RubyInstaller-2.4+ native build doesn't need DLL preloading
17
17
  else
18
18
  # This will use default / system library paths
19
19
  'libmysql.dll'
20
20
  end
21
21
 
22
- require 'Win32API'
23
- LoadLibrary = Win32API.new('Kernel32', 'LoadLibrary', ['P'], 'I')
24
- if 0 == LoadLibrary.call(dll_path)
25
- abort "Failed to load libmysql.dll from #{dll_path}"
22
+ if dll_path
23
+ require 'Win32API'
24
+ LoadLibrary = Win32API.new('Kernel32', 'LoadLibrary', ['P'], 'I')
25
+ if LoadLibrary.call(dll_path).zero?
26
+ abort "Failed to load libmysql.dll from #{dll_path}"
27
+ end
26
28
  end
27
29
  end
28
30
 
@@ -71,14 +73,11 @@ module Mysql2
71
73
  # Timeout::ExitException was removed in Ruby 2.3.0, 2.2.3, and 2.1.8,
72
74
  # but is present in earlier 2.1.x and 2.2.x, so we provide a shim.
73
75
  #
74
- if Thread.respond_to?(:handle_interrupt)
75
- require 'timeout'
76
- # rubocop:disable Style/ConstantName
77
- TimeoutError = if defined?(::Timeout::ExitException)
78
- ::Timeout::ExitException
79
- else
80
- ::Timeout::Error
81
- end
76
+ require 'timeout'
77
+ TIMEOUT_ERROR_CLASS = if defined?(::Timeout::ExitException)
78
+ ::Timeout::ExitException
79
+ else
80
+ ::Timeout::Error
82
81
  end
83
82
  end
84
83
  end
data/spec/em/em_spec.rb CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'spec_helper'
3
2
  begin
4
3
  require 'eventmachine'
@@ -49,13 +48,13 @@ begin
49
48
  end
50
49
 
51
50
  it "should not swallow exceptions raised in callbacks" do
52
- expect {
51
+ expect do
53
52
  EM.run do
54
53
  client = Mysql2::EM::Client.new DatabaseCredentials['root']
55
54
  defer = client.query "SELECT sleep(0.1) as first_query"
56
55
  defer.callback do
57
56
  client.close
58
- fail 'some error'
57
+ raise 'some error'
59
58
  end
60
59
  defer.errback do
61
60
  # This _shouldn't_ be run, but it needed to prevent the specs from
@@ -63,13 +62,14 @@ begin
63
62
  EM.stop_event_loop
64
63
  end
65
64
  end
66
- }.to raise_error('some error')
65
+ end.to raise_error('some error')
67
66
  end
68
67
 
69
68
  context 'when an exception is raised by the client' do
70
69
  let(:client) { Mysql2::EM::Client.new DatabaseCredentials['root'] }
71
70
  let(:error) { StandardError.new('some error') }
72
71
  before { allow(client).to receive(:async_result).and_raise(error) }
72
+ after { client.close }
73
73
 
74
74
  it "should swallow exceptions raised in by the client" do
75
75
  errors = []
@@ -122,9 +122,9 @@ begin
122
122
  end
123
123
  EM.add_timer(0.1) do
124
124
  expect(callbacks_run).to eq([:callback])
125
- expect {
125
+ expect do
126
126
  client.close
127
- }.not_to raise_error
127
+ end.not_to raise_error
128
128
  EM.stop_event_loop
129
129
  end
130
130
  end