Skip to content

Update DATETIME casting tests for mysql 8.0 #1221

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

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
9 changes: 7 additions & 2 deletions spec/mysql2/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

@junaruga junaruga Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seems that this part and another part on this PR to compare the MySQL client version will not work when the MySQL 10.0 is released in the future. The following way could be the solution.

if (@client.info[:version].split('.').map(&:to_i) <=> [8, 0]) < 0

The version is about MySQL not about Gem's, but the following way could be also possible technically.

if Gem::Version.new(@client.info[:version]) < Gem::Version.new("8.0")

I have not tested it by myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To best honest it's test code, so it's not like it's gonna break apps updating or anything and we can always update it when we add MySQL 10 to the CI in 4 or 5 years.

But yeah, feel free to PR the Gem::Version one.

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
Expand Down
9 changes: 7 additions & 2 deletions spec/mysql2/statement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down