From d79638e6883acb52b6a32aed93b197f42f290256 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 26 Nov 2021 15:26:04 +0100 Subject: [PATCH] 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. --- spec/mysql2/result_spec.rb | 9 +++++++-- spec/mysql2/statement_spec.rb | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/spec/mysql2/result_spec.rb b/spec/mysql2/result_spec.rb index 47a4a6de..86752e13 100644 --- a/spec/mysql2/result_spec.rb +++ b/spec/mysql2/result_spec.rb @@ -410,8 +410,13 @@ end it "should raise an error given an invalid DATETIME" do - expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \ - raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00") + if @client.info[:version] < "8.0" + expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \ + raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00") + else + expect(@client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").to_a.first).to \ + eql("bad_datetime" => nil) + end end context "string encoding for ENUM values" do diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index 77c86b55..3c00d0ff 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -482,8 +482,13 @@ def stmt_count end it "should raise an error given an invalid DATETIME" do - expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \ - raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00") + if @client.info[:version] < "8.0" + expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \ + raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00") + else + expect(@client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").to_a.first).to \ + eql("bad_datetime" => nil) + end end context "string encoding for ENUM values" do