Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc Cleanups #918

Merged
merged 3 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ matrix:
addons:
hosts:
- mysql2gem.example.com
before_install:
# Use the system RubyGem with the system Ruby
- gem --version
- sudo gem install bundler
- bash .travis_setup.sh
fast_finish: true
allow_failures:
- rvm: ruby-head
Expand Down
5 changes: 2 additions & 3 deletions ext/mysql2/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {
// Get count of ordinary arguments, and extract hash opts/keyword arguments
c = rb_scan_args(argc, argv, "*:", NULL, &opts);

// Scratch space for string encoding exports, allocate on the stack
params_enc = alloca(sizeof(VALUE) * c);

stmt = stmt_wrapper->stmt;

bind_count = mysql_stmt_param_count(stmt);
Expand All @@ -278,6 +275,8 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {

// setup any bind variables in the query
if (bind_count > 0) {
// Scratch space for string encoding exports, allocate on the stack
params_enc = alloca(sizeof(VALUE) * c);
bind_buffers = xcalloc(bind_count, sizeof(MYSQL_BIND));
length_buffers = xcalloc(bind_count, sizeof(unsigned long));

Expand Down
100 changes: 47 additions & 53 deletions spec/mysql2/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@
end

context "#fields" do
before(:each) do
@test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1")
end
let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1") }

it "method should exist" do
expect(@test_result).to respond_to(:fields)
expect(test_result).to respond_to(:fields)
end

it "should return an array of field names in proper order" do
Expand Down Expand Up @@ -173,9 +171,7 @@
end

context "row data type mapping" do
before(:each) do
@test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
end
let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first }

it "should return nil values for NULL and strings for everything else when :cast is false" do
result = @client.query('SELECT null_test, tiny_int_test, bool_cast_test, int_test, date_test, enum_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', cast: false).first
Expand All @@ -188,23 +184,23 @@
end

it "should return nil for a NULL value" do
expect(@test_result['null_test']).to be_an_instance_of(NilClass)
expect(@test_result['null_test']).to eql(nil)
expect(test_result['null_test']).to be_an_instance_of(NilClass)
expect(test_result['null_test']).to eql(nil)
end

it "should return String for a BIT(64) value" do
expect(@test_result['bit_test']).to be_an_instance_of(String)
expect(@test_result['bit_test']).to eql("\000\000\000\000\000\000\000\005")
expect(test_result['bit_test']).to be_an_instance_of(String)
expect(test_result['bit_test']).to eql("\000\000\000\000\000\000\000\005")
end

it "should return String for a BIT(1) value" do
expect(@test_result['single_bit_test']).to be_an_instance_of(String)
expect(@test_result['single_bit_test']).to eql("\001")
expect(test_result['single_bit_test']).to be_an_instance_of(String)
expect(test_result['single_bit_test']).to eql("\001")
end

it "should return Fixnum for a TINYINT value" do
expect(num_classes).to include(@test_result['tiny_int_test'].class)
expect(@test_result['tiny_int_test']).to eql(1)
expect(num_classes).to include(test_result['tiny_int_test'].class)
expect(test_result['tiny_int_test']).to eql(1)
end

context "cast booleans for TINYINT if :cast_booleans is enabled" do
Expand Down Expand Up @@ -247,48 +243,48 @@
end

it "should return Fixnum for a SMALLINT value" do
expect(num_classes).to include(@test_result['small_int_test'].class)
expect(@test_result['small_int_test']).to eql(10)
expect(num_classes).to include(test_result['small_int_test'].class)
expect(test_result['small_int_test']).to eql(10)
end

it "should return Fixnum for a MEDIUMINT value" do
expect(num_classes).to include(@test_result['medium_int_test'].class)
expect(@test_result['medium_int_test']).to eql(10)
expect(num_classes).to include(test_result['medium_int_test'].class)
expect(test_result['medium_int_test']).to eql(10)
end

it "should return Fixnum for an INT value" do
expect(num_classes).to include(@test_result['int_test'].class)
expect(@test_result['int_test']).to eql(10)
expect(num_classes).to include(test_result['int_test'].class)
expect(test_result['int_test']).to eql(10)
end

it "should return Fixnum for a BIGINT value" do
expect(num_classes).to include(@test_result['big_int_test'].class)
expect(@test_result['big_int_test']).to eql(10)
expect(num_classes).to include(test_result['big_int_test'].class)
expect(test_result['big_int_test']).to eql(10)
end

it "should return Fixnum for a YEAR value" do
expect(num_classes).to include(@test_result['year_test'].class)
expect(@test_result['year_test']).to eql(2009)
expect(num_classes).to include(test_result['year_test'].class)
expect(test_result['year_test']).to eql(2009)
end

it "should return BigDecimal for a DECIMAL value" do
expect(@test_result['decimal_test']).to be_an_instance_of(BigDecimal)
expect(@test_result['decimal_test']).to eql(10.3)
expect(test_result['decimal_test']).to be_an_instance_of(BigDecimal)
expect(test_result['decimal_test']).to eql(10.3)
end

it "should return Float for a FLOAT value" do
expect(@test_result['float_test']).to be_an_instance_of(Float)
expect(@test_result['float_test']).to eql(10.3)
expect(test_result['float_test']).to be_an_instance_of(Float)
expect(test_result['float_test']).to eql(10.3)
end

it "should return Float for a DOUBLE value" do
expect(@test_result['double_test']).to be_an_instance_of(Float)
expect(@test_result['double_test']).to eql(10.3)
expect(test_result['double_test']).to be_an_instance_of(Float)
expect(test_result['double_test']).to eql(10.3)
end

it "should return Time for a DATETIME value when within the supported range" do
expect(@test_result['date_time_test']).to be_an_instance_of(Time)
expect(@test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
expect(test_result['date_time_test']).to be_an_instance_of(Time)
expect(test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
end

it "should return Time when timestamp is < 1901-12-13 20:45:52" do
Expand All @@ -302,23 +298,23 @@
end

it "should return Time for a TIMESTAMP value when within the supported range" do
expect(@test_result['timestamp_test']).to be_an_instance_of(Time)
expect(@test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
expect(test_result['timestamp_test']).to be_an_instance_of(Time)
expect(test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
end

it "should return Time for a TIME value" do
expect(@test_result['time_test']).to be_an_instance_of(Time)
expect(@test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2000-01-01 11:44:00')
expect(test_result['time_test']).to be_an_instance_of(Time)
expect(test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2000-01-01 11:44:00')
end

it "should return Date for a DATE value" do
expect(@test_result['date_test']).to be_an_instance_of(Date)
expect(@test_result['date_test'].strftime("%Y-%m-%d")).to eql('2010-04-04')
expect(test_result['date_test']).to be_an_instance_of(Date)
expect(test_result['date_test'].strftime("%Y-%m-%d")).to eql('2010-04-04')
end

it "should return String for an ENUM value" do
expect(@test_result['enum_test']).to be_an_instance_of(String)
expect(@test_result['enum_test']).to eql('val1')
expect(test_result['enum_test']).to be_an_instance_of(String)
expect(test_result['enum_test']).to eql('val1')
end

it "should raise an error given an invalid DATETIME" do
Expand Down Expand Up @@ -352,8 +348,8 @@
end

it "should return String for a SET value" do
expect(@test_result['set_test']).to be_an_instance_of(String)
expect(@test_result['set_test']).to eql('val1,val2')
expect(test_result['set_test']).to be_an_instance_of(String)
expect(test_result['set_test']).to eql('val1,val2')
end

context "string encoding for SET values" do
Expand Down Expand Up @@ -382,8 +378,8 @@
end

it "should return String for a BINARY value" do
expect(@test_result['binary_test']).to be_an_instance_of(String)
expect(@test_result['binary_test']).to eql("test#{"\000" * 6}")
expect(test_result['binary_test']).to be_an_instance_of(String)
expect(test_result['binary_test']).to eql("test#{"\000" * 6}")
end

context "string encoding for BINARY values" do
Expand Down Expand Up @@ -421,8 +417,8 @@
'long_text_test' => 'LONGTEXT',
}.each do |field, type|
it "should return a String for #{type}" do
expect(@test_result[field]).to be_an_instance_of(String)
expect(@test_result[field]).to eql("test")
expect(test_result[field]).to be_an_instance_of(String)
expect(test_result[field]).to eql("test")
end

context "string encoding for #{type} values" do
Expand Down Expand Up @@ -474,18 +470,16 @@
end

context "server flags" do
before(:each) do
@test_result = @client.query("SELECT * FROM mysql2_test ORDER BY null_test DESC LIMIT 1")
end
let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY null_test DESC LIMIT 1") }

it "should set a definitive value for query_was_slow" do
expect(@test_result.server_flags[:query_was_slow]).to eql(false)
expect(test_result.server_flags[:query_was_slow]).to eql(false)
end
it "should set a definitive value for no_index_used" do
expect(@test_result.server_flags[:no_index_used]).to eql(true)
expect(test_result.server_flags[:no_index_used]).to eql(true)
end
it "should set a definitive value for no_good_index_used" do
expect(@test_result.server_flags[:no_good_index_used]).to eql(false)
expect(test_result.server_flags[:no_good_index_used]).to eql(false)
end
end
end
Loading