Skip to content

Commit

Permalink
Raise better error messages on "zero" dates, closes #62
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Jul 4, 2019
1 parent cd3a5ba commit 425550d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/myxql/protocol/values.ex
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ defmodule MyXQL.Protocol.Values do
decode_binary_row(r, null_bitmap >>> 1, t, [v | acc])
end

defp decode_date(<<0, _r::bits>>, _null_bitmap, _t, _acc) do
raise ArgumentError, "cannot decode MySQL \"zero\" date as Date"
end

defp decode_time(
<<8, 0, 0::uint4, hour::uint1, minute::uint1, second::uint1, r::bits>>,
null_bitmap,
Expand Down Expand Up @@ -452,6 +456,14 @@ defmodule MyXQL.Protocol.Values do
decode_binary_row(r, null_bitmap >>> 1, t, [v | acc])
end

defp decode_datetime(<<0, _r::bits>>, _null_bitmap, _t, _acc, :naive_datetime) do
raise ArgumentError, "cannot decode MySQL \"zero\" date as NaiveDateTime"
end

defp decode_datetime(<<0, _r::bits>>, _null_bitmap, _t, _acc, :datetime) do
raise ArgumentError, "cannot decode MySQL \"zero\" date as DateTime"
end

defp new_datetime(:datetime, year, month, day, hour, minute, second, microsecond) do
%DateTime{
year: year,
Expand Down

0 comments on commit 425550d

Please sign in to comment.