Skip to content

Commit

Permalink
Drop 1.9.3 support (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird authored and sodabrew committed Nov 30, 2017
1 parent 245c3d1 commit 5fa7700
Show file tree
Hide file tree
Showing 41 changed files with 17 additions and 138 deletions.
6 changes: 1 addition & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 1.9
TargetRubyVersion: 2.0

DisplayCopNames: true
Exclude:
Expand All @@ -21,10 +21,6 @@ Layout/IndentHeredoc:
Lint/EndAlignment:
EnforcedStyleAlignWith: variable

Style/Encoding:
AutoCorrectEncodingComment: '# encoding: UTF-8'
EnforcedStyle: always

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: consistent_comma

Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ rvm:
- 2.2
- 2.1
- 2.0.0
- 1.9.3
- ruby-head
matrix:
include:
Expand Down
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

source 'https://rubygems.org'

gemspec
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'rake'

# Load custom tasks (careful attention to define tasks before prerequisites)
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions benchmark/active_record.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down
2 changes: 0 additions & 2 deletions benchmark/active_record_threaded.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down
2 changes: 0 additions & 2 deletions benchmark/allocations.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down
2 changes: 0 additions & 2 deletions benchmark/escape.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down
2 changes: 0 additions & 2 deletions benchmark/query_with_mysql_casting.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down
2 changes: 0 additions & 2 deletions benchmark/query_without_mysql_casting.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down
2 changes: 0 additions & 2 deletions benchmark/sequel.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
Expand Down
2 changes: 0 additions & 2 deletions benchmark/setup_db.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions examples/eventmachine.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

$LOAD_PATH.unshift 'lib'

require 'rubygems'
Expand Down
2 changes: 0 additions & 2 deletions examples/threaded.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

$LOAD_PATH.unshift 'lib'
require 'mysql2'
require 'timeout'
Expand Down
6 changes: 0 additions & 6 deletions ext/mysql2/client.h
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
13 changes: 0 additions & 13 deletions ext/mysql2/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'mkmf'
require 'English'

Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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-----"
Expand Down
8 changes: 0 additions & 8 deletions ext/mysql2/mysql2_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@ void Init_mysql2(void);
#endif

#include <ruby/encoding.h>
// 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 <ruby/thread.h>
#endif

#if defined(__GNUC__) && (__GNUC__ >= 3)
#define RB_MYSQL_NORETURN __attribute__ ((noreturn))
Expand Down
14 changes: 5 additions & 9 deletions lib/mysql2.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'date'
require 'bigdecimal'

Expand Down Expand Up @@ -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
16 changes: 4 additions & 12 deletions lib/mysql2/client.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

module Mysql2
class Client
attr_reader :query_options, :read_timeout
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/mysql2/console.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

# Loaded by script/console. Land helpers here.

Pry.config.prompt = lambda do |context, *|
Expand Down
2 changes: 0 additions & 2 deletions lib/mysql2/em.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

require 'eventmachine'
require 'mysql2'

Expand Down
2 changes: 0 additions & 2 deletions lib/mysql2/error.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

module Mysql2
class Error < StandardError
ENCODE_OPTS = {
Expand Down
2 changes: 0 additions & 2 deletions lib/mysql2/field.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

module Mysql2
Field = Struct.new(:name, :type)
end
2 changes: 0 additions & 2 deletions lib/mysql2/result.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

module Mysql2
class Result
attr_reader :server_flags
Expand Down
12 changes: 2 additions & 10 deletions lib/mysql2/statement.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/mysql2/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

module Mysql2
VERSION = "0.4.10".freeze
end
4 changes: 1 addition & 3 deletions mysql2.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require File.expand_path('../lib/mysql2/version', __FILE__)

Mysql2::GEMSPEC = Gem::Specification.new do |s|
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions spec/em/em_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'spec_helper'
begin
require 'eventmachine'
Expand Down
6 changes: 0 additions & 6 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'spec_helper'

RSpec.describe Mysql2::Client do
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions spec/mysql2/error_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'spec_helper'

RSpec.describe Mysql2::Error do
Expand Down
2 changes: 0 additions & 2 deletions spec/mysql2/result_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'spec_helper'

RSpec.describe Mysql2::Result do
Expand Down
2 changes: 0 additions & 2 deletions spec/mysql2/statement_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require './spec/spec_helper.rb'

RSpec.describe Mysql2::Statement do
Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'rspec'
require 'mysql2'
require 'timeout'
Expand Down
2 changes: 0 additions & 2 deletions support/mysql_enc_to_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'mysql2'

Expand Down
2 changes: 0 additions & 2 deletions support/ruby_enc_to_mysql.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

mysql_to_rb = {
"big5" => "Big5",
"dec8" => nil,
Expand Down
2 changes: 0 additions & 2 deletions tasks/benchmarks.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

BENCHMARKS = Dir["#{File.dirname(__FILE__)}/../benchmark/*.rb"].map do |path|
File.basename(path, '.rb')
end - ['setup_db']
Expand Down
Loading

0 comments on commit 5fa7700

Please sign in to comment.