Skip to content
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

Numerous fixes #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 2 additions & 5 deletions src/mysql.app.src
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{application, mysql,
[{description, "MySQL Library"},
{vsn, "34"},
{modules, [mysql,
mysql_auth,
mysql_conn,
mysql_recv]},
{vsn, "35"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib]}]}.

4 changes: 3 additions & 1 deletion src/mysql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ init([PoolId, Host, Port, User, Password, Database, LogFun, Encoding]) ->
Database, Encoding),
State = #state{log_fun = LogFun1},
{ok, add_conn(Conn, State)};
{error, Reason} ->
{error, _Reason} ->
?Log(LogFun1, error,
"failed starting first MySQL connection handler, "
"exiting"),
Expand Down Expand Up @@ -806,6 +806,8 @@ encode(Val, true) when is_binary(Val) ->
quote(Val);
encode(Val, true) ->
list_to_binary(encode(Val,false));
encode(Val, false) when is_boolean(Val) ->
atom_to_list(Val);
encode(Val, false) when is_atom(Val) ->
quote(atom_to_list(Val));
encode(Val, false) when is_list(Val) ->
Expand Down
9 changes: 6 additions & 3 deletions src/mysql_conn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,9 @@ do_execute(State, Name, Params, ExpectedVersion) ->

prepare_and_exec(State, Name, Version, Stmt, Params) ->
NameBin = atom_to_binary(Name),
StmtEscaped = binary:replace(Stmt,<<"'">>,<<"\\'">>,[global]),
StmtBin = <<"PREPARE ", NameBin/binary, " FROM '",
Stmt/binary, "'">>,
StmtEscaped/binary, "'">>,
case do_query(State, StmtBin) of
{updated, _} ->
State1 =
Expand Down Expand Up @@ -773,6 +774,9 @@ get_rows(Fields, LogFun, RecvPid, Res) ->
case do_recv(LogFun, RecvPid, undefined) of
{ok, Packet, _Num} ->
case Packet of
<<255:8, Rest/binary>> ->
<<_Code:16/little, Message/binary>> = Rest,
{error, Message};
<<254:8, Rest/binary>> when size(Rest) < 8 ->
{ok, lists:reverse(Res)};
_ ->
Expand All @@ -797,10 +801,9 @@ get_row([Field | OtherFields], Data, Res) ->
get_row(OtherFields, Rest, [This | Res]).

get_with_length(Bin) when is_binary(Bin) ->
{Length, Rest} = get_lcb(Bin),
case get_lcb(Bin) of
{null, Rest} -> {null, Rest};
_ -> split_binary(Rest, Length)
{Length, Rest} -> split_binary(Rest, Length)
end.


Expand Down