Skip to content
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
58 changes: 29 additions & 29 deletions src/pgsql_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,24 @@ auth({$R, <<5:?int32, Salt:4/binary>>}, State) ->
{next_state, auth, State, Timeout};

auth({$R, <<M:?int32, _/binary>>}, 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),
{stop, normal, 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};
Expand All @@ -188,9 +188,9 @@ initializing({$K, <<Pid:?int32, Key:?int32>>}, 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};
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -271,19 +271,19 @@ 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, []),
{next_state, describing, State#state{reply_to = From}, Timeout};

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, []),
Expand Down Expand Up @@ -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], <<Len:?int32, Value:Len/binary, Rest/binary>>, 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]).

Expand Down Expand Up @@ -585,9 +585,9 @@ encode_types([], Count, Acc) ->
<<Count:?int16, Acc/binary>>;

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, <<Acc/binary, Oid:?int32>>).

Expand Down
20 changes: 9 additions & 11 deletions src/pgsql_fdatetime.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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};
Expand Down
14 changes: 6 additions & 8 deletions src/pgsql_idatetime.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions src/pgsql_sock.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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, <<Code>>} = 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}]),
Expand Down Expand Up @@ -149,9 +149,9 @@ decode(<<Type:8, Len:?int32, Rest/binary>> = Bin, #state{c = C} = State) ->
decode(Tail, State);
<<Data:Len2/binary, Tail/binary>> when Type == $A ->
<<Pid:?int32, Strings/binary>> = 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);
Expand Down