Skip to content

Commit 8c6186b

Browse files
authored
Merge pull request #929 from sodabrew/appveyor-2.4
Windows build fixes for Ruby 2.0, Appveyor fixes for Ruby 2.4
2 parents c0ba3d3 + 827dc51 commit 8c6186b

File tree

9 files changed

+39
-44
lines changed

9 files changed

+39
-44
lines changed

.travis.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ matrix:
4545
mariadb: 10.2
4646
hosts:
4747
- mysql2gem.example.com
48-
- rvm: 2.0.0
49-
env: DB=mysql51
50-
dist: precise
51-
addons:
52-
hosts:
53-
- mysql2gem.example.com
5448
- rvm: 2.0.0
5549
env: DB=mysql55
5650
dist: precise
@@ -84,6 +78,3 @@ matrix:
8478
- os: osx
8579
rvm: 2.3
8680
env: DB=mysql56
87-
- rvm: 2.0.0
88-
env: DB=mysql51
89-
dist: precise

.travis_mysql51.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

.travis_setup.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
set -eux
44

5-
# Install MySQL 5.1 if DB=mysql51
6-
if [[ -n ${DB-} && x$DB =~ ^xmysql51 ]]; then
7-
sudo bash .travis_mysql51.sh
8-
fi
9-
105
# Install MySQL 5.7 if DB=mysql57
116
if [[ -n ${DB-} && x$DB =~ ^xmysql57 ]]; then
127
sudo bash .travis_mysql57.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ This gem is tested with the following MySQL and MariaDB versions:
530530

531531
* MySQL 5.5, 5.6, 5.7, 8.0
532532
* MySQL Connector/C 6.0 and 6.1 (primarily on Windows)
533-
* MariaDB 5.5, 10.0, 10.1
533+
* MariaDB 5.5, 10.0, 10.1, 10.2
534534

535535
### Ruby on Rails / Active Record
536536

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ install:
66
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
77
- ruby --version
88
- gem --version
9-
- gem install bundler --quiet --no-ri --no-rdoc
109
- bundler --version
1110
- bundle install --without benchmarks --path vendor/bundle
1211
- IF DEFINED MINGW_PACKAGE_PREFIX (ridk exec pacman -S --noconfirm --needed %MINGW_PACKAGE_PREFIX%-libmariadbclient)

ext/mysql2/client.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static VALUE rb_mysql_get_ssl_cipher(VALUE self)
400400
return rb_str;
401401
}
402402

403-
#ifdef HAVE_CONST_MYSQL_OPT_CONNECT_ATTR_ADD
403+
#ifdef CLIENT_CONNECT_ATTRS
404404
static int opt_connect_attr_add_i(VALUE key, VALUE value, VALUE arg)
405405
{
406406
mysql_client_wrapper *wrapper = (mysql_client_wrapper *)arg;
@@ -428,7 +428,7 @@ static VALUE rb_mysql_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VA
428428
args.mysql = wrapper->client;
429429
args.client_flag = NUM2ULONG(flags);
430430

431-
#ifdef HAVE_CONST_MYSQL_OPT_CONNECT_ATTR_ADD
431+
#ifdef CLIENT_CONNECT_ATTRS
432432
mysql_options(wrapper->client, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
433433
rb_hash_foreach(conn_attrs, opt_connect_attr_add_i, (VALUE)wrapper);
434434
#endif
@@ -1558,6 +1558,16 @@ void init_mysql2_client() {
15581558
LONG2NUM(CLIENT_BASIC_FLAGS));
15591559
#endif
15601560

1561+
#ifdef CLIENT_CONNECT_ATTRS
1562+
rb_const_set(cMysql2Client, rb_intern("CONNECT_ATTRS"),
1563+
LONG2NUM(CLIENT_CONNECT_ATTRS));
1564+
#else
1565+
/* HACK because MySQL 5.5 and earlier don't define this constant,
1566+
* but we're using it in our default connection flags. */
1567+
rb_const_set(cMysql2Client, rb_intern("CONNECT_ATTRS"),
1568+
INT2NUM(0));
1569+
#endif
1570+
15611571
#if defined(FULL_SSL_MODE_SUPPORT) // MySQL 5.7.11 and above
15621572
rb_const_set(cMysql2Client, rb_intern("SSL_MODE_DISABLED"), INT2NUM(SSL_MODE_DISABLED));
15631573
rb_const_set(cMysql2Client, rb_intern("SSL_MODE_PREFERRED"), INT2NUM(SSL_MODE_PREFERRED));

ext/mysql2/extconf.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def add_ssl_defines(header)
5252
# If the user has provided a --with-mysql-dir argument, we must respect it or fail.
5353
inc, lib = dir_config('mysql')
5454
if inc && lib
55+
# Ruby versions below 2.0 on Unix and below 2.1 on Windows
56+
# do not properly search for lib directories, and must be corrected:
57+
# https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717
58+
unless lib && lib[-3, 3] == 'lib'
59+
@libdir_basename = 'lib'
60+
inc, lib = dir_config('mysql')
61+
end
5562
abort "-----\nCannot find include dir(s) #{inc}\n-----" unless inc && inc.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
5663
abort "-----\nCannot find library dir(s) #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
5764
warn "-----\nUsing --with-mysql-dir=#{File.dirname inc}\n-----"
@@ -103,7 +110,6 @@ def add_ssl_defines(header)
103110
have_const('SERVER_QUERY_NO_GOOD_INDEX_USED', mysql_h)
104111
have_const('SERVER_QUERY_NO_INDEX_USED', mysql_h)
105112
have_const('SERVER_QUERY_WAS_SLOW', mysql_h)
106-
have_const('MYSQL_OPT_CONNECT_ATTR_ADD', mysql_h) # for mysql_options4
107113

108114
# This is our wishlist. We use whichever flags work on the host.
109115
# -Wall and -Wextra are included by default.

lib/mysql2/client.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def self.default_query_options
1111
database_timezone: :local, # timezone Mysql2 will assume datetime objects are stored in
1212
application_timezone: nil, # timezone Mysql2 will convert to before handing the object back to the caller
1313
cache_rows: true, # tells Mysql2 to use its internal row cache for results
14-
connect_flags: REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION,
14+
connect_flags: REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION | CONNECT_ATTRS,
1515
cast: true,
1616
default_file: nil,
1717
default_group: nil,
@@ -64,11 +64,6 @@ def initialize(opts = {})
6464
# SSL verify is a connection flag rather than a mysql_ssl_set option
6565
flags |= SSL_VERIFY_SERVER_CERT if opts[:sslverify]
6666

67-
# Set default program_name in performance_schema.session_connect_attrs
68-
# and performance_schema.session_account_connect_attrs
69-
conn_attrs = opts[:connect_attrs] || {}
70-
conn_attrs[:program_name] = $PROGRAM_NAME unless conn_attrs.key?(:program_name)
71-
7267
if %i[user pass hostname dbname db sock].any? { |k| @query_options.key?(k) }
7368
warn "============= WARNING FROM mysql2 ============="
7469
warn "The options :user, :pass, :hostname, :dbname, :db, and :sock are deprecated and will be removed at some point in the future."
@@ -90,9 +85,7 @@ def initialize(opts = {})
9085
port = port.to_i unless port.nil?
9186
database = database.to_s unless database.nil?
9287
socket = socket.to_s unless socket.nil?
93-
conn_attrs = conn_attrs.each_with_object({}) do |(key, value), hash|
94-
hash[key.to_s] = value.to_s
95-
end
88+
conn_attrs = parse_connect_attrs(opts[:connect_attrs])
9689

9790
connect user, pass, host, port, database, socket, flags, conn_attrs
9891
end
@@ -122,6 +115,17 @@ def parse_flags_array(flags, initial = 0)
122115
end
123116
end
124117

118+
# Set default program_name in performance_schema.session_connect_attrs
119+
# and performance_schema.session_account_connect_attrs
120+
def parse_connect_attrs(conn_attrs)
121+
return {} if Mysql2::Client::CONNECT_ATTRS.zero?
122+
conn_attrs ||= {}
123+
conn_attrs[:program_name] ||= $PROGRAM_NAME
124+
conn_attrs.each_with_object({}) do |(key, value), hash|
125+
hash[key.to_s] = value.to_s
126+
end
127+
end
128+
125129
def query(sql, options = {})
126130
Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do
127131
_query(sql, @query_options.merge(options))

spec/mysql2/client_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def connect(*args)
7979
Mysql2::Client::LONG_FLAG |
8080
Mysql2::Client::TRANSACTIONS |
8181
Mysql2::Client::PROTOCOL_41 |
82-
Mysql2::Client::SECURE_CONNECTION
82+
Mysql2::Client::SECURE_CONNECTION |
83+
Mysql2::Client::CONNECT_ATTRS
8384
expect(client.connect_args.last[6]).to eql(client_flags)
8485
end
8586

@@ -438,17 +439,17 @@ def run_gc
438439

439440
it "should set default program_name in connect_attrs" do
440441
client = new_client
441-
if Mysql2::Client.info[:version] < '5.6' || client.info[:version] < '5.6'
442-
pending('Both client and server versions must be MySQL 5.6 or later.')
442+
if Mysql2::Client::CONNECT_ATTRS.zero? || client.server_info[:version].match(/10.[01].\d+-MariaDB/)
443+
pending('Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.')
443444
end
444445
result = client.query("SELECT attr_value FROM performance_schema.session_account_connect_attrs WHERE processlist_id = connection_id() AND attr_name = 'program_name'")
445446
expect(result.first['attr_value']).to eq($PROGRAM_NAME)
446447
end
447448

448449
it "should set custom connect_attrs" do
449450
client = new_client(connect_attrs: { program_name: 'my_program_name', foo: 'fooval', bar: 'barval' })
450-
if Mysql2::Client.info[:version] < '5.6' || client.info[:version] < '5.6'
451-
pending('Both client and server versions must be MySQL 5.6 or later.')
451+
if Mysql2::Client::CONNECT_ATTRS.zero? || client.server_info[:version].match(/10.[01].\d+-MariaDB/)
452+
pending('Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.')
452453
end
453454
results = Hash[client.query("SELECT * FROM performance_schema.session_account_connect_attrs WHERE processlist_id = connection_id()").map { |x| x.values_at('ATTR_NAME', 'ATTR_VALUE') }]
454455
expect(results['program_name']).to eq('my_program_name')

0 commit comments

Comments
 (0)