Closed benkimpel closed 4 months ago
I imagine this isn't a bigger problem because it doesn't seem to effect prepared statements and it seems like that is mostly (exclusively?) what Ecto does.
I imagine this isn't a bigger problem because it doesn't seem to effect prepared statements and it seems like that is mostly (exclusively?) what Ecto does.
That's correct.
def decode_text_value(value, type) when type in [:float, :double] do
value = if String.contains(value, "."), do: value, else: "#{value}.0"
String.to_float(value)
end
Maybe Float.parse
instead...it seems to take care of it automatically https://hexdocs.pm/elixir/1.11.0/Float.html#parse/1
Maybe
Float.parse
instead...it seems to take care of it automatically https://hexdocs.pm/elixir/1.11.0/Float.html#parse/1
Yeah, Float.parse
could work. I'm not sure how you'd prefer to handle errors in these functions so that would definitely be a factor in the fix.
case Float.parse(value) do
{value, _rest} -> value
:error -> ?
end
I think raising so it matches the old behaviour. But we can put a better message. Something that says we are trying to decode this value into a float and it's not a float.
We should also probably raise when rest is not empty string. That would be more in line with the old behaviour. i.e. String.to_float("123.xtz") raises
I think raising so it matches the old behaviour. But we can put a better message. Something that says we are trying to decode this value into a float and it's not a float.
We should also probably raise when rest is not empty string. That would be more in line with the old behaviour. i.e. String.to_float("123.xtz") raises
I like that. We can raise an ArgumentError
(what it previously raised) with a better message.
case Float.parse(value) do
{value, ""} -> value
_ -> raise ArgumentError, "cannot parse FLOAT/DOUBLE"
end
perfect !
Here's a PR if you're interested #181.
Thanks for the quick response.
Can't decode FLOAT/DOUBLE in TextQuery when the fractional portion of the number is 0.
SQL Setup
Query Code
Test Case
Here's a test case that reproduces the issue:
Potential Fix
I can open a pull request if you want.