Hello community, here is the log from the commit of package rubygem-mysql2 for openSUSE:Factory checked in at 2017-07-12 19:35:22 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-mysql2 (Old) and /work/SRC/openSUSE:Factory/.rubygem-mysql2.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-mysql2" Wed Jul 12 19:35:22 2017 rev:22 rq:507881 version:0.4.7 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-mysql2/rubygem-mysql2.changes 2017-06-08 15:01:22.428820006 +0200 +++ /work/SRC/openSUSE:Factory/.rubygem-mysql2.new/rubygem-mysql2.changes 2017-07-12 19:35:24.513412107 +0200 @@ -1,0 +2,6 @@ +Mon Jul 3 15:27:50 UTC 2017 - [email protected] + +- updated to version 0.4.7 + see installed CHANGELOG.md + +------------------------------------------------------------------- Old: ---- mysql2-0.4.6.gem New: ---- mysql2-0.4.7.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-mysql2.spec ++++++ --- /var/tmp/diff_new_pack.e93wJn/_old 2017-07-12 19:35:25.153321714 +0200 +++ /var/tmp/diff_new_pack.e93wJn/_new 2017-07-12 19:35:25.157321149 +0200 @@ -24,7 +24,7 @@ # Name: rubygem-mysql2 -Version: 0.4.6 +Version: 0.4.7 Release: 0 %define mod_name mysql2 %define mod_full_name %{mod_name}-%{version} @@ -37,7 +37,7 @@ BuildRequires: %{rubygem rdoc > 3.10} BuildRequires: ruby-macros >= 5 Url: http://github.com/brianmario/mysql2 -Source: http://rubygems.org/gems/%{mod_full_name}.gem +Source: https://rubygems.org/gems/%{mod_full_name}.gem Source1: rubygem-mysql2-rpmlintrc Source2: gem2rpm.yml Summary: A simple, fast Mysql library for Ruby, binding to libmysql ++++++ mysql2-0.4.6.gem -> mysql2-0.4.7.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 1970-01-01 01:00:00.000000000 +0100 +++ new/README.md 1970-01-01 01:00:00.000000000 +0100 @@ -112,7 +112,7 @@ ``` ruby # this takes a hash of options, almost all of which map directly # to the familiar database.yml in rails -# See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html +# See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Mysql2Adapter.html client = Mysql2::Client.new(:host => "localhost", :username => "root") ``` @@ -213,6 +213,21 @@ ) ``` +### Connecting to localhost + +The underlying MySQL client library has a special interpretation of the "localhost" default connection host name: + + 1. Attempt to connect via local socket (as specified in your distribution's my.cnf or `default_file` config file). + 2. But if the socket is not available, look up "localhost" to find an IP address... + * The file "/etc/hosts" is generally the source of truth for "localhost", and can override its value. + * Systems with IPv4 use "127.0.0.1" + * Systems with IPv6 use "::1" + * Systems with both IPv4 and IPv6 can be configured to prefer one or the other. + 3. If an address is found for "localhost", connect to it over TCP/IP. + +You can be explicit about using either a local socket or a TCP/IP connection, +and whether to use IPv4 or IPv6, by specifying a value other than "localhost" +for the `host` or `socket` connection options. ### SSL options @@ -235,47 +250,6 @@ ) ``` -### Multiple result sets - -You can also retrieve multiple result sets. For this to work you need to -connect with flags `Mysql2::Client::MULTI_STATEMENTS`. Multiple result sets can -be used with stored procedures that return more than one result set, and for -bundling several SQL statements into a single call to `client.query`. - -``` ruby -client = Mysql2::Client.new(:host => "localhost", :username => "root", :flags => Mysql2::Client::MULTI_STATEMENTS) -result = client.query('CALL sp_customer_list( 25, 10 )') -# result now contains the first result set -while client.next_result - result = client.store_result - # result now contains the next result set -end -``` - -Repeated calls to `client.next_result` will return true, false, or raise an -exception if the respective query erred. When `client.next_result` returns true, -call `client.store_result` to retrieve a result object. Exceptions are not -raised until `client.next_result` is called to find the status of the respective -query. Subsequent queries are not executed if an earlier query raised an -exception. Subsequent calls to `client.next_result` will return false. - -``` ruby -result = client.query('SELECT 1; SELECT 2; SELECT A; SELECT 3') -p result.first - -while client.next_result - result = client.store_result - p result.first -end -``` - -Yields: -``` -{"1"=>1} -{"2"=>2} -next_result: Unknown column 'A' in 'field list' (Mysql2::Error) -``` - ### Secure auth Starting wih MySQL 5.6.5, secure_auth is enabled by default on servers (it was disabled by default prior to this). @@ -332,6 +306,47 @@ Mysql2::Client.new(:init_command => "SET @@SESSION.sql_mode = 'STRICT_ALL_TABLES'") ``` +### Multiple result sets + +You can also retrieve multiple result sets. For this to work you need to +connect with flags `Mysql2::Client::MULTI_STATEMENTS`. Multiple result sets can +be used with stored procedures that return more than one result set, and for +bundling several SQL statements into a single call to `client.query`. + +``` ruby +client = Mysql2::Client.new(:host => "localhost", :username => "root", :flags => Mysql2::Client::MULTI_STATEMENTS) +result = client.query('CALL sp_customer_list( 25, 10 )') +# result now contains the first result set +while client.next_result + result = client.store_result + # result now contains the next result set +end +``` + +Repeated calls to `client.next_result` will return true, false, or raise an +exception if the respective query erred. When `client.next_result` returns true, +call `client.store_result` to retrieve a result object. Exceptions are not +raised until `client.next_result` is called to find the status of the respective +query. Subsequent queries are not executed if an earlier query raised an +exception. Subsequent calls to `client.next_result` will return false. + +``` ruby +result = client.query('SELECT 1; SELECT 2; SELECT A; SELECT 3') +p result.first + +while client.next_result + result = client.store_result + p result.first +end +``` + +Yields: +``` +{"1"=>1} +{"2"=>2} +next_result: Unknown column 'A' in 'field list' (Mysql2::Error) +``` + ## Cascading config The default config hash is at: Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ext/mysql2/client.c new/ext/mysql2/client.c --- old/ext/mysql2/client.c 1970-01-01 01:00:00.000000000 +0100 +++ new/ext/mysql2/client.c 1970-01-01 01:00:00.000000000 +0100 @@ -30,15 +30,21 @@ rb_raise(cMysql2Error, "MySQL client is not initialized"); \ } +#if defined(HAVE_MYSQL_NET_VIO) || defined(HAVE_ST_NET_VIO) + #define CONNECTED(wrapper) (wrapper->client->net.vio != NULL && wrapper->client->net.fd != -1) +#elif defined(HAVE_MYSQL_NET_PVIO) || defined(HAVE_ST_NET_PVIO) + #define CONNECTED(wrapper) (wrapper->client->net.pvio != NULL && wrapper->client->net.fd != -1) +#endif + #define REQUIRE_CONNECTED(wrapper) \ REQUIRE_INITIALIZED(wrapper) \ - if (!wrapper->connected && !wrapper->reconnect_enabled) { \ + if (!CONNECTED(wrapper) && !wrapper->reconnect_enabled) { \ rb_raise(cMysql2Error, "MySQL client is not connected"); \ } #define REQUIRE_NOT_CONNECTED(wrapper) \ REQUIRE_INITIALIZED(wrapper) \ - if (wrapper->connected) { \ + if (CONNECTED(wrapper)) { \ rb_raise(cMysql2Error, "MySQL connection is already open"); \ } @@ -107,14 +113,13 @@ return Qnil; } #ifdef HAVE_CONST_MYSQL_OPT_SSL_ENFORCE - GET_CLIENT(self); + GET_CLIENT(self); int val = NUM2INT( setting ); if (version >= 50703 && version < 50711) { if (val == SSL_MODE_DISABLED || val == SSL_MODE_REQUIRED) { bool b = ( val == SSL_MODE_REQUIRED ); int result = mysql_options( wrapper->client, MYSQL_OPT_SSL_ENFORCE, &b ); return INT2NUM(result); - } else { rb_warn( "MySQL client libraries between 5.7.3 and 5.7.10 only support SSL_MODE_DISABLED and SSL_MODE_REQUIRED" ); return Qnil; @@ -122,7 +127,7 @@ } #endif #ifdef FULL_SSL_MODE_SUPPORT - GET_CLIENT(self); + GET_CLIENT(self); int val = NUM2INT( setting ); if (val != SSL_MODE_DISABLED && val != SSL_MODE_PREFERRED && val != SSL_MODE_REQUIRED && val != SSL_MODE_VERIFY_CA && val != SSL_MODE_VERIFY_IDENTITY) { @@ -264,11 +269,10 @@ static void *nogvl_close(void *ptr) { mysql_client_wrapper *wrapper = ptr; - if (wrapper->client) { + if (!wrapper->closed) { mysql_close(wrapper->client); - xfree(wrapper->client); - wrapper->client = NULL; - wrapper->connected = 0; + wrapper->closed = 1; + wrapper->reconnect_enabled = 0; wrapper->active_thread = Qnil; } @@ -287,7 +291,7 @@ if (wrapper->refcount == 0) { #ifndef _WIN32 - if (wrapper->connected && !wrapper->automatic_close) { + if (CONNECTED(wrapper) && !wrapper->automatic_close) { /* The client is being garbage collected while connected. Prevent * mysql_close() from sending a mysql-QUIT or from calling shutdown() on * the socket by invalidating it. invalidate_fd() will drop this @@ -299,10 +303,12 @@ fprintf(stderr, "[WARN] mysql2 failed to invalidate FD safely\n"); close(wrapper->client->net.fd); } + wrapper->client->net.fd = -1; } #endif nogvl_close(wrapper); + xfree(wrapper->client); xfree(wrapper); } } @@ -317,9 +323,9 @@ wrapper->server_version = 0; wrapper->reconnect_enabled = 0; wrapper->connect_timeout = 0; - wrapper->connected = 0; /* means that a database connection is open */ wrapper->initialized = 0; /* means that that the wrapper is initialized */ wrapper->refcount = 1; + wrapper->closed = 0; wrapper->client = (MYSQL*)xmalloc(sizeof(MYSQL)); return obj; @@ -450,7 +456,6 @@ } wrapper->server_version = mysql_get_server_version(wrapper->client); - wrapper->connected = 1; return self; } @@ -465,13 +470,23 @@ static VALUE rb_mysql_client_close(VALUE self) { GET_CLIENT(self); - if (wrapper->connected) { + if (wrapper->client) { rb_thread_call_without_gvl(nogvl_close, wrapper, RUBY_UBF_IO, 0); } return Qnil; } +/* call-seq: + * client.closed? + * + * @return [Boolean] + */ +static VALUE rb_mysql_client_closed(VALUE self) { + GET_CLIENT(self); + return CONNECTED(wrapper) ? Qfalse : Qtrue; +} + /* * mysql_send_query is unlikely to block since most queries are small * enough to fit in a socket buffer, but sometimes large UPDATE and @@ -591,16 +606,16 @@ GET_CLIENT(self); wrapper->active_thread = Qnil; - wrapper->connected = 0; /* Invalidate the MySQL socket to prevent further communication. * The GC will come along later and call mysql_close to free it. */ - if (wrapper->client) { + if (CONNECTED(wrapper)) { if (invalidate_fd(wrapper->client->net.fd) == Qfalse) { fprintf(stderr, "[WARN] mysql2 failed to invalidate FD safely, closing unsafely\n"); close(wrapper->client->net.fd); } + wrapper->client->net.fd = -1; } rb_exc_raise(error); @@ -656,19 +671,21 @@ /* Check if execution terminated while result was still being read. */ if (!NIL_P(wrapper->active_thread)) { - /* Invalidate the MySQL socket to prevent further communication. */ + if (CONNECTED(wrapper)) { + /* Invalidate the MySQL socket to prevent further communication. */ #ifndef _WIN32 - if (invalidate_fd(wrapper->client->net.fd) == Qfalse) { - rb_warn("mysql2 failed to invalidate FD safely, closing unsafely\n"); - close(wrapper->client->net.fd); - } + if (invalidate_fd(wrapper->client->net.fd) == Qfalse) { + rb_warn("mysql2 failed to invalidate FD safely, closing unsafely\n"); + close(wrapper->client->net.fd); + } #else - close(wrapper->client->net.fd); + close(wrapper->client->net.fd); #endif + wrapper->client->net.fd = -1; + } /* Skip mysql client check performed before command execution. */ wrapper->client->status = MYSQL_STATUS_READY; wrapper->active_thread = Qnil; - wrapper->connected = 0; } return Qnil; @@ -886,6 +903,11 @@ retval = charval; break; + case MYSQL_ENABLE_CLEARTEXT_PLUGIN: + boolval = (value == Qfalse ? 0 : 1); + retval = &boolval; + break; + default: return Qfalse; } @@ -1075,7 +1097,7 @@ static VALUE rb_mysql_client_ping(VALUE self) { GET_CLIENT(self); - if (!wrapper->connected) { + if (!CONNECTED(wrapper)) { return Qfalse; } else { return (VALUE)rb_thread_call_without_gvl(nogvl_ping, wrapper->client, RUBY_UBF_IO, 0); @@ -1303,6 +1325,10 @@ return _mysql_client_options(self, MYSQL_INIT_COMMAND, value); } +static VALUE set_enable_cleartext_plugin(VALUE self, VALUE value) { + return _mysql_client_options(self, MYSQL_ENABLE_CLEARTEXT_PLUGIN, value); +} + static VALUE initialize_ext(VALUE self) { GET_CLIENT(self); @@ -1363,6 +1389,7 @@ rb_define_singleton_method(cMysql2Client, "info", rb_mysql_client_info, 0); rb_define_method(cMysql2Client, "close", rb_mysql_client_close, 0); + rb_define_method(cMysql2Client, "closed?", rb_mysql_client_closed, 0); rb_define_method(cMysql2Client, "abandon_results!", rb_mysql_client_abandon_results, 0); rb_define_method(cMysql2Client, "escape", rb_mysql_client_real_escape, 1); rb_define_method(cMysql2Client, "server_info", rb_mysql_client_server_info, 0); @@ -1398,6 +1425,7 @@ rb_define_private_method(cMysql2Client, "init_command=", set_init_command, 1); rb_define_private_method(cMysql2Client, "ssl_set", set_ssl_options, 5); rb_define_private_method(cMysql2Client, "ssl_mode=", rb_set_ssl_mode_option, 1); + rb_define_private_method(cMysql2Client, "enable_cleartext_plugin=", set_enable_cleartext_plugin, 1); rb_define_private_method(cMysql2Client, "initialize_ext", initialize_ext, 0); rb_define_private_method(cMysql2Client, "connect", rb_connect, 7); rb_define_private_method(cMysql2Client, "_query", rb_query, 2); @@ -1419,6 +1447,10 @@ #ifdef CLIENT_LONG_PASSWORD rb_const_set(cMysql2Client, rb_intern("LONG_PASSWORD"), LONG2NUM(CLIENT_LONG_PASSWORD)); +#else + /* HACK because MariaDB 10.2 no longer defines this constant, + * but we're using it in our default connection flags. */ + rb_const_set(cMysql2Client, rb_intern("LONG_PASSWORD"), INT2NUM(0)); #endif #ifdef CLIENT_FOUND_ROWS diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ext/mysql2/client.h new/ext/mysql2/client.h --- old/ext/mysql2/client.h 1970-01-01 01:00:00.000000000 +0100 +++ new/ext/mysql2/client.h 1970-01-01 01:00:00.000000000 +0100 @@ -44,10 +44,9 @@ unsigned int connect_timeout; int active; int automatic_close; - int connected; int initialized; int refcount; - int freed; + int closed; MYSQL *client; } mysql_client_wrapper; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ext/mysql2/extconf.rb new/ext/mysql2/extconf.rb --- old/ext/mysql2/extconf.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/ext/mysql2/extconf.rb 1970-01-01 01:00:00.000000000 +0100 @@ -105,13 +105,16 @@ asplode 'mysql.h' end -add_ssl_defines([prefix, 'mysql.h'].compact.join('/')) - %w(errmsg.h mysqld_error.h).each do |h| header = [prefix, h].compact.join '/' asplode h unless have_header header end +mysql_h = [prefix, 'mysql.h'].compact.join('/') +add_ssl_defines(mysql_h) +have_struct_member('MYSQL', 'net.vio', mysql_h) +have_struct_member('MYSQL', 'net.pvio', mysql_h) + # This is our wishlist. We use whichever flags work on the host. # -Wall and -Wextra are included by default. wishlist = [ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ext/mysql2/mysql2_ext.h new/ext/mysql2/mysql2_ext.h --- old/ext/mysql2/mysql2_ext.h 1970-01-01 01:00:00.000000000 +0100 +++ new/ext/mysql2/mysql2_ext.h 1970-01-01 01:00:00.000000000 +0100 @@ -14,11 +14,13 @@ #include <mysql_com.h> #include <errmsg.h> #include <mysqld_error.h> +#include <mysql_version.h> #else #include <mysql/mysql.h> #include <mysql/mysql_com.h> #include <mysql/errmsg.h> #include <mysql/mysqld_error.h> +#include <mysql/mysql_version.h> #endif #ifdef HAVE_RUBY_ENCODING_H diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ext/mysql2/statement.c new/ext/mysql2/statement.c --- old/ext/mysql2/statement.c 1970-01-01 01:00:00.000000000 +0100 +++ new/ext/mysql2/statement.c 1970-01-01 01:00:00.000000000 +0100 @@ -468,6 +468,7 @@ rb_encoding *default_internal_enc, *conn_enc; #endif GET_STATEMENT(self); + GET_CLIENT(stmt_wrapper->client); stmt = stmt_wrapper->stmt; #ifdef HAVE_RUBY_ENCODING_H @@ -478,12 +479,22 @@ } #endif - metadata = mysql_stmt_result_metadata(stmt); + metadata = mysql_stmt_result_metadata(stmt); + if (metadata == NULL) { + if (mysql_stmt_errno(stmt) != 0) { + // either CR_OUT_OF_MEMORY or CR_UNKNOWN_ERROR. both fatal. + wrapper->active_thread = Qnil; + rb_raise_mysql2_stmt_error(stmt_wrapper); + } + // no data and no error, so query was not a SELECT + return Qnil; + } + fields = mysql_fetch_fields(metadata); field_count = mysql_stmt_field_count(stmt); field_list = rb_ary_new2((long)field_count); - for(i = 0; i < field_count; i++) { + for (i = 0; i < field_count; i++) { VALUE rb_field; rb_field = rb_str_new(fields[i].name, fields[i].name_length); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mysql2/client.rb new/lib/mysql2/client.rb --- old/lib/mysql2/client.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mysql2/client.rb 1970-01-01 01:00:00.000000000 +0100 @@ -31,10 +31,10 @@ 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].each do |key| + [: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 + when :reconnect, :local_infile, :secure_auth, :automatic_close, :enable_cleartext_plugin send(:"#{key}=", !!opts[key]) # rubocop:disable Style/DoubleNegation when :connect_timeout, :read_timeout, :write_timeout send(:"#{key}=", Integer(opts[key])) unless opts[key].nil? @@ -66,7 +66,7 @@ if [: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 will be deprecated at some point in the future." + 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." warn "============= END WARNING FROM mysql2 =========" end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/mysql2/version.rb new/lib/mysql2/version.rb --- old/lib/mysql2/version.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/mysql2/version.rb 1970-01-01 01:00:00.000000000 +0100 @@ -1,3 +1,3 @@ module Mysql2 - VERSION = "0.4.6" + VERSION = "0.4.7" end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 1970-01-01 01:00:00.000000000 +0100 +++ new/metadata 1970-01-01 01:00:00.000000000 +0100 @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: mysql2 version: !ruby/object:Gem::Version - version: 0.4.6 + version: 0.4.7 platform: ruby authors: - Brian Lopez @@ -9,7 +9,7 @@ autorequire: bindir: bin cert_chain: [] -date: 2017-05-04 00:00:00.000000000 Z +date: 2017-07-01 00:00:00.000000000 Z dependencies: [] description: email: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/em/em_spec.rb new/spec/em/em_spec.rb --- old/spec/em/em_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/em/em_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -70,6 +70,7 @@ let(:client) { Mysql2::EM::Client.new DatabaseCredentials['root'] } let(:error) { StandardError.new('some error') } before { allow(client).to receive(:async_result).and_raise(error) } + after { client.close } it "should swallow exceptions raised in by the client" do errors = [] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/mysql2/client_spec.rb new/spec/mysql2/client_spec.rb --- old/spec/mysql2/client_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/mysql2/client_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -7,14 +7,13 @@ it "should not raise an exception for valid defaults group" do expect { - opts = DatabaseCredentials['root'].merge(:default_file => cnf_file, :default_group => "test") - @client = Mysql2::Client.new(opts) + new_client(:default_file => cnf_file, :default_group => "test") }.not_to raise_error end it "should not raise an exception without default group" do expect { - @client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:default_file => cnf_file)) + new_client(:default_file => cnf_file) }.not_to raise_error end end @@ -23,29 +22,29 @@ expect { # The odd local host IP address forces the mysql client library to # use a TCP socket rather than a domain socket. - Mysql2::Client.new DatabaseCredentials['root'].merge('host' => '127.0.0.2', 'port' => 999999) + new_client('host' => '127.0.0.2', 'port' => 999999) }.to raise_error(Mysql2::Error) end it "should raise an exception on create for invalid encodings" do expect { - Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => "fake")) + new_client(:encoding => "fake") }.to raise_error(Mysql2::Error) end it "should raise an exception on non-string encodings" do expect { - Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => :fake)) + new_client(:encoding => :fake) }.to raise_error(TypeError) end it "should not raise an exception on create for a valid encoding" do expect { - Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => "utf8")) + new_client(:encoding => "utf8") }.not_to raise_error expect { - Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => "big5")) + new_client(DatabaseCredentials['root'].merge(:encoding => "big5")) }.not_to raise_error end @@ -88,7 +87,7 @@ it "should execute init command" do options = DatabaseCredentials['root'].dup options[:init_command] = "SET @something = 'setting_value';" - client = Mysql2::Client.new(options) + client = new_client(options) result = client.query("SELECT @something;") expect(result.first['@something']).to eq('setting_value') end @@ -97,7 +96,7 @@ options = DatabaseCredentials['root'].dup options[:init_command] = "SET @something = 'setting_value';" options[:reconnect] = true - client = Mysql2::Client.new(options) + client = new_client(options) result = client.query("SELECT @something;") expect(result.first['@something']).to eq('setting_value') @@ -138,15 +137,13 @@ ssl_client = nil expect { # rubocop:disable Style/TrailingComma - ssl_client = Mysql2::Client.new( - DatabaseCredentials['root'].merge( - 'host' => 'mysql2gem.example.com', # must match the certificates - :sslkey => '/etc/mysql/client-key.pem', - :sslcert => '/etc/mysql/client-cert.pem', - :sslca => '/etc/mysql/ca-cert.pem', - :sslcipher => 'DHE-RSA-AES256-SHA', - :sslverify => true - ) + ssl_client = new_client( + 'host' => 'mysql2gem.example.com', # must match the certificates + :sslkey => '/etc/mysql/client-key.pem', + :sslcert => '/etc/mysql/client-cert.pem', + :sslca => '/etc/mysql/ca-cert.pem', + :sslcipher => 'DHE-RSA-AES256-SHA', + :sslverify => true ) # rubocop:enable Style/TrailingComma }.not_to raise_error @@ -157,8 +154,6 @@ expect(ssl_client.ssl_cipher).not_to be_empty expect(results['Ssl_cipher']).to eql(ssl_client.ssl_cipher) - - ssl_client.close end def run_gc @@ -172,10 +167,21 @@ it "should terminate connections when calling close" do expect { - Mysql2::Client.new(DatabaseCredentials['root']).close + client = Mysql2::Client.new(DatabaseCredentials['root']) + connection_id = client.thread_id + client.close + + # mysql_close sends a quit command without waiting for a response + # so give the server some time to handle the detect the closed connection + closed = false + 10.times do + closed = @client.query("SHOW PROCESSLIST").none? { |row| row['Id'] == connection_id } + break if closed + sleep(0.1) + end + expect(closed).to eq(true) }.to_not change { - @client.query("SHOW STATUS LIKE 'Aborted_%'").to_a + - @client.query("SHOW STATUS LIKE 'Threads_connected'").to_a + @client.query("SHOW STATUS LIKE 'Aborted_%'").to_a } end @@ -199,36 +205,35 @@ context "#automatic_close" do it "is enabled by default" do - client = Mysql2::Client.new(DatabaseCredentials['root']) - expect(client.automatic_close?).to be(true) + expect(new_client.automatic_close?).to be(true) end if RUBY_PLATFORM =~ /mingw|mswin/ it "cannot be disabled" do expect do - client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => false)) + client = new_client(:automatic_close => false) expect(client.automatic_close?).to be(true) end.to output(/always closed by garbage collector/).to_stderr expect do - client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => true)) + client = new_client(:automatic_close => true) expect(client.automatic_close?).to be(true) end.to_not output(/always closed by garbage collector/).to_stderr expect do - client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => true)) + client = new_client(:automatic_close => true) client.automatic_close = false expect(client.automatic_close?).to be(true) end.to output(/always closed by garbage collector/).to_stderr end else it "can be configured" do - client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => false)) + client = new_client(:automatic_close => false) expect(client.automatic_close?).to be(false) end it "can be assigned" do - client = Mysql2::Client.new(DatabaseCredentials['root']) + client = new_client client.automatic_close = false expect(client.automatic_close?).to be(false) @@ -247,21 +252,18 @@ client = Mysql2::Client.new(DatabaseCredentials['root']) client.automatic_close = false - # this empty `fork` call fixes this tests on RBX; without it, the next - # `fork` call hangs forever. WTF? - fork {} - - fork do + child = fork do client.query('SELECT 1') client = nil run_gc end - Process.wait + Process.wait(child) # this will throw an error if the underlying socket was shutdown by the # child's GC expect { client.query('SELECT 1') }.to_not raise_exception + client.close end end end @@ -271,7 +273,7 @@ @client.query "CREATE DATABASE IF NOT EXISTS `#{database}`" expect { - Mysql2::Client.new(DatabaseCredentials['root'].merge('database' => database)) + new_client('database' => database) }.not_to raise_error @client.query "DROP DATABASE IF EXISTS `#{database}`" @@ -288,6 +290,25 @@ }.to raise_error(Mysql2::Error) end + context "#closed?" do + it "should return false when connected" do + expect(@client.closed?).to eql(false) + end + + it "should return true after close" do + @client.close + expect(@client.closed?).to eql(true) + end + end + + it "should not try to query closed mysql connection" do + client = new_client(:reconnect => true) + expect(client.close).to be_nil + expect { + client.query "SELECT 1" + }.to raise_error(Mysql2::Error) + end + it "should respond to #query" do expect(@client).to respond_to(:query) end @@ -344,67 +365,72 @@ context ":local_infile" do before(:all) do - @client_i = Mysql2::Client.new DatabaseCredentials['root'].merge(:local_infile => true) - local = @client_i.query "SHOW VARIABLES LIKE 'local_infile'" - local_enabled = local.any? { |x| x['Value'] == 'ON' } - pending("DON'T WORRY, THIS TEST PASSES - but LOCAL INFILE is not enabled in your MySQL daemon.") unless local_enabled - - @client_i.query %[ - CREATE TABLE IF NOT EXISTS infileTest ( - id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, - foo VARCHAR(10), - bar MEDIUMTEXT - ) - ] + new_client(:local_infile => true) do |client| + local = client.query "SHOW VARIABLES LIKE 'local_infile'" + local_enabled = local.any? { |x| x['Value'] == 'ON' } + pending("DON'T WORRY, THIS TEST PASSES - but LOCAL INFILE is not enabled in your MySQL daemon.") unless local_enabled + + client.query %[ + CREATE TABLE IF NOT EXISTS infileTest ( + id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, + foo VARCHAR(10), + bar MEDIUMTEXT + ) + ] + end end after(:all) do - @client_i.query "DROP TABLE infileTest" + new_client do |client| + client.query "DROP TABLE infileTest" + end end it "should raise an error when local_infile is disabled" do - client = Mysql2::Client.new DatabaseCredentials['root'].merge(:local_infile => false) + client = new_client(:local_infile => false) expect { client.query "LOAD DATA LOCAL INFILE 'spec/test_data' INTO TABLE infileTest" }.to raise_error(Mysql2::Error, /command is not allowed/) end it "should raise an error when a non-existent file is loaded" do + client = new_client(:local_infile => true) expect { - @client_i.query "LOAD DATA LOCAL INFILE 'this/file/is/not/here' INTO TABLE infileTest" + client.query "LOAD DATA LOCAL INFILE 'this/file/is/not/here' INTO TABLE infileTest" }.to raise_error(Mysql2::Error, 'No such file or directory: this/file/is/not/here') end it "should LOAD DATA LOCAL INFILE" do - @client_i.query "LOAD DATA LOCAL INFILE 'spec/test_data' INTO TABLE infileTest" - info = @client_i.query_info + client = new_client(:local_infile => true) + client.query "LOAD DATA LOCAL INFILE 'spec/test_data' INTO TABLE infileTest" + info = client.query_info expect(info).to eql(:records => 1, :deleted => 0, :skipped => 0, :warnings => 0) - result = @client_i.query "SELECT * FROM infileTest" + result = client.query "SELECT * FROM infileTest" expect(result.first).to eql('id' => 1, 'foo' => 'Hello', 'bar' => 'World') end end it "should expect connect_timeout to be a positive integer" do expect { - Mysql2::Client.new(DatabaseCredentials['root'].merge(:connect_timeout => -1)) + new_client(:connect_timeout => -1) }.to raise_error(Mysql2::Error) end it "should expect read_timeout to be a positive integer" do expect { - Mysql2::Client.new(DatabaseCredentials['root'].merge(:read_timeout => -1)) + new_client(:read_timeout => -1) }.to raise_error(Mysql2::Error) end it "should expect write_timeout to be a positive integer" do expect { - Mysql2::Client.new(DatabaseCredentials['root'].merge(:write_timeout => -1)) + new_client(:write_timeout => -1) }.to raise_error(Mysql2::Error) end it "should allow nil read_timeout" do - client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:read_timeout => nil)) + client = new_client(:read_timeout => nil) expect(client.read_timeout).to be_nil end @@ -474,6 +500,25 @@ }.to raise_error(Mysql2::Error) end + it "should detect closed connection on query read error" do + connection_id = @client.thread_id + Thread.new do + sleep(0.1) + Mysql2::Client.new(DatabaseCredentials['root']).tap do |supervisor| + supervisor.query("KILL #{connection_id}") + end.close + end + expect { + @client.query("SELECT SLEEP(1)") + }.to raise_error(Mysql2::Error, /Lost connection to MySQL server/) + + if RUBY_PLATFORM !~ /mingw|mswin/ + expect { + @client.socket + }.to raise_error(Mysql2::Error, 'MySQL client is not connected') + end + end + if RUBY_PLATFORM !~ /mingw|mswin/ it "should not allow another query to be sent without fetching a result first" do @client.query("SELECT 1", :async => true) @@ -490,7 +535,7 @@ end it "should timeout if we wait longer than :read_timeout" do - client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:read_timeout => 0)) + client = new_client(:read_timeout => 0) expect { client.query('SELECT SLEEP(0.1)') }.to raise_error(Mysql2::Error) @@ -563,7 +608,7 @@ pending('libmysqlclient 5.5 on OSX is afflicted by an unknown bug that breaks this test. See #633 and #634.') end - client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:reconnect => true)) + client = new_client(:reconnect => true) expect { Timeout.timeout(0.1, ArgumentError) { client.query('SELECT SLEEP(1)') } }.to raise_error(ArgumentError) expect { client.query('SELECT 1') }.to_not raise_error @@ -574,7 +619,7 @@ pending('libmysqlclient 5.5 on OSX is afflicted by an unknown bug that breaks this test. See #633 and #634.') end - client = Mysql2::Client.new(DatabaseCredentials['root']) + client = new_client expect { Timeout.timeout(0.1, ArgumentError) { client.query('SELECT SLEEP(1)') } }.to raise_error(ArgumentError) expect { client.query('SELECT 1') }.to raise_error(Mysql2::Error) @@ -592,8 +637,9 @@ # Note that each thread opens its own database connection threads = 5.times.map do Thread.new do - client = Mysql2::Client.new(DatabaseCredentials.fetch('root')) - client.query("SELECT SLEEP(#{sleep_time})") + new_client do |client| + client.query("SELECT SLEEP(#{sleep_time})") + end Thread.current.object_id end end @@ -606,10 +652,11 @@ end it "evented async queries should be supported" do + skip("ruby 1.8 doesn't support IO.for_fd options") if RUBY_VERSION.start_with?("1.8.") # should immediately return nil expect(@client.query("SELECT sleep(0.1)", :async => true)).to eql(nil) - io_wrapper = IO.for_fd(@client.socket) + io_wrapper = IO.for_fd(@client.socket, :autoclose => false) loops = 0 loop do if IO.select([io_wrapper], nil, nil, 0.05) @@ -629,7 +676,7 @@ context "Multiple results sets" do before(:each) do - @multi_client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:flags => Mysql2::Client::MULTI_STATEMENTS)) + @multi_client = new_client(:flags => Mysql2::Client::MULTI_STATEMENTS) end it "should raise an exception when one of multiple statements fails" do @@ -707,7 +754,7 @@ it "#socket should raise as it's not supported" do expect { @client.socket - }.to raise_error(Mysql2::Error) + }.to raise_error(Mysql2::Error, /Raw access to the mysql file descriptor isn't supported on Windows/) end end @@ -786,7 +833,7 @@ context 'when mysql encoding is not utf8' do before { pending('Encoding is undefined') unless defined?(Encoding) } - let(:client) { Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => "ujis")) } + let(:client) { new_client(:encoding => "ujis") } it 'should return a internal encoding string if Encoding.default_internal is set' do with_internal_encoding Encoding::UTF_8 do @@ -855,7 +902,7 @@ with_internal_encoding nil do expect(@client.server_info[:version].encoding).to eql(Encoding::UTF_8) - client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii')) + client2 = new_client(:encoding => 'ascii') expect(client2.server_info[:version].encoding).to eql(Encoding::ASCII) end end @@ -873,11 +920,11 @@ it "should raise a Mysql2::Error exception upon connection failure" do expect { - Mysql2::Client.new :host => "localhost", :username => 'asdfasdf8d2h', :password => 'asdfasdfw42' + new_client(:host => "localhost", :username => 'asdfasdf8d2h', :password => 'asdfasdfw42') }.to raise_error(Mysql2::Error) expect { - Mysql2::Client.new DatabaseCredentials['root'] + new_client(DatabaseCredentials['root']) }.not_to raise_error end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/mysql2/error_spec.rb new/spec/mysql2/error_spec.rb --- old/spec/mysql2/error_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/mysql2/error_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -3,11 +3,9 @@ require 'spec_helper' RSpec.describe Mysql2::Error do - let(:client) { Mysql2::Client.new(DatabaseCredentials['root']) } - let(:error) do begin - client.query("HAHAHA") + @client.query("HAHAHA") rescue Mysql2::Error => e error = e end @@ -28,7 +26,7 @@ let(:valid_utf8) { '造字' } let(:error) do begin - client.query(valid_utf8) + @client.query(valid_utf8) rescue Mysql2::Error => e e end @@ -37,7 +35,7 @@ let(:invalid_utf8) { ["e5c67d1f"].pack('H*').force_encoding(Encoding::UTF_8) } let(:bad_err) do begin - client.query(invalid_utf8) + @client.query(invalid_utf8) rescue Mysql2::Error => e e end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/mysql2/result_spec.rb new/spec/mysql2/result_spec.rb --- old/spec/mysql2/result_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/mysql2/result_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -153,18 +153,16 @@ end it "should raise an exception if streaming ended due to a timeout" do - # Create an extra client instance, since we're going to time it out - client = Mysql2::Client.new DatabaseCredentials['root'] - client.query "CREATE TEMPORARY TABLE streamingTest (val BINARY(255)) ENGINE=MEMORY" + @client.query "CREATE TEMPORARY TABLE streamingTest (val BINARY(255)) ENGINE=MEMORY" # Insert enough records to force the result set into multiple reads # (the BINARY type is used simply because it forces full width results) 10000.times do |i| - client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')" + @client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')" end - client.query "SET net_write_timeout = 1" - res = client.query "SELECT * FROM streamingTest", :stream => true, :cache_rows => false + @client.query "SET net_write_timeout = 1" + res = @client.query "SELECT * FROM streamingTest", :stream => true, :cache_rows => false expect { res.each_with_index do |_, i| @@ -367,10 +365,9 @@ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result['enum_test'].encoding).to eql(Encoding::UTF_8) - client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii')) + client2 = new_client(:encoding => 'ascii') result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result['enum_test'].encoding).to eql(Encoding::ASCII) - client2.close end end @@ -400,10 +397,9 @@ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result['set_test'].encoding).to eql(Encoding::UTF_8) - client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii')) + client2 = new_client(:encoding => 'ascii') result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result['set_test'].encoding).to eql(Encoding::ASCII) - client2.close end end @@ -494,10 +490,9 @@ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result[field].encoding).to eql(Encoding::UTF_8) - client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii')) + client2 = new_client(:encoding => 'ascii') result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result[field].encoding).to eql(Encoding::ASCII) - client2.close end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/mysql2/statement_spec.rb new/spec/mysql2/statement_spec.rb --- old/spec/mysql2/statement_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/mysql2/statement_spec.rb 1970-01-01 01:00:00.000000000 +0100 @@ -3,7 +3,7 @@ RSpec.describe Mysql2::Statement do before :each do - @client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => "utf8")) + @client = new_client(:encoding => "utf8") end def stmt_count @@ -326,18 +326,19 @@ end context "#fields" do - before(:each) do - @client.query "USE test" - @test_result = @client.prepare("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").execute - end - it "method should exist" do - expect(@test_result).to respond_to(:fields) + stmt = @client.prepare("SELECT 1") + expect(stmt).to respond_to(:fields) end it "should return an array of field names in proper order" do - result = @client.prepare("SELECT 'a', 'b', 'c'").execute - expect(result.fields).to eql(%w(a b c)) + stmt = @client.prepare("SELECT 'a', 'b', 'c'") + expect(stmt.fields).to eql(%w(a b c)) + end + + it "should return nil for statement with no result fields" do + stmt = @client.prepare("INSERT INTO mysql2_test () VALUES ()") + expect(stmt.fields).to eql(nil) end end @@ -524,10 +525,9 @@ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result['enum_test'].encoding).to eql(Encoding::UTF_8) - client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii')) + client2 = new_client(:encoding => 'ascii') result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result['enum_test'].encoding).to eql(Encoding::US_ASCII) - client2.close end end @@ -557,10 +557,9 @@ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result['set_test'].encoding).to eql(Encoding::UTF_8) - client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii')) + client2 = new_client(:encoding => 'ascii') result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result['set_test'].encoding).to eql(Encoding::US_ASCII) - client2.close end end @@ -651,10 +650,9 @@ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result[field].encoding).to eql(Encoding::UTF_8) - client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii')) + client2 = new_client(:encoding => 'ascii') result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first expect(result[field].encoding).to eql(Encoding::US_ASCII) - client2.close end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/spec_helper.rb new/spec/spec_helper.rb --- old/spec/spec_helper.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/spec_helper.rb 1970-01-01 01:00:00.000000000 +0100 @@ -23,72 +23,86 @@ $VERBOSE = old_verbose end + def new_client(option_overrides = {}) + client = Mysql2::Client.new(DatabaseCredentials['root'].merge(option_overrides)) + @clients ||= [] + @clients << client + return client unless block_given? + begin + yield client + ensure + client.close + @clients.delete(client) + end + end + config.before :each do - @client = Mysql2::Client.new DatabaseCredentials['root'] + @client = new_client end config.after :each do - @client.close + @clients.each(&:close) end config.before(:all) do - client = Mysql2::Client.new DatabaseCredentials['root'] - client.query %[ - CREATE TABLE IF NOT EXISTS mysql2_test ( - id MEDIUMINT NOT NULL AUTO_INCREMENT, - null_test VARCHAR(10), - bit_test BIT(64), - single_bit_test BIT(1), - tiny_int_test TINYINT, - bool_cast_test TINYINT(1), - small_int_test SMALLINT, - medium_int_test MEDIUMINT, - int_test INT, - big_int_test BIGINT, - float_test FLOAT(10,3), - float_zero_test FLOAT(10,3), - double_test DOUBLE(10,3), - decimal_test DECIMAL(10,3), - decimal_zero_test DECIMAL(10,3), - date_test DATE, - date_time_test DATETIME, - timestamp_test TIMESTAMP, - time_test TIME, - year_test YEAR(4), - char_test CHAR(10), - varchar_test VARCHAR(10), - binary_test BINARY(10), - varbinary_test VARBINARY(10), - tiny_blob_test TINYBLOB, - tiny_text_test TINYTEXT, - blob_test BLOB, - text_test TEXT, - medium_blob_test MEDIUMBLOB, - medium_text_test MEDIUMTEXT, - long_blob_test LONGBLOB, - long_text_test LONGTEXT, - enum_test ENUM('val1', 'val2'), - set_test SET('val1', 'val2'), - PRIMARY KEY (id) - ) - ] - client.query "DELETE FROM mysql2_test;" - client.query %[ - INSERT INTO mysql2_test ( - null_test, bit_test, single_bit_test, tiny_int_test, bool_cast_test, small_int_test, medium_int_test, int_test, big_int_test, - float_test, float_zero_test, double_test, decimal_test, decimal_zero_test, date_test, date_time_test, timestamp_test, time_test, - year_test, char_test, varchar_test, binary_test, varbinary_test, tiny_blob_test, - tiny_text_test, blob_test, text_test, medium_blob_test, medium_text_test, - long_blob_test, long_text_test, enum_test, set_test - ) + new_client do |client| + client.query %[ + CREATE TABLE IF NOT EXISTS mysql2_test ( + id MEDIUMINT NOT NULL AUTO_INCREMENT, + null_test VARCHAR(10), + bit_test BIT(64), + single_bit_test BIT(1), + tiny_int_test TINYINT, + bool_cast_test TINYINT(1), + small_int_test SMALLINT, + medium_int_test MEDIUMINT, + int_test INT, + big_int_test BIGINT, + float_test FLOAT(10,3), + float_zero_test FLOAT(10,3), + double_test DOUBLE(10,3), + decimal_test DECIMAL(10,3), + decimal_zero_test DECIMAL(10,3), + date_test DATE, + date_time_test DATETIME, + timestamp_test TIMESTAMP, + time_test TIME, + year_test YEAR(4), + char_test CHAR(10), + varchar_test VARCHAR(10), + binary_test BINARY(10), + varbinary_test VARBINARY(10), + tiny_blob_test TINYBLOB, + tiny_text_test TINYTEXT, + blob_test BLOB, + text_test TEXT, + medium_blob_test MEDIUMBLOB, + medium_text_test MEDIUMTEXT, + long_blob_test LONGBLOB, + long_text_test LONGTEXT, + enum_test ENUM('val1', 'val2'), + set_test SET('val1', 'val2'), + PRIMARY KEY (id) + ) + ] + client.query "DELETE FROM mysql2_test;" + client.query %[ + INSERT INTO mysql2_test ( + null_test, bit_test, single_bit_test, tiny_int_test, bool_cast_test, small_int_test, medium_int_test, int_test, big_int_test, + float_test, float_zero_test, double_test, decimal_test, decimal_zero_test, date_test, date_time_test, timestamp_test, time_test, + year_test, char_test, varchar_test, binary_test, varbinary_test, tiny_blob_test, + tiny_text_test, blob_test, text_test, medium_blob_test, medium_text_test, + long_blob_test, long_text_test, enum_test, set_test + ) - VALUES ( - NULL, b'101', b'1', 1, 1, 10, 10, 10, 10, - 10.3, 0, 10.3, 10.3, 0, '2010-4-4', '2010-4-4 11:44:00', '2010-4-4 11:44:00', '11:44:00', - 2009, "test", "test", "test", "test", "test", - "test", "test", "test", "test", "test", - "test", "test", 'val1', 'val1,val2' - ) - ] + VALUES ( + NULL, b'101', b'1', 1, 1, 10, 10, 10, 10, + 10.3, 0, 10.3, 10.3, 0, '2010-4-4', '2010-4-4 11:44:00', '2010-4-4 11:44:00', '11:44:00', + 2009, "test", "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", 'val1', 'val1,val2' + ) + ] + end end end
