epgsql_cmd_sync.erl 649 B

123456789101112131415161718192021222324252627
  1. %% > Sync
  2. %% < ReadyForQuery
  3. -module(epgsql_cmd_sync).
  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. init(_) ->
  11. undefined.
  12. execute(Sock, St) ->
  13. epgsql_sock:send(Sock, ?SYNC, []),
  14. Sock1 = epgsql_sock:set_attr(sync_required, false, Sock),
  15. {ok, Sock1, St}.
  16. handle_message(?READY_FOR_QUERY, _, Sock, _State) ->
  17. {finish, ok, ok, Sock};
  18. handle_message(?ERROR, Error, _Sock, _State) ->
  19. {sync_required, {error, Error}};
  20. handle_message(_, _, _, _) ->
  21. unknown.