Skip to content

Commit d79638e

Browse files
committed
Update DATETIME casting tests for mysql 8.0
With Mysql 5, the invalid datetime was returned. However with 8.0 the returned row is `NULL`, so we can no longer detect this case and raise.
1 parent 6652da2 commit d79638e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

spec/mysql2/result_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,13 @@
410410
end
411411

412412
it "should raise an error given an invalid DATETIME" do
413-
expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
414-
raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
413+
if @client.info[:version] < "8.0"
414+
expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
415+
raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
416+
else
417+
expect(@client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").to_a.first).to \
418+
eql("bad_datetime" => nil)
419+
end
415420
end
416421

417422
context "string encoding for ENUM values" do

spec/mysql2/statement_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,13 @@ def stmt_count
482482
end
483483

484484
it "should raise an error given an invalid DATETIME" do
485-
expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
486-
raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
485+
if @client.info[:version] < "8.0"
486+
expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
487+
raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
488+
else
489+
expect(@client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").to_a.first).to \
490+
eql("bad_datetime" => nil)
491+
end
487492
end
488493

489494
context "string encoding for ENUM values" do

0 commit comments

Comments
 (0)