Skip to content
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
2 changes: 1 addition & 1 deletion .travis_mysql57.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eux
apt-get purge -qq '^mysql*' '^libmysql*'
rm -fr /etc/mysql
rm -fr /var/lib/mysql
apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
apt-key add - < support/5072E1F5.asc
add-apt-repository 'deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7'
apt-get update -qq
apt-get install -qq mysql-server libmysqlclient-dev
Expand Down
2 changes: 1 addition & 1 deletion .travis_mysql80.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eux
apt-get purge -qq '^mysql*' '^libmysql*'
rm -fr /etc/mysql
rm -fr /var/lib/mysql
apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
apt-key add - < support/5072E1F5.asc
add-apt-repository 'deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-8.0'
apt-get update -qq
apt-get install -qq mysql-server libmysqlclient-dev
Expand Down
81 changes: 56 additions & 25 deletions spec/mysql2/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,36 +208,43 @@
expect(@test_result['tiny_int_test']).to eql(1)
end

it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
@client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (1)'
id1 = @client.last_id
@client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (0)'
id2 = @client.last_id
@client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'
id3 = @client.last_id

result1 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast_booleans => true
result2 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1', :cast_booleans => true
result3 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = -1 LIMIT 1', :cast_booleans => true
expect(result1.first['bool_cast_test']).to be true
expect(result2.first['bool_cast_test']).to be false
expect(result3.first['bool_cast_test']).to be true
context "cast booleans for TINYINT if :cast_booleans is enabled" do
# rubocop:disable Style/Semicolon
let(:id1) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 1)'; @client.last_id }
let(:id2) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 0)'; @client.last_id }
let(:id3) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'; @client.last_id }
# rubocop:enable Style/Semicolon

after do
@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
end

@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
result1 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id1} LIMIT 1", :cast_booleans => true
result2 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id2} LIMIT 1", :cast_booleans => true
result3 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id3} LIMIT 1", :cast_booleans => true
expect(result1.first['bool_cast_test']).to be true
expect(result2.first['bool_cast_test']).to be false
expect(result3.first['bool_cast_test']).to be true
end
end

it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
@client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'
id1 = @client.last_id
@client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'
id2 = @client.last_id
context "cast booleans for BIT(1) if :cast_booleans is enabled" do
# rubocop:disable Style/Semicolon
let(:id1) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'; @client.last_id }
let(:id2) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'; @client.last_id }
# rubocop:enable Style/Semicolon

result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", :cast_booleans => true
result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", :cast_booleans => true
expect(result1.first['single_bit_test']).to be true
expect(result2.first['single_bit_test']).to be false
after do
@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
end

@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", :cast_booleans => true
result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", :cast_booleans => true
expect(result1.first['single_bit_test']).to be true
expect(result2.first['single_bit_test']).to be false
end
end

it "should return Fixnum for a SMALLINT value" do
Expand Down Expand Up @@ -285,6 +292,30 @@
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 values with microseconds" do
now = Time.now
if RUBY_VERSION =~ /1.8/ || @client.server_info[:id] / 100 < 506
result = @client.query("SELECT CAST('#{now.strftime('%F %T %z')}' AS DATETIME) AS a")
expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z'))
else
result = @client.query("SELECT CAST('#{now.strftime('%F %T.%6N %z')}' AS DATETIME(6)) AS a")
# microseconds is 6 digits after the decimal, but only test on 5 significant figures
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
end
end

it "should return DateTime values with microseconds" do
now = DateTime.now
if RUBY_VERSION =~ /1.8/ || @client.server_info[:id] / 100 < 506
result = @client.query("SELECT CAST('#{now.strftime('%F %T %z')}' AS DATETIME) AS a")
expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z'))
else
result = @client.query("SELECT CAST('#{now.strftime('%F %T.%6N %z')}' AS DATETIME(6)) AS a")
# microseconds is 6 digits after the decimal, but only test on 5 significant figures
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
end
end

if 1.size == 4 # 32bit
klass = if RUBY_VERSION =~ /1.8/
DateTime
Expand Down
8 changes: 5 additions & 3 deletions spec/mysql2/statement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def stmt_count
if RUBY_VERSION =~ /1.8/
expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z'))
else
expect(result.first['a'].strftime('%F %T.%6N %z')).to eql(now.strftime('%F %T.%6N %z'))
# microseconds is six digits after the decimal, but only test on 5 significant figures
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
end
end

Expand All @@ -161,7 +162,8 @@ def stmt_count
if RUBY_VERSION =~ /1.8/
expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z'))
else
expect(result.first['a'].strftime('%F %T.%6N %z')).to eql(now.strftime('%F %T.%6N %z'))
# microseconds is six digits after the decimal, but only test on 5 significant figures
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
end
end

Expand Down Expand Up @@ -374,7 +376,7 @@ def stmt_count
expect(@test_result['tiny_int_test']).to eql(1)
end

context "cast booleans for TINYINY if :cast_booleans is enabled" do
context "cast booleans for TINYINT if :cast_booleans is enabled" do
# rubocop:disable Style/Semicolon
let(:client) { new_client(:cast_booleans => true) }
let(:id1) { client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 1)'; client.last_id }
Expand Down
Loading