epgsql_cmd_close.erl 951 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. %% @doc Closes statement / portal
  2. %%
  3. %% ```
  4. %% > Close
  5. %% < CloseComplete
  6. %% '''
  7. -module(epgsql_cmd_close).
  8. -behaviour(epgsql_command).
  9. -export([init/1, execute/2, handle_message/4]).
  10. -export_type([response/0]).
  11. -type response() :: ok | {error, epgsql:query_error()}.
  12. -include("epgsql.hrl").
  13. -include("protocol.hrl").
  14. -record(close,
  15. {type :: statement | portal,
  16. name :: iodata()}).
  17. init({Type, Name}) ->
  18. #close{type = Type, name = Name}.
  19. execute(Sock, #close{type = Type, name = Name} = St) ->
  20. Type2 = case Type of
  21. statement -> ?PREPARED_STATEMENT;
  22. portal -> ?PORTAL
  23. end,
  24. Packets = [
  25. {?CLOSE, [Type2, Name, 0]},
  26. {?FLUSH, []}
  27. ],
  28. {send_multi, Packets, Sock, St}.
  29. handle_message(?CLOSE_COMPLETE, <<>>, Sock, _St) ->
  30. {finish, ok, ok, Sock};
  31. handle_message(?ERROR, Error, _Sock, _State) ->
  32. {sync_required, {error, Error}};
  33. handle_message(_, _, _, _) ->
  34. unknown.