From 5fa11ecd9fb556a051d40a46f8febed34ba22407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Wei=C3=9Fl?= Date: Mon, 20 Feb 2017 20:19:54 +0100 Subject: [PATCH] Remove stray whitespace at the end of line / file Same as: find src include test -type f -exec sed -i -e 's/\s*$//' {} \; -exec sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' {} \; --- src/mysql.app.src | 1 - src/mysql.erl | 34 +++++++++++++++++----------------- src/mysql_conn.erl | 32 ++++++++++++++++---------------- test/mysql_test.erl | 18 ++++++++---------- 4 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/mysql.app.src b/src/mysql.app.src index c8883bb..f42f634 100644 --- a/src/mysql.app.src +++ b/src/mysql.app.src @@ -7,4 +7,3 @@ mysql_recv]}, {registered, []}, {applications, [kernel, stdlib]}]}. - diff --git a/src/mysql.erl b/src/mysql.erl index d2dd510..fd7af2b 100644 --- a/src/mysql.erl +++ b/src/mysql.erl @@ -17,7 +17,7 @@ %%% provide a simpler, Mnesia-style transaction interface. Also, %%% moved much of the prepared statement handling code to mysql_conn.erl %%% and added versioning to prepared statements. -%%% +%%% %%% %%% Usage: %%% @@ -65,7 +65,7 @@ %%% ErrSqlState = mysql:get_result_err_sql_state(MysqlRes) %%% with Reason and ErrSqlState = string() %%% and ErrCode = integer() -%%% +%%% %%% If you just want a single MySQL connection, or want to manage your %%% connections yourself, you can use the mysql_conn module as a %%% stand-alone single MySQL connection. See the comment at the top of @@ -98,7 +98,7 @@ fetch/1, fetch/2, fetch/3, - + prepare/2, execute/1, execute/2, @@ -142,7 +142,7 @@ -record(conn, { pool_id, %% atom(), the pool's id - pid, %% pid(), mysql_conn process + pid, %% pid(), mysql_conn process reconnect, %% true | false, should mysql_dispatcher try %% to reconnect if this connection dies? host, %% string() @@ -156,15 +156,15 @@ -record(state, { %% gb_tree mapping connection %% pool id to a connection pool tuple - conn_pools = gb_trees:empty(), - + conn_pools = gb_trees:empty(), + %% gb_tree mapping connection Pid %% to pool id - pids_pools = gb_trees:empty(), - + pids_pools = gb_trees:empty(), + %% function for logging, - log_fun, + log_fun, %% maps names to {Statement::binary(), Version::integer()} values @@ -187,7 +187,7 @@ LogFun(?MODULE,?LINE,Level,fun()-> {Msg,[]} end)). -define(Log2(LogFun,Level,Msg,Params), LogFun(?MODULE,?LINE,Level,fun()-> {Msg,Params} end)). - + log(Module, Line, _Level, FormatFun) -> {Format, Arguments} = FormatFun(), @@ -307,7 +307,7 @@ new_conn(PoolId, ConnPid, Reconnect, Host, Port, User, Password, Database, database = Database, encoding = Encoding }; - false -> + false -> #conn{pool_id = PoolId, pid = ConnPid, reconnect = false} @@ -333,7 +333,7 @@ fetch(Query) -> fetch(PoolId, Query) -> fetch(PoolId, Query, undefined). -fetch(PoolId, Query, Timeout) -> +fetch(PoolId, Query, Timeout) -> case get(?STATE_VAR) of undefined -> call_server({fetch, PoolId, Query}, Timeout); @@ -471,7 +471,7 @@ get_result_field_info(#mysql_result{fieldinfo = FieldInfo}) -> FieldInfo. %% @doc Extract the Rows from MySQL Result on data received -%% +%% %% @spec get_result_rows(MySQLRes::mysql_result()) -> [Row::list()] get_result_rows(#mysql_result{rows=AllRows}) -> AllRows. @@ -645,7 +645,7 @@ handle_info({'DOWN', _MonitorRef, process, Pid, Info}, State) -> "received 'DOWN' signal from pid ~p not in my list", [Pid]), {noreply, State} end. - + terminate(Reason, State) -> LogFun = State#state.log_fun, LogLevel = case Reason of @@ -672,7 +672,7 @@ fetch_queries(PoolId, From, State, QueryList) -> with_next_conn(PoolId, State, Fun) -> case get_next_conn(PoolId, State) of - {ok, Conn, NewState} -> + {ok, Conn, NewState} -> Fun(Conn, NewState); error -> %% we have no active connection matching PoolId @@ -691,7 +691,7 @@ add_conn(Conn, State) -> erlang:monitor(process, Conn#conn.pid), PoolId = Conn#conn.pool_id, ConnPools = State#state.conn_pools, - NewPool = + NewPool = case gb_trees:lookup(PoolId, ConnPools) of none -> {[Conn],[]}; @@ -724,7 +724,7 @@ remove_pid_from_lists(Pid, Conns1, Conns2) -> {NewConns1, Conn} -> {Conn, {NewConns1, Conns2}} end. - + remove_conn(Pid, State) -> PidsPools = State#state.pids_pools, case gb_trees:lookup(Pid, PidsPools) of diff --git a/src/mysql_conn.erl b/src/mysql_conn.erl index a077598..02649e7 100644 --- a/src/mysql_conn.erl +++ b/src/mysql_conn.erl @@ -442,7 +442,7 @@ loop(State) -> %% GenSrvFrom is either a gen_server:call/3 From term(), %% or a pid if no gen_server was used to make the query send_reply(GenSrvFrom, Res) when is_pid(GenSrvFrom) -> - %% The query was not sent using gen_server mechanisms + %% The query was not sent using gen_server mechanisms GenSrvFrom ! {fetch_result, self(), Res}; send_reply(GenSrvFrom, Res) -> gen_server:reply(GenSrvFrom, Res). @@ -482,7 +482,7 @@ do_queries(State, Queries) -> %% Execute a list of queries, returning the response for the last query. %% If a query returns an error before the last query is executed, the -%% loop is aborted and the error is returned. +%% loop is aborted and the error is returned. do_queries(Sock, RecvPid, LogFun, Queries, Version) -> catch lists:foldl( @@ -495,7 +495,7 @@ do_queries(Sock, RecvPid, LogFun, Queries, Version) -> do_transaction(State, Fun) -> case do_query(State, <<"BEGIN">>) of - {error, _} = Err -> + {error, _} = Err -> {aborted, Err}; _ -> case catch Fun() of @@ -566,7 +566,7 @@ make_statements_for_execute(Name, Params) -> ParamNums = lists:seq(1, NumParams), NameBin = atom_to_binary(Name), - + ParamNames = lists:foldl( fun(Num, Acc) -> @@ -699,12 +699,12 @@ get_query_response(LogFun, RecvPid, Version) -> {updated, #mysql_result{affectedrows=AffectedRows, insertid=InsertId}}; 255 -> case get_error_data(Rest, Version) of - {Code, {SqlState, Message}} -> + {Code, {SqlState, Message}} -> % MYSQL_4_1 error data - {error, #mysql_result{error=Message, + {error, #mysql_result{error=Message, errcode=Code, errsqlstate=SqlState}}; - {Code, Message} -> + {Code, Message} -> % MYSQL_4_0 error data {error, #mysql_result{error=Message, errcode=Code}} @@ -717,12 +717,12 @@ get_query_response(LogFun, RecvPid, Version) -> {ok, Rows} -> {data, #mysql_result{fieldinfo=Fields, rows=Rows}}; - {error, {Code, {SqlState, Message}}} -> + {error, {Code, {SqlState, Message}}} -> % MYSQL_4_1 error data - {error, #mysql_result{error=Message, + {error, #mysql_result{error=Message, errcode=Code, errsqlstate=SqlState}}; - {error, {Code, Message}} -> + {error, {Code, Message}} -> % MYSQL_4_0 error data {error, #mysql_result{error=Message, errcode=Code}} @@ -767,7 +767,7 @@ get_fields(LogFun, RecvPid, Res, ?MYSQL_4_0) -> Field, Length, %% TODO: Check on MySQL 4.0 if types are specified - %% using the same 4.1 formalism and could + %% using the same 4.1 formalism and could %% be expanded to atoms: Type}, get_fields(LogFun, RecvPid, [This | Res], ?MYSQL_4_0) @@ -798,7 +798,7 @@ get_fields(LogFun, RecvPid, Res, ?MYSQL_4_1) -> Length:32/little, Type:8/little, _Flags:16/little, _Decimals:8/little, _Rest7/binary>> = Rest6, - + This = {Table, Field, Length, @@ -827,7 +827,7 @@ get_rows(Fields, LogFun, RecvPid, Res, Version) -> <<254:8, Rest/binary>> when size(Rest) < 8 -> {ok, lists:reverse(Res)}; <<255:8, Rest/binary>> -> - {Code, ErrData} = get_error_data(Rest, Version), + {Code, ErrData} = get_error_data(Rest, Version), {error, {Code, ErrData}}; _ -> {ok, This} = get_row(Fields, Packet, []), @@ -852,7 +852,7 @@ get_row([Field | OtherFields], Data, Res) -> get_with_length(Bin) when is_binary(Bin) -> {Length, Rest} = get_lcb(Bin), - case get_lcb(Bin) of + case get_lcb(Bin) of {null, Rest} -> {null, Rest}; _ -> split_binary(Rest, Length) end. @@ -900,7 +900,7 @@ normalize_version([$4,$.,$1|_T], _LogFun) -> ?MYSQL_4_1; normalize_version([$5|_T], _LogFun) -> %% MySQL version 5.x protocol is compliant with MySQL 4.1.x: - ?MYSQL_4_1; + ?MYSQL_4_1; normalize_version(_Other, LogFun) -> ?Log(LogFun, error, "MySQL version not supported: MySQL Erlang module " "might not work correctly."), @@ -982,7 +982,7 @@ convert_type(Val, ColType) -> _Other -> Val end. - + get_error_data(ErrPacket, ?MYSQL_4_0) -> <> = ErrPacket, {Code, binary_to_list(Message)}; diff --git a/test/mysql_test.erl b/test/mysql_test.erl index 38f9a52..4490bd8 100644 --- a/test/mysql_test.erl +++ b/test/mysql_test.erl @@ -8,7 +8,7 @@ test() -> compile:file("/usr/local/lib/erlang/lib/mysql/mysql.erl"), compile:file("/usr/local/lib/erlang/lib/mysql/mysql_conn.erl"), - + %% Start the MySQL dispatcher and create the first connection %% to the database. 'p1' is the connection pool identifier. mysql:start_link(p1, "localhost", "root", "password", "test"), @@ -18,7 +18,7 @@ test() -> true), mysql:connect(p1, "localhost", undefined, "root", "password", "test", true), - + mysql:fetch(p1, <<"DELETE FROM developer">>), mysql:fetch(p1, <<"INSERT INTO developer(name, country) VALUES " @@ -28,17 +28,17 @@ test() -> %% Execute a query (using a binary) Result1 = mysql:fetch(p1, <<"SELECT * FROM developer">>), io:format("Result1: ~p~n", [Result1]), - + %% Register a prepared statement mysql:prepare(update_developer_country, <<"UPDATE developer SET country=? where name like ?">>), - + %% Execute the prepared statement mysql:execute(p1, update_developer_country, [<<"Sweden">>, <<"%Wiger">>]), - + Result2 = mysql:fetch(p1, <<"SELECT * FROM developer">>), io:format("Result2: ~p~n", [Result2]), - + mysql:transaction( p1, fun() -> mysql:fetch(<<"INSERT INTO developer(name, country) VALUES " @@ -49,7 +49,7 @@ test() -> Result3 = mysql:fetch(p1, <<"SELECT * FROM developer">>), io:format("Result3: ~p~n", [Result3]), - + mysql:prepare(delete_all, <<"DELETE FROM developer">>), {aborted, {{error, foo}, _}} = @@ -70,7 +70,5 @@ test() -> Result5 = mysql:fetch(p1, <<"SELECT * FROM numbers WHERE name='t1'">>), {data, {mysql_result, _, [[<<"t1">>, D]], _, _, _, _, _}} = Result5, mysql:fetch(p1, <<"DELETE FROM numbers">>), - + ok. - -