epgsql_cmd_close.erl 916 B

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