From cc4800f55d720f53c187b5ebe4dbafce0d626028 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Tue, 8 Sep 2020 17:40:54 +0200 Subject: [PATCH] Support Decimal 2.x (#519) --- lib/postgrex/extensions/numeric.ex | 7 +++++-- mix.exs | 2 +- mix.lock | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/postgrex/extensions/numeric.ex b/lib/postgrex/extensions/numeric.ex index 3e9213b71..dec69f7d3 100644 --- a/lib/postgrex/extensions/numeric.ex +++ b/lib/postgrex/extensions/numeric.ex @@ -28,7 +28,8 @@ defmodule Postgrex.Extensions.Numeric do ## Helpers - def encode_numeric(%Decimal{coef: coef}) when coef in [:qNaN, :sNaN] do + # TODO: remove qNaN and sNaN when we depend on Decimal 2.0 + def encode_numeric(%Decimal{coef: coef}) when coef in [:NaN, :qNaN, :sNaN] do <<0::int16, 0::int16, 0xC000::uint16, 0::int16>> end @@ -90,8 +91,10 @@ defmodule Postgrex.Extensions.Numeric do decode_numeric(ndigits, weight, sign, scale, tail) end + @nan Decimal.new("NaN") + defp decode_numeric(0, _weight, 0xC000, _scale, "") do - Decimal.new(1, :qNaN, 0) + @nan end defp decode_numeric(_num_digits, weight, sign, scale, bin) do diff --git a/mix.exs b/mix.exs index 4367d694a..e30ae094a 100644 --- a/mix.exs +++ b/mix.exs @@ -31,7 +31,7 @@ defmodule Postgrex.Mixfile do [ {:ex_doc, "~> 0.20", only: :docs}, {:jason, "~> 1.0", optional: true}, - {:decimal, "~> 1.5"}, + {:decimal, "~> 1.5 or ~> 2.0"}, {:db_connection, "~> 2.1"}, {:connection, "~> 1.0"} ] diff --git a/mix.lock b/mix.lock index 876823dc5..18bd5441b 100644 --- a/mix.lock +++ b/mix.lock @@ -1,7 +1,7 @@ %{ "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, "db_connection": {:hex, :db_connection, "2.1.0", "122e2f62c4906bf2e49554f1e64db5030c19229aa40935f33088e7d543aa79d0", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "f398f3144db606de82ed42c2ddc69767f0607abdb796e8220de5f0fcf80f5ba4"}, - "decimal": {:hex, :decimal, "1.6.0", "bfd84d90ff966e1f5d4370bdd3943432d8f65f07d3bab48001aebd7030590dcc", [:mix], [], "hexpm", "bbd124e240e3ff40f407d50fced3736049e72a73d547f69201484d3a624ab569"}, + "decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"}, "earmark": {:hex, :earmark, "1.4.4", "4821b8d05cda507189d51f2caeef370cf1e18ca5d7dfb7d31e9cafe6688106a4", [:mix], [], "hexpm", "1f93aba7340574847c0f609da787f0d79efcab51b044bb6e242cae5aca9d264d"}, "ex_doc": {:hex, :ex_doc, "0.22.1", "9bb6d51508778193a4ea90fa16eac47f8b67934f33f8271d5e1edec2dc0eee4c", [:mix], [{:earmark, "~> 1.4.0", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "d957de1b75cb9f78d3ee17820733dc4460114d8b1e11f7ee4fd6546e69b1db60"}, "jason": {:hex, :jason, "1.1.1", "d3ccb840dfb06f2f90a6d335b536dd074db748b3e7f5b11ab61d239506585eb2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "639645cfac325e34938167b272bae0791fea3a34cf32c29525abf1d323ed4c18"},