diff --git a/.rubocop.yml b/.rubocop.yml index 8f634d507..a9cd803dc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ inherit_from: .rubocop_todo.yml AllCops: - TargetRubyVersion: 1.9 + TargetRubyVersion: 2.0 DisplayCopNames: true Exclude: @@ -21,10 +21,6 @@ Layout/IndentHeredoc: Lint/EndAlignment: EnforcedStyleAlignWith: variable -Style/Encoding: - AutoCorrectEncodingComment: '# encoding: UTF-8' - EnforcedStyle: always - Style/TrailingCommaInArguments: EnforcedStyleForMultiline: consistent_comma diff --git a/.travis.yml b/.travis.yml index 92f10ad4a..7c3c594cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,6 @@ rvm: - 2.2 - 2.1 - 2.0.0 - - 1.9.3 - ruby-head matrix: include: diff --git a/Gemfile b/Gemfile index 3f64bcc33..5d9c98491 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ -# encoding: UTF-8 - source 'https://rubygems.org' gemspec @@ -10,9 +8,8 @@ gem 'rake-compiler', '~> 1.0' group :test do gem 'eventmachine' unless RUBY_PLATFORM =~ /mswin|mingw/ gem 'rspec', '~> 3.2' - # https://github.com/bbatsov/rubocop/pull/3328 # https://github.com/bbatsov/rubocop/pull/4789 - gem 'rubocop', '~> 0.50.0' unless RUBY_VERSION =~ /1.9/ + gem 'rubocop', '~> 0.50.0' end group :benchmarks do diff --git a/README.md b/README.md index c385f2932..7284777dc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ The Mysql2 gem is meant to serve the extremely common use-case of connecting, qu Some database libraries out there serve as direct 1:1 mappings of the already complex C APIs available. This one is not. -It also forces the use of UTF-8 [or binary] for the connection [and all strings in 1.9, unless Encoding.default_internal is set then it'll convert from UTF-8 to that encoding] and uses encoding-aware MySQL API calls where it can. +It also forces the use of UTF-8 [or binary] for the connection and uses encoding-aware MySQL API calls where it can. The API consists of three classes: @@ -510,7 +510,7 @@ As for field values themselves, I'm workin on it - but expect that soon. This gem is tested with the following Ruby versions on Linux and Mac OS X: - * Ruby MRI 1.9.3, 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x + * Ruby MRI 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x * Rubinius 2.x and 3.x do work but may fail under some workloads This gem is tested with the following MySQL and MariaDB versions: diff --git a/Rakefile b/Rakefile index 1b7a093cf..4164a7ad2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'rake' # Load custom tasks (careful attention to define tasks before prerequisites) @@ -12,7 +10,7 @@ load 'tasks/benchmarks.rake' begin require 'rubocop/rake_task' RuboCop::RakeTask.new - task default: [:spec, :rubocop] + task default: %i[spec rubocop] rescue LoadError warn 'RuboCop is not available' task default: :spec diff --git a/benchmark/active_record.rb b/benchmark/active_record.rb index 90191dcff..0ae442c25 100644 --- a/benchmark/active_record.rb +++ b/benchmark/active_record.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rubygems' diff --git a/benchmark/active_record_threaded.rb b/benchmark/active_record_threaded.rb index 013b2d57c..22c3f01be 100644 --- a/benchmark/active_record_threaded.rb +++ b/benchmark/active_record_threaded.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rubygems' diff --git a/benchmark/allocations.rb b/benchmark/allocations.rb index 372ffb9a2..7926a837d 100644 --- a/benchmark/allocations.rb +++ b/benchmark/allocations.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rubygems' diff --git a/benchmark/escape.rb b/benchmark/escape.rb index fad2190e6..0e2320e2b 100644 --- a/benchmark/escape.rb +++ b/benchmark/escape.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rubygems' diff --git a/benchmark/query_with_mysql_casting.rb b/benchmark/query_with_mysql_casting.rb index 33fa024f2..caf7eb011 100644 --- a/benchmark/query_with_mysql_casting.rb +++ b/benchmark/query_with_mysql_casting.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rubygems' diff --git a/benchmark/query_without_mysql_casting.rb b/benchmark/query_without_mysql_casting.rb index 1fc6af235..4080e22d1 100644 --- a/benchmark/query_without_mysql_casting.rb +++ b/benchmark/query_without_mysql_casting.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rubygems' diff --git a/benchmark/sequel.rb b/benchmark/sequel.rb index afd67654c..a9555fa6e 100644 --- a/benchmark/sequel.rb +++ b/benchmark/sequel.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rubygems' diff --git a/benchmark/setup_db.rb b/benchmark/setup_db.rb index 6ba3033dd..497406700 100644 --- a/benchmark/setup_db.rb +++ b/benchmark/setup_db.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') # This script is for generating psudo-random data into a single table consisting of nearly every diff --git a/examples/eventmachine.rb b/examples/eventmachine.rb index 273f1bc52..dd8419cf2 100644 --- a/examples/eventmachine.rb +++ b/examples/eventmachine.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - $LOAD_PATH.unshift 'lib' require 'rubygems' diff --git a/examples/threaded.rb b/examples/threaded.rb index eaf769f8b..440a0081b 100644 --- a/examples/threaded.rb +++ b/examples/threaded.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - $LOAD_PATH.unshift 'lib' require 'mysql2' require 'timeout' diff --git a/ext/mysql2/client.h b/ext/mysql2/client.h index e5afe985f..5e0ebe3f0 100644 --- a/ext/mysql2/client.h +++ b/ext/mysql2/client.h @@ -1,12 +1,6 @@ #ifndef MYSQL2_CLIENT_H #define MYSQL2_CLIENT_H -#ifndef HAVE_RB_THREAD_CALL_WITHOUT_GVL -/* emulate rb_thread_call_without_gvl with rb_thread_blocking_region */ -#define rb_thread_call_without_gvl(func, data1, ubf, data2) \ - rb_thread_blocking_region((rb_blocking_function_t *)func, data1, ubf, data2) -#endif /* ! HAVE_RB_THREAD_CALL_WITHOUT_GVL */ - typedef struct { VALUE encoding; VALUE active_thread; /* rb_thread_current() or Qnil */ diff --git a/ext/mysql2/extconf.rb b/ext/mysql2/extconf.rb index bb08556a2..b73774536 100644 --- a/ext/mysql2/extconf.rb +++ b/ext/mysql2/extconf.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'mkmf' require 'English' @@ -27,9 +25,6 @@ def add_ssl_defines(header) have_func('rb_absint_size') have_func('rb_absint_singlebit_p') -# 2.0-only -have_header('ruby/thread.h') && have_func('rb_thread_call_without_gvl', 'ruby/thread.h') - # Missing in RBX (https://github.com/rubinius/rubinius/issues/3771) have_func('rb_wait_for_single_fd') @@ -57,14 +52,6 @@ def add_ssl_defines(header) # If the user has provided a --with-mysql-dir argument, we must respect it or fail. inc, lib = dir_config('mysql') if inc && lib - # TODO: Remove when 2.0.0 is the minimum supported version - # Ruby versions not incorporating the mkmf fix at - # https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717 - # do not properly search for lib directories, and must be corrected - unless lib && lib[-3, 3] == 'lib' - @libdir_basename = 'lib' - inc, lib = dir_config('mysql') - end abort "-----\nCannot find include dir(s) #{inc}\n-----" unless inc && inc.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) } abort "-----\nCannot find library dir(s) #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) } warn "-----\nUsing --with-mysql-dir=#{File.dirname inc}\n-----" diff --git a/ext/mysql2/mysql2_ext.h b/ext/mysql2/mysql2_ext.h index d94f29483..f76ea45ec 100644 --- a/ext/mysql2/mysql2_ext.h +++ b/ext/mysql2/mysql2_ext.h @@ -18,15 +18,7 @@ void Init_mysql2(void); #endif #include -// ruby/thread.h was added in 2.0.0. See: -// https://github.com/ruby/ruby/commit/c51a826 -// -// Rubinius doesn't define this, but it ships an empty thread.h (the symbols we -// care about are in ruby.h); this is safe to remove when < 2.0.0 is no longer -// supported. -#ifdef HAVE_RUBY_THREAD_H #include -#endif #if defined(__GNUC__) && (__GNUC__ >= 3) #define RB_MYSQL_NORETURN __attribute__ ((noreturn)) diff --git a/lib/mysql2.rb b/lib/mysql2.rb index 4ec3198f6..4bf75364a 100644 --- a/lib/mysql2.rb +++ b/lib/mysql2.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'date' require 'bigdecimal' @@ -75,13 +73,11 @@ def self.key_hash_as_symbols(hash) # Timeout::ExitException was removed in Ruby 2.3.0, 2.2.3, and 2.1.8, # but is present in earlier 2.1.x and 2.2.x, so we provide a shim. # - if Thread.respond_to?(:handle_interrupt) - require 'timeout' - TIMEOUT_ERROR_CLASS = if defined?(::Timeout::ExitException) - ::Timeout::ExitException - else - ::Timeout::Error - end + require 'timeout' + TIMEOUT_ERROR_CLASS = if defined?(::Timeout::ExitException) + ::Timeout::ExitException + else + ::Timeout::Error end end end diff --git a/lib/mysql2/client.rb b/lib/mysql2/client.rb index 2c3a92d72..2cc0953cf 100644 --- a/lib/mysql2/client.rb +++ b/lib/mysql2/client.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - module Mysql2 class Client attr_reader :query_options, :read_timeout @@ -33,7 +31,7 @@ def initialize(opts = {}) opts[:connect_timeout] = 120 unless opts.key?(:connect_timeout) # TODO: stricter validation rather than silent massaging - [:reconnect, :connect_timeout, :local_infile, :read_timeout, :write_timeout, :default_file, :default_group, :secure_auth, :init_command, :automatic_close, :enable_cleartext_plugin].each do |key| + %i[reconnect connect_timeout local_infile read_timeout write_timeout default_file default_group secure_auth init_command automatic_close enable_cleartext_plugin].each do |key| next unless opts.key?(key) case key when :reconnect, :local_infile, :secure_auth, :automatic_close, :enable_cleartext_plugin @@ -71,7 +69,7 @@ def initialize(opts = {}) conn_attrs = opts[:connect_attrs] || {} conn_attrs[:program_name] = $PROGRAM_NAME unless conn_attrs.key?(:program_name) - if [:user, :pass, :hostname, :dbname, :db, :sock].any? { |k| @query_options.key?(k) } + if %i[user pass hostname dbname db sock].any? { |k| @query_options.key?(k) } warn "============= WARNING FROM mysql2 =============" warn "The options :user, :pass, :hostname, :dbname, :db, and :sock are deprecated and will be removed at some point in the future." warn "Instead, please use :username, :password, :host, :port, :database, :socket, :flags for the options." @@ -124,14 +122,8 @@ def parse_flags_array(flags, initial = 0) end end - if Thread.respond_to?(:handle_interrupt) - def query(sql, options = {}) - Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do - _query(sql, @query_options.merge(options)) - end - end - else - def query(sql, options = {}) + def query(sql, options = {}) + Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do _query(sql, @query_options.merge(options)) end end diff --git a/lib/mysql2/console.rb b/lib/mysql2/console.rb index 1e3885ffa..d8fb9e324 100644 --- a/lib/mysql2/console.rb +++ b/lib/mysql2/console.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - # Loaded by script/console. Land helpers here. Pry.config.prompt = lambda do |context, *| diff --git a/lib/mysql2/em.rb b/lib/mysql2/em.rb index 381a2a739..329b3080e 100644 --- a/lib/mysql2/em.rb +++ b/lib/mysql2/em.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'eventmachine' require 'mysql2' diff --git a/lib/mysql2/error.rb b/lib/mysql2/error.rb index a66fce45d..093dc65c2 100644 --- a/lib/mysql2/error.rb +++ b/lib/mysql2/error.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - module Mysql2 class Error < StandardError ENCODE_OPTS = { diff --git a/lib/mysql2/field.rb b/lib/mysql2/field.rb index 94a006739..516ec17c2 100644 --- a/lib/mysql2/field.rb +++ b/lib/mysql2/field.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - module Mysql2 Field = Struct.new(:name, :type) end diff --git a/lib/mysql2/result.rb b/lib/mysql2/result.rb index 255026a2b..585104e0b 100644 --- a/lib/mysql2/result.rb +++ b/lib/mysql2/result.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - module Mysql2 class Result attr_reader :server_flags diff --git a/lib/mysql2/statement.rb b/lib/mysql2/statement.rb index 482ccce19..f9741d075 100644 --- a/lib/mysql2/statement.rb +++ b/lib/mysql2/statement.rb @@ -1,17 +1,9 @@ -# encoding: UTF-8 - module Mysql2 class Statement include Enumerable - if Thread.respond_to?(:handle_interrupt) - def execute(*args) - Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do - _execute(*args) - end - end - else - def execute(*args) + def execute(*args) + Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do _execute(*args) end end diff --git a/lib/mysql2/version.rb b/lib/mysql2/version.rb index 2afa42fc0..d7a169357 100644 --- a/lib/mysql2/version.rb +++ b/lib/mysql2/version.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - module Mysql2 VERSION = "0.4.10".freeze end diff --git a/mysql2.gemspec b/mysql2.gemspec index 3e9d4e5e3..1ec27428f 100644 --- a/mysql2.gemspec +++ b/mysql2.gemspec @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require File.expand_path('../lib/mysql2/version', __FILE__) Mysql2::GEMSPEC = Gem::Specification.new do |s| @@ -12,7 +10,7 @@ Mysql2::GEMSPEC = Gem::Specification.new do |s| s.homepage = 'http://github.com/brianmario/mysql2' s.rdoc_options = ["--charset=UTF-8"] s.summary = 'A simple, fast Mysql library for Ruby, binding to libmysql' - s.required_ruby_version = '>= 1.9.3' + s.required_ruby_version = '>= 2.0.0' s.files = `git ls-files README.md CHANGELOG.md LICENSE ext lib support`.split s.test_files = `git ls-files spec examples`.split diff --git a/spec/em/em_spec.rb b/spec/em/em_spec.rb index 4daab27bc..c57d474dd 100644 --- a/spec/em/em_spec.rb +++ b/spec/em/em_spec.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'spec_helper' begin require 'eventmachine' diff --git a/spec/mysql2/client_spec.rb b/spec/mysql2/client_spec.rb index 3c72c2a99..502d72af5 100644 --- a/spec/mysql2/client_spec.rb +++ b/spec/mysql2/client_spec.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'spec_helper' RSpec.describe Mysql2::Client do @@ -607,10 +605,6 @@ def run_gc end it 'should be impervious to connection-corrupting timeouts in #execute' do - # the statement handle gets corrupted and will segfault the tests if interrupted, - # so we can't even use pending on this test, really have to skip it on older Rubies. - skip('`Thread.handle_interrupt` is not defined') unless Thread.respond_to?(:handle_interrupt) - # attempt to break the connection stmt = @client.prepare('SELECT SLEEP(?)') expect { Timeout.timeout(0.1) { stmt.execute(0.2) } }.to raise_error(Timeout::Error) diff --git a/spec/mysql2/error_spec.rb b/spec/mysql2/error_spec.rb index be3154be9..c94a31961 100644 --- a/spec/mysql2/error_spec.rb +++ b/spec/mysql2/error_spec.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'spec_helper' RSpec.describe Mysql2::Error do diff --git a/spec/mysql2/result_spec.rb b/spec/mysql2/result_spec.rb index f1386b16c..775bcf8ad 100644 --- a/spec/mysql2/result_spec.rb +++ b/spec/mysql2/result_spec.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'spec_helper' RSpec.describe Mysql2::Result do diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index 7d856cbd3..40feb634e 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require './spec/spec_helper.rb' RSpec.describe Mysql2::Statement do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 32e3b0069..12b48df67 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'rspec' require 'mysql2' require 'timeout' diff --git a/support/mysql_enc_to_ruby.rb b/support/mysql_enc_to_ruby.rb index d0a5a4b81..602c5447a 100644 --- a/support/mysql_enc_to_ruby.rb +++ b/support/mysql_enc_to_ruby.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'mysql2' diff --git a/support/ruby_enc_to_mysql.rb b/support/ruby_enc_to_mysql.rb index 120431e6e..4749ead75 100644 --- a/support/ruby_enc_to_mysql.rb +++ b/support/ruby_enc_to_mysql.rb @@ -1,5 +1,3 @@ -# encoding: UTF-8 - mysql_to_rb = { "big5" => "Big5", "dec8" => nil, diff --git a/tasks/benchmarks.rake b/tasks/benchmarks.rake index 8302f62a3..b587ecdc0 100644 --- a/tasks/benchmarks.rake +++ b/tasks/benchmarks.rake @@ -1,5 +1,3 @@ -# encoding: UTF-8 - BENCHMARKS = Dir["#{File.dirname(__FILE__)}/../benchmark/*.rb"].map do |path| File.basename(path, '.rb') end - ['setup_db'] diff --git a/tasks/compile.rake b/tasks/compile.rake index ce33554f5..a9b7eb8a6 100644 --- a/tasks/compile.rake +++ b/tasks/compile.rake @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require "rake/extensiontask" load File.expand_path('../../mysql2.gemspec', __FILE__) unless defined? Mysql2::GEMSPEC diff --git a/tasks/generate.rake b/tasks/generate.rake index 2712eeaee..6e5eebd99 100644 --- a/tasks/generate.rake +++ b/tasks/generate.rake @@ -1,5 +1,3 @@ -# encoding: UTF-8 - task :encodings do sh "ruby support/mysql_enc_to_ruby.rb > ./ext/mysql2/mysql_enc_to_ruby.h" sh "ruby support/ruby_enc_to_mysql.rb | gperf > ./ext/mysql2/mysql_enc_name_to_ruby.h" diff --git a/tasks/rspec.rake b/tasks/rspec.rake index a7bbfb098..ea8dc2258 100644 --- a/tasks/rspec.rake +++ b/tasks/rspec.rake @@ -1,5 +1,3 @@ -# encoding: UTF-8 - begin require 'rspec' require 'rspec/core/rake_task' diff --git a/tasks/vendor_mysql.rake b/tasks/vendor_mysql.rake index 6d77be208..85e88fe68 100644 --- a/tasks/vendor_mysql.rake +++ b/tasks/vendor_mysql.rake @@ -1,5 +1,3 @@ -# encoding: UTF-8 - require 'rake/clean' require 'rake/extensioncompiler'