epgsql_cmd_describe_portal.erl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. %% > Describe
  2. %% < RowDescription | NoData
  3. -module(epgsql_cmd_describe_portal).
  4. -behaviour(epgsql_command).
  5. -export([init/1, execute/2, handle_message/4]).
  6. -export_type([response/0]).
  7. -include("epgsql.hrl").
  8. -include("protocol.hrl").
  9. -type response() :: {ok, [epgsql:column()]} | {error, epgsql:query_error()}.
  10. -record(desc_portal,
  11. {name :: iodata(),
  12. parameter_descr}).
  13. init(Name) ->
  14. #desc_portal{name = Name}.
  15. execute(Sock, #desc_portal{name = Name} = St) ->
  16. epgsql_sock:send_multi(
  17. Sock,
  18. [
  19. {?DESCRIBE, [?PORTAL, Name, 0]},
  20. {?FLUSH, []}
  21. ]),
  22. {ok, Sock, St}.
  23. handle_message(?ROW_DESCRIPTION, <<Count:?int16, Bin/binary>>, Sock, St) ->
  24. Codec = epgsql_sock:get_codec(Sock),
  25. Columns = epgsql_wire:decode_columns(Count, Bin, Codec),
  26. {finish, {ok, Columns}, {columns, Columns}, St};
  27. handle_message(?NO_DATA, <<>>, _Sock, _State) ->
  28. {finish, {ok, []}, no_data};
  29. handle_message(?ERROR, Error, _Sock, _State) ->
  30. Result = {error, Error},
  31. {sync_required, Result};
  32. handle_message(_, _, _, _) ->
  33. unknown.