From 31bdc778097e72e4cc6cb30c22553b471e20a2a9 Mon Sep 17 00:00:00 2001 From: Marcello Ceschia Date: Mon, 23 Sep 2013 11:49:32 +0200 Subject: [PATCH] fixes issues with exported variables from case --- src/pgsql_connection.erl | 58 ++++++++++++++++++++-------------------- src/pgsql_fdatetime.erl | 20 +++++++------- src/pgsql_idatetime.erl | 14 +++++----- src/pgsql_sock.erl | 18 ++++++------- 4 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/pgsql_connection.erl b/src/pgsql_connection.erl index 81c3c17..a238a1e 100644 --- a/src/pgsql_connection.erl +++ b/src/pgsql_connection.erl @@ -154,13 +154,13 @@ auth({$R, <<5:?int32, Salt:4/binary>>}, State) -> {next_state, auth, State, Timeout}; auth({$R, <>}, State) -> - case M of - 2 -> Method = kerberosV5; - 4 -> Method = crypt; - 6 -> Method = scm; - 7 -> Method = gss; - 8 -> Method = sspi; - _ -> Method = unknown + Method = case M of + 2 -> kerberosV5; + 4 -> crypt; + 6 -> scm; + 7 -> gss; + 8 -> sspi; + _ -> unknown end, Error = {error, {unsupported_auth_method, Method}}, gen_fsm:reply(State#state.reply_to, Error), @@ -168,10 +168,10 @@ auth({$R, <>}, State) -> %% ErrorResponse auth({error, E}, State) -> - case E#error.code of - <<"28000">> -> Why = invalid_authorization_specification; - <<"28P01">> -> Why = invalid_password; - Any -> Why = Any + Why = case E#error.code of + <<"28000">> -> invalid_authorization_specification; + <<"28P01">> -> invalid_password; + Any -> Any end, gen_fsm:reply(State#state.reply_to, {error, Why}), {stop, normal, State}; @@ -188,9 +188,9 @@ initializing({$K, <>}, State) -> %% ErrorResponse initializing({error, E}, State) -> - case E#error.code of - <<"28000">> -> Why = invalid_authorization_specification; - Any -> Why = Any + Why = case E#error.code of + <<"28000">> -> invalid_authorization_specification; + Any -> Any end, gen_fsm:reply(State#state.reply_to, {error, Why}), {stop, normal, State}; @@ -235,9 +235,9 @@ ready({equery, Statement, Parameters}, From, State) -> {reply, ok, querying, State2, Timeout}; ready({get_parameter, Name}, _From, State) -> - case lists:keysearch(Name, 1, State#state.parameters) of - {value, {Name, Value}} -> Value; - false -> Value = undefined + Value = case lists:keysearch(Name, 1, State#state.parameters) of + {value, {Name, Value1}} -> Value1; + false -> undefined end, {reply, {ok, Value}, ready, State}; @@ -271,9 +271,9 @@ ready({execute, Statement, PortalName, MaxRows}, From, State) -> ready({describe, Type, Name}, From, State) -> #state{timeout = Timeout} = State, - case Type of - statement -> Type2 = $S; - portal -> Type2 = $P + Type2 = case Type of + statement -> $S; + portal -> $P end, send(State, $D, [Type2, Name, 0]), send(State, $H, []), @@ -281,9 +281,9 @@ ready({describe, Type, Name}, From, State) -> ready({close, Type, Name}, From, State) -> #state{timeout = Timeout} = State, - case Type of - statement -> Type2 = $S; - portal -> Type2 = $P + Type2 = case Type of + statement -> $S; + portal -> $P end, send(State, $C, [Type2, Name, 0]), send(State, $H, []), @@ -537,9 +537,9 @@ decode_data([], _Bin, Acc) -> decode_data([_C | T], <<-1:?int32, Rest/binary>>, Acc) -> decode_data(T, Rest, [null | Acc]); decode_data([C | T], <>, Acc) -> - case C of - #column{type = Type, format = 1} -> Value2 = pgsql_binary:decode(Type, Value); - #column{} -> Value2 = Value + Value2 = case C of + #column{type = Type, format = 1} -> pgsql_binary:decode(Type, Value); + #column{} -> Value end, decode_data(T, Rest, [Value2 | Acc]). @@ -585,9 +585,9 @@ encode_types([], Count, Acc) -> <>; encode_types([Type | T], Count, Acc) -> - case Type of - undefined -> Oid = 0; - _Any -> Oid = pgsql_types:type2oid(Type) + Oid = case Type of + undefined -> 0; + _Any -> pgsql_types:type2oid(Type) end, encode_types(T, Count + 1, <>). diff --git a/src/pgsql_fdatetime.erl b/src/pgsql_fdatetime.erl index 7995f6c..f3fd8cd 100644 --- a/src/pgsql_fdatetime.erl +++ b/src/pgsql_fdatetime.erl @@ -35,9 +35,9 @@ j2date(N) -> Q2 = J2 div 1461, J3 = J2 - Q2 * 1461, Y = J3 * 4 div 1461, - case Y of - 0 -> J4 = ((J3 + 306) rem 366) + 123; - _ -> J4 = ((J3 + 305) rem 365) + 123 + J4 = case Y of + 0 -> ((J3 + 306) rem 366) + 123; + _ -> ((J3 + 305) rem 365) + 123 end, Year = (Y + Q2 * 4) - 4800, Q3 = J4 * 2141 div 65536, @@ -46,13 +46,11 @@ j2date(N) -> {Year, Month, Day}. date2j({Y, M, D}) -> - case M > 2 of + {Y2, M2} = case M > 2 of true -> - M2 = M + 1, - Y2 = Y + 4800; + {M + 1,Y + 4800}; false -> - M2 = M + 13, - Y2 = Y + 4799 + {M + 13,Y + 4799} end, C = Y2 div 100, J1 = Y2 * 365 - 32167, @@ -95,9 +93,9 @@ timestamp2f({Date, Time}) -> D * ?secs_per_day + time2f(Time). tmodulo(T, U) -> - case T < 0 of - true -> Q = ceiling(T / U); - false -> Q = floor(T / U) + Q = case T < 0 of + true -> ceiling(T / U); + false -> floor(T / U) end, case Q of 0 -> {T, Q}; diff --git a/src/pgsql_idatetime.erl b/src/pgsql_idatetime.erl index 58fd6d3..017ca71 100644 --- a/src/pgsql_idatetime.erl +++ b/src/pgsql_idatetime.erl @@ -39,9 +39,9 @@ j2date(N) -> Q2 = J2 div 1461, J3 = J2 - Q2 * 1461, Y = J3 * 4 div 1461, - case Y of - 0 -> J4 = ((J3 + 306) rem 366) + 123; - _ -> J4 = ((J3 + 305) rem 365) + 123 + J4 = case Y of + 0 -> ((J3 + 306) rem 366) + 123; + _ -> ((J3 + 305) rem 365) + 123 end, Year = (Y + Q2 * 4) - 4800, Q3 = J4 * 2141 div 65536, @@ -50,13 +50,11 @@ j2date(N) -> {Year, Month, Day}. date2j({Y, M, D}) -> - case M > 2 of + {Y2, M2} = case M > 2 of true -> - M2 = M + 1, - Y2 = Y + 4800; + {M + 1, Y + 4800}; false -> - M2 = M + 13, - Y2 = Y + 4799 + {M + 13, Y + 4799} end, C = Y2 div 100, J1 = Y2 * 365 - 32167, diff --git a/src/pgsql_sock.erl b/src/pgsql_sock.erl index a750396..478580f 100644 --- a/src/pgsql_sock.erl +++ b/src/pgsql_sock.erl @@ -41,9 +41,9 @@ init([C, Host, Username, Opts]) -> process_flag(trap_exit, true), Opts2 = ["user", 0, Username, 0], - case proplists:get_value(database, Opts, undefined) of - undefined -> Opts3 = Opts2; - Database -> Opts3 = [Opts2 | ["database", 0, Database, 0]] + Opts3 = case proplists:get_value(database, Opts, undefined) of + undefined -> Opts2; + Database -> [Opts2 | ["database", 0, Database, 0]] end, Port = proplists:get_value(port, Opts, 5432), @@ -56,13 +56,13 @@ init([C, Host, Username, Opts]) -> sock = S, tail = <<>>}, - case proplists:get_value(ssl, Opts) of + State2 = case proplists:get_value(ssl, Opts) of T when T == true; T == required -> ok = gen_tcp:send(S, <<8:?int32, 80877103:?int32>>), {ok, <>} = gen_tcp:recv(S, 1), - State2 = start_ssl(Code, T, Opts, State); + start_ssl(Code, T, Opts, State); _ -> - State2 = State + State end, setopts(State2, [{active, true}]), @@ -149,9 +149,9 @@ decode(<> = Bin, #state{c = C} = State) -> decode(Tail, State); <> when Type == $A -> <> = Data, - case decode_strings(Strings) of - [Channel, Payload] -> ok; - [Channel] -> Payload = <<>> + {Channel, Payload} = case decode_strings(Strings) of + [C, P] -> {C, P}; + [C] -> {C, <<>>} end, gen_fsm:send_all_state_event(C, {notification, Channel, Pid, Payload}), decode(Tail, State);