From 327ce194320d4189bd7f8289404503ed99e853ca Mon Sep 17 00:00:00 2001 From: David Siaw Date: Tue, 4 Jun 2024 15:47:23 +0900 Subject: [PATCH 1/7] add bigdecimal for ruby 3.4 --- mysql2.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql2.gemspec b/mysql2.gemspec index cc9a55e48..28fd1c301 100644 --- a/mysql2.gemspec +++ b/mysql2.gemspec @@ -22,4 +22,6 @@ Mysql2::GEMSPEC = Gem::Specification.new do |s| s.files = `git ls-files README.md CHANGELOG.md LICENSE ext lib support`.split s.metadata['msys2_mingw_dependencies'] = 'libmariadbclient' + + s.add_dependency 'bigdecimal' end From 76a221282c4f6f7e64740bfa6cb79303d5ae8aa1 Mon Sep 17 00:00:00 2001 From: David Siaw Date: Tue, 4 Jun 2024 15:48:59 +0900 Subject: [PATCH 2/7] remove ubuntu 18 because it doesnt exist anymore --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34a04ca4d..354f8a240 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: - {os: ubuntu-22.04, ruby: '3.0', db: mariadb10.6} - {os: ubuntu-20.04, ruby: '2.7', db: mariadb10.6} - {os: ubuntu-20.04, ruby: '2.7', db: mysql80} - - {os: ubuntu-18.04, ruby: '2.7', db: mysql57} + # - {os: ubuntu-18.04, ruby: '2.7', db: mysql57} # no longer exists # TODO - Windows CI # - {os: windows-2022, ruby: '3.2', db: mysql80} From 5af964dbfcfeffb3204da731dfc1309fe6a9e0a8 Mon Sep 17 00:00:00 2001 From: David Siaw Date: Tue, 4 Jun 2024 15:53:56 +0900 Subject: [PATCH 3/7] zstd --- README.md | 2 +- ci/setup.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf35222d5..d44e77dc7 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Ruby runtime and MySQL client libraries are compiled with the same OpenSSL family, 1.0 or 1.1 or 3.0, since only one can be loaded at runtime. ``` sh -$ brew install openssl@1.1 +$ brew install openssl@1.1 zstd $ gem install mysql2 -- --with-openssl-dir=$(brew --prefix openssl@1.1) or diff --git a/ci/setup.sh b/ci/setup.sh index 956608c69..938f0c8de 100644 --- a/ci/setup.sh +++ b/ci/setup.sh @@ -70,7 +70,7 @@ if [[ x$OSTYPE =~ ^xdarwin ]]; then done brew info "$DB" - brew install "$DB" + brew install "$DB" zstd DB_PREFIX="$(brew --prefix "${DB}")" export PATH="${DB_PREFIX}/bin:${PATH}" export LDFLAGS="-L${DB_PREFIX}/lib" From 757b357339a315d63c1566a0dc16e7f6ea367cff Mon Sep 17 00:00:00 2001 From: David Siaw Date: Tue, 4 Jun 2024 15:20:26 +0900 Subject: [PATCH 4/7] dynamic password provider --- lib/mysql2/client.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/mysql2/client.rb b/lib/mysql2/client.rb index 582b6e305..973ebd78b 100644 --- a/lib/mysql2/client.rb +++ b/lib/mysql2/client.rb @@ -79,7 +79,7 @@ def initialize(opts = {}) end user = opts[:username] || opts[:user] - pass = opts[:password] || opts[:pass] + pass = extract_password(opts) host = opts[:host] || opts[:hostname] port = opts[:port] database = opts[:database] || opts[:dbname] || opts[:db] @@ -97,6 +97,14 @@ def initialize(opts = {}) connect user, pass, host, port, database, socket, flags, conn_attrs end + def extract_password(opts) + return (opts[:password] || opts[:pass]) if !opts[:password_provider] + klass = Kernel.const_get(opts[:password_provider]) + + obj = klass.new(opts) + obj.password + end + def parse_ssl_mode(mode) m = mode.to_s.upcase if m.start_with?('SSL_MODE_') From 9babaf311d08fca95ab3ff85164354682d1565c8 Mon Sep 17 00:00:00 2001 From: David Siaw Date: Tue, 4 Jun 2024 16:03:24 +0900 Subject: [PATCH 5/7] rubocop fixes --- .rubocop_todo.yml | 2 +- ext/mysql2/extconf.rb | 2 +- lib/mysql2/client.rb | 3 ++- spec/mysql2/statement_spec.rb | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index eba2091dc..02cfbae17 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -45,7 +45,7 @@ Metrics/BlockNesting: # Offense count: 1 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 135 + Max: 141 # Offense count: 3 # Configuration parameters: IgnoredMethods. diff --git a/ext/mysql2/extconf.rb b/ext/mysql2/extconf.rb index bee775854..01e5eeed6 100644 --- a/ext/mysql2/extconf.rb +++ b/ext/mysql2/extconf.rb @@ -108,7 +108,7 @@ def add_ssl_defines(header) warn "-----\nUsing --with-mysql-dir=#{File.dirname inc}\n-----" rpath_dir = lib have_library('mysqlclient') -elsif (mc = (with_config('mysql-config') || Dir[GLOB].first)) +elsif (mc = with_config('mysql-config') || Dir[GLOB].first) # If the user has provided a --with-mysql-config argument, we must respect it or fail. # If the user gave --with-mysql-config with no argument means we should try to find it. mc = Dir[GLOB].first if mc == true diff --git a/lib/mysql2/client.rb b/lib/mysql2/client.rb index 973ebd78b..f1013ea34 100644 --- a/lib/mysql2/client.rb +++ b/lib/mysql2/client.rb @@ -98,7 +98,8 @@ def initialize(opts = {}) end def extract_password(opts) - return (opts[:password] || opts[:pass]) if !opts[:password_provider] + return opts[:password] || opts[:pass] unless opts[:password_provider] + klass = Kernel.const_get(opts[:password_provider]) obj = klass.new(opts) diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index 57e590804..c3ebf9bb3 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -320,7 +320,7 @@ def stmt_count result = @client.prepare("SELECT 1 UNION SELECT 2").execute(stream: true, cache_rows: false) expect do result.each {} - result.each {} # rubocop:disable Style/CombinableLoops + result.each {} end.to raise_exception(Mysql2::Error) end end From a786cf5e5d531f61a430fb067088c29c0d56446c Mon Sep 17 00:00:00 2001 From: David Siaw Date: Tue, 4 Jun 2024 16:09:27 +0900 Subject: [PATCH 6/7] restore disable --- spec/mysql2/statement_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index c3ebf9bb3..8485a8b66 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -319,7 +319,7 @@ def stmt_count it "should throw an exception if we try to iterate twice when streaming is enabled" do result = @client.prepare("SELECT 1 UNION SELECT 2").execute(stream: true, cache_rows: false) expect do - result.each {} + result.each {} # rubocop:disable Style/CombinableLoops result.each {} end.to raise_exception(Mysql2::Error) end From 13c22232231fd058ac617b09c800c984ac502af2 Mon Sep 17 00:00:00 2001 From: David Siaw Date: Tue, 4 Jun 2024 16:14:27 +0900 Subject: [PATCH 7/7] disable the thing --- spec/mysql2/statement_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index 8485a8b66..57e590804 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -319,8 +319,8 @@ def stmt_count it "should throw an exception if we try to iterate twice when streaming is enabled" do result = @client.prepare("SELECT 1 UNION SELECT 2").execute(stream: true, cache_rows: false) expect do - result.each {} # rubocop:disable Style/CombinableLoops result.each {} + result.each {} # rubocop:disable Style/CombinableLoops end.to raise_exception(Mysql2::Error) end end