Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Commit

Permalink
Fix: FLOAT column becomes INT after being selected out.
Browse files Browse the repository at this point in the history
fix:#6
closed:#6
  • Loading branch information
qingchuwudi committed Nov 3, 2017
1 parent ebb96c0 commit 5806edf
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/emysql_tcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,19 @@ cast_fun_for(Type) ->
identity(Data) -> Data.
to_integer(Data) -> list_to_integer(binary_to_list(Data)).
to_float(Data) ->
{ok, [Num], _Leftovers} = case io_lib:fread("~f", binary_to_list(Data)) of
% note: does not need conversion
{ok, [Num], _Leftovers} =
case io_lib:fread("~f", binary_to_list(Data)) of % note: does not need conversion
{error, _} ->
case io_lib:fread("~d", binary_to_list(Data)) of % note: does not need conversion
{ok, [_], []} = Res ->
Res;
{ok, [X], E} ->
io_lib:fread("~f", lists:flatten(io_lib:format("~w~s~s" ,[X,".0",E])))
end
;
case io_lib:fread("~d", binary_to_list(Data)) of % note: does not need conversion
{ok, [_], []} = Res ->
Res;
{ok, [X], E} ->
io_lib:fread("~f", lists:flatten(io_lib:format("~w~s~s" ,[X,".0",E])))
end;
Res ->
Res
end,
Num.
erlang:float(Num).
to_date(Data) ->
case io_lib:fread("~d-~d-~d", binary_to_list(Data)) of % note: does not need conversion
{ok, [Year, Month, Day], _} ->
Expand Down

0 comments on commit 5806edf

Please sign in to comment.