Skip to content

Commit

Permalink
Merge branch 'master' into force_latin1_to_utf8
Browse files Browse the repository at this point in the history
* master: (21 commits)
  Bump version to 0.5.0
  README note that MariaDB 10.3 and Ruby 2.6 are supported
  Initialize params_enc variable to resolve a warning
  Travis CI add MariaDB 10.3
  Travis CI add Ruby 2.6
  Use a local scope to avoid leaking the temporary variable for bind_count
  Revert "Layout/IndentHeredoc"
  Bump RuboCop limits for spec file length
  Style nit fix for brianmario#943
  Use a typedef my_bool to improve compatibility across MySQL versions
  Revert "Use `bool` instead of `my_bool` which has been removed since MySQL 8.0.1 (brianmario#840)"
  Style nit for brianmario#943
  Expose the `mysql_set_server_option`: (brianmario#943)
  Update usage section of README.md (brianmario#939)
  Travis CI should run MySQL 5.5 tests on Trusty
  Looks like Windows Ruby 2.0 still has the buggy mkmf
  Use CLIENT_CONNECT_ATTRS flag to test the connection attributes feature
  README note that MariaDB 10.2 is supported
  Travis CI drop tests for MySQL 5.1 on Ubuntu Precise
  Fix Ruby 2.4 on Appveyor
  ...
  • Loading branch information
jeremy committed Mar 21, 2018
2 parents 18a3b23 + bf227ac commit a6de4a6
Show file tree
Hide file tree
Showing 22 changed files with 209 additions and 116 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ Layout/CaseIndentation:
Layout/IndentHash:
EnforcedStyle: consistent

Layout/IndentHeredoc:
EnforcedStyle: powerpack

Lint/EndAlignment:
EnforcedStyleAlignWith: variable

Expand Down
11 changes: 10 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
Exclude:
- 'support/ruby_enc_to_mysql.rb'
- 'tasks/compile.rake'

# Offense count: 2
Metrics/AbcSize:
Max: 90

# Offense count: 31
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 825
Max: 850

# Offense count: 1
# Configuration parameters: CountBlocks.
Expand Down
24 changes: 8 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bundler_args: --without benchmarks development
# Pin Rubygems to a working version. Sometimes it breaks upstream. Update now and then.
before_install:
- gem --version
- gem update --system 2.7.3
- gem update --system 2.7.6 --quiet
- gem update bundler
- gem --version
- bash .travis_setup.sh
Expand All @@ -18,6 +18,7 @@ addons:
- mysql-client-core-5.6
- mysql-client-5.6
rvm:
- 2.6
- 2.5
- 2.4
- 2.3
Expand Down Expand Up @@ -45,23 +46,17 @@ matrix:
mariadb: 10.2
hosts:
- mysql2gem.example.com
- rvm: 2.0.0
env: DB=mysql51
dist: precise
- rvm: 2.4
env: DB=mariadb10.3
addons:
mariadb: 10.3
hosts:
- mysql2gem.example.com
- rvm: 2.0.0
- rvm: 2.4
env: DB=mysql55
dist: precise
addons:
hosts:
- mysql2gem.example.com
apt:
packages:
- mysql-server-5.5
- mysql-client-core-5.5
- mysql-client-5.5
- rvm: 2.4
env: DB=mysql57
addons:
Expand All @@ -73,7 +68,7 @@ matrix:
hosts:
- mysql2gem.example.com
- os: osx
rvm: 2.3
rvm: 2.4
env: DB=mysql56
addons:
hosts:
Expand All @@ -82,8 +77,5 @@ matrix:
allow_failures:
- rvm: ruby-head
- os: osx
rvm: 2.3
rvm: 2.4
env: DB=mysql56
- rvm: 2.0.0
env: DB=mysql51
dist: precise
11 changes: 0 additions & 11 deletions .travis_mysql51.sh

This file was deleted.

8 changes: 8 additions & 0 deletions .travis_mysql55.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -eux

apt-get purge -qq '^mysql*' '^libmysql*'
rm -fr /etc/mysql
rm -fr /var/lib/mysql
apt-get install -qq mysql-server-5.5 mysql-client-core-5.5 mysql-client-5.5 libmysqlclient-dev
6 changes: 3 additions & 3 deletions .travis_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

set -eux

# Install MySQL 5.1 if DB=mysql51
if [[ -n ${DB-} && x$DB =~ ^xmysql51 ]]; then
sudo bash .travis_mysql51.sh
# Install MySQL 5.5 if DB=mysql55
if [[ -n ${DB-} && x$DB =~ ^xmysql55 ]]; then
sudo bash .travis_mysql55.sh
fi

# Install MySQL 5.7 if DB=mysql57
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ results.each do |row|
# conveniently, row is a hash
# the keys are the fields, as you'd expect
# the values are pre-built ruby primitives mapped from their corresponding field types in MySQL
puts row["id"] # row["id"].class == Fixnum
puts row["id"] # row["id"].is_a? Integer
if row["dne"] # non-existant hash entry is nil
puts row["dne"]
end
Expand Down Expand Up @@ -533,14 +533,14 @@ 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 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x
* Ruby MRI 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.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:

* MySQL 5.5, 5.6, 5.7, 8.0
* MySQL Connector/C 6.0 and 6.1 (primarily on Windows)
* MariaDB 5.5, 10.0, 10.1
* MariaDB 5.5, 10.0, 10.1, 10.2, 10.3

### Ruby on Rails / Active Record

Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ install:
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
- ruby --version
- gem --version
- gem install bundler --quiet --no-ri --no-rdoc
- bundler --version
- bundle install --without benchmarks --path vendor/bundle
- IF DEFINED MINGW_PACKAGE_PREFIX (ridk exec pacman -S --noconfirm --needed %MINGW_PACKAGE_PREFIX%-libmariadbclient)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/query_with_mysql_casting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def mysql_cast(type, value)
Mysql::Field::TYPE_INT24, Mysql::Field::TYPE_LONGLONG, Mysql::Field::TYPE_YEAR
value.to_i
when Mysql::Field::TYPE_DECIMAL, Mysql::Field::TYPE_NEWDECIMAL
BigDecimal.new(value)
BigDecimal(value)
when Mysql::Field::TYPE_DOUBLE, Mysql::Field::TYPE_FLOAT
value.to_f
when Mysql::Field::TYPE_DATE
Expand Down
48 changes: 43 additions & 5 deletions ext/mysql2/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static VALUE rb_set_ssl_mode_option(VALUE self, VALUE setting) {
int val = NUM2INT( setting );
if (version >= 50703 && version < 50711) {
if (val == SSL_MODE_DISABLED || val == SSL_MODE_REQUIRED) {
bool b = ( val == SSL_MODE_REQUIRED );
my_bool b = ( val == SSL_MODE_REQUIRED );
int result = mysql_options( wrapper->client, MYSQL_OPT_SSL_ENFORCE, &b );
return INT2NUM(result);
} else {
Expand Down Expand Up @@ -400,7 +400,7 @@ static VALUE rb_mysql_get_ssl_cipher(VALUE self)
return rb_str;
}

#ifdef HAVE_CONST_MYSQL_OPT_CONNECT_ATTR_ADD
#ifdef CLIENT_CONNECT_ATTRS
static int opt_connect_attr_add_i(VALUE key, VALUE value, VALUE arg)
{
mysql_client_wrapper *wrapper = (mysql_client_wrapper *)arg;
Expand Down Expand Up @@ -428,7 +428,7 @@ static VALUE rb_mysql_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VA
args.mysql = wrapper->client;
args.client_flag = NUM2ULONG(flags);

#ifdef HAVE_CONST_MYSQL_OPT_CONNECT_ATTR_ADD
#ifdef CLIENT_CONNECT_ATTRS
mysql_options(wrapper->client, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
rb_hash_foreach(conn_attrs, opt_connect_attr_add_i, (VALUE)wrapper);
#endif
Expand Down Expand Up @@ -526,7 +526,7 @@ static VALUE do_send_query(void *args) {
*/
static void *nogvl_read_query_result(void *ptr) {
MYSQL * client = ptr;
bool res = mysql_read_query_result(client);
my_bool res = mysql_read_query_result(client);

return (void *)(res == 0 ? Qtrue : Qfalse);
}
Expand Down Expand Up @@ -846,7 +846,7 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
const void *retval = NULL;
unsigned int intval = 0;
const char * charval = NULL;
bool boolval;
my_bool boolval;

GET_CLIENT(self);

Expand Down Expand Up @@ -1098,6 +1098,23 @@ static VALUE rb_mysql_client_ping(VALUE self) {
}
}

/* call-seq:
* client.set_server_option(value)
*
* Enables or disables an option for the connection.
* Read https://dev.mysql.com/doc/refman/5.7/en/mysql-set-server-option.html
* for more information.
*/
static VALUE rb_mysql_client_set_server_option(VALUE self, VALUE value) {
GET_CLIENT(self);

if (mysql_set_server_option(wrapper->client, NUM2INT(value)) == 0) {
return Qtrue;
} else {
return Qfalse;
}
}

/* call-seq:
* client.more_results?
*
Expand Down Expand Up @@ -1399,6 +1416,7 @@ void init_mysql2_client() {
rb_define_method(cMysql2Client, "thread_id", rb_mysql_client_thread_id, 0);
rb_define_method(cMysql2Client, "ping", rb_mysql_client_ping, 0);
rb_define_method(cMysql2Client, "select_db", rb_mysql_client_select_db, 1);
rb_define_method(cMysql2Client, "set_server_option", rb_mysql_client_set_server_option, 1);
rb_define_method(cMysql2Client, "more_results?", rb_mysql_client_more_results, 0);
rb_define_method(cMysql2Client, "next_result", rb_mysql_client_next_result, 0);
rb_define_method(cMysql2Client, "store_result", rb_mysql_client_store_result, 0);
Expand Down Expand Up @@ -1528,6 +1546,16 @@ void init_mysql2_client() {
rb_const_set(cMysql2Client, rb_intern("SECURE_CONNECTION"), LONG2NUM(0));
#endif

#ifdef HAVE_CONST_MYSQL_OPTION_MULTI_STATEMENTS_ON
rb_const_set(cMysql2Client, rb_intern("OPTION_MULTI_STATEMENTS_ON"),
LONG2NUM(MYSQL_OPTION_MULTI_STATEMENTS_ON));
#endif

#ifdef HAVE_CONST_MYSQL_OPTION_MULTI_STATEMENTS_OFF
rb_const_set(cMysql2Client, rb_intern("OPTION_MULTI_STATEMENTS_OFF"),
LONG2NUM(MYSQL_OPTION_MULTI_STATEMENTS_OFF));
#endif

#ifdef CLIENT_MULTI_STATEMENTS
rb_const_set(cMysql2Client, rb_intern("MULTI_STATEMENTS"),
LONG2NUM(CLIENT_MULTI_STATEMENTS));
Expand Down Expand Up @@ -1558,6 +1586,16 @@ void init_mysql2_client() {
LONG2NUM(CLIENT_BASIC_FLAGS));
#endif

#ifdef CLIENT_CONNECT_ATTRS
rb_const_set(cMysql2Client, rb_intern("CONNECT_ATTRS"),
LONG2NUM(CLIENT_CONNECT_ATTRS));
#else
/* HACK because MySQL 5.5 and earlier don't define this constant,
* but we're using it in our default connection flags. */
rb_const_set(cMysql2Client, rb_intern("CONNECT_ATTRS"),
INT2NUM(0));
#endif

#if defined(FULL_SSL_MODE_SUPPORT) // MySQL 5.7.11 and above
rb_const_set(cMysql2Client, rb_intern("SSL_MODE_DISABLED"), INT2NUM(SSL_MODE_DISABLED));
rb_const_set(cMysql2Client, rb_intern("SSL_MODE_PREFERRED"), INT2NUM(SSL_MODE_PREFERRED));
Expand Down
15 changes: 14 additions & 1 deletion ext/mysql2/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ 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
# Ruby versions below 2.0 on Unix and below 2.1 on Windows
# do not properly search for lib directories, and must be corrected:
# https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717
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 Expand Up @@ -98,12 +105,18 @@ def add_ssl_defines(header)
add_ssl_defines(mysql_h)
have_struct_member('MYSQL', 'net.vio', mysql_h)
have_struct_member('MYSQL', 'net.pvio', mysql_h)

# These constants are actually enums, so they cannot be detected by #ifdef in C code.
have_const('MYSQL_ENABLE_CLEARTEXT_PLUGIN', mysql_h)
have_const('SERVER_QUERY_NO_GOOD_INDEX_USED', mysql_h)
have_const('SERVER_QUERY_NO_INDEX_USED', mysql_h)
have_const('SERVER_QUERY_WAS_SLOW', mysql_h)
have_const('MYSQL_OPT_CONNECT_ATTR_ADD', mysql_h) # for mysql_options4
have_const('MYSQL_OPTION_MULTI_STATEMENTS_ON', mysql_h)
have_const('MYSQL_OPTION_MULTI_STATEMENTS_OFF', mysql_h)

# my_bool is replaced by C99 bool in MySQL 8.0, but we want
# to retain compatibility with the typedef in earlier MySQLs.
have_type('my_bool', mysql_h)

# This is our wishlist. We use whichever flags work on the host.
# -Wall and -Wextra are included by default.
Expand Down
8 changes: 8 additions & 0 deletions ext/mysql2/mysql2_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ void Init_mysql2(void);
#define RB_MYSQL_UNUSED
#endif

/* MySQL 8.0 replaces my_bool with C99 bool. Earlier versions of MySQL had
* a typedef to char. Gem users reported failures on big endian systems when
* using C99 bool types with older MySQLs due to mismatched behavior. */
#ifndef HAVE_TYPE_MY_BOOL
#include <stdbool.h>
typedef bool my_bool;
#endif

#include <client.h>
#include <statement.h>
#include <result.h>
Expand Down
Loading

0 comments on commit a6de4a6

Please sign in to comment.