anchor.diff:  
   %% -- internal functions --
   
  -receive_result(C, Result) ->
  -    try receive_result(C, [], []) of
  +receive_result(C, Ref, Result) ->
  +    try receive_result(C, Ref, [], []) of
           done    -> Result;
  -        R       -> receive_result(C, R)
  +        R       -> receive_result(C, Ref, R)
       catch
           throw:E -> E
       end.
   
  -receive_results(C, Results) ->
  -    try receive_result(C, [], []) of
  +receive_results(C, Ref, Results) ->
  +    try receive_result(C, Ref, [], []) of
           done    -> lists:reverse(Results);
  -        R       -> receive_results(C, [R | Results])
  +        R       -> receive_results(C, Ref, [R | Results])
       catch
           throw:E -> E
       end.
   
  -receive_result(C, Cols, Rows) ->
  -    receive
  -        {pgsql, C, {columns, Cols2}} ->
  -            receive_result(C, Cols2, Rows);
  -        {pgsql, C, {data, Row}} ->
  -            receive_result(C, Cols, [Row | Rows]);
  -        {pgsql, C, {error, _E} = Error} ->
  -            Error;
  -        {pgsql, C, {complete, {_Type, Count}}} ->
  +receive_result(C, Ref, Cols, Rows) ->
  +    receive
  +        {Ref, {columns, Cols2}} ->
  +            receive_result(C, Ref, Cols2, Rows);
  +        {Ref, {data, Row}} ->
  +            receive_result(C, Ref, Cols, [Row | Rows]);
  +        {Ref, {error, _E} = Error} ->
  +            Error;
  +        {Ref, {complete, {_Type, Count}}} ->
               case Rows of
                   [] -> {ok, Count};
                   _L -> {ok, Count, Cols, lists:reverse(Rows)}
               end;
  -        {pgsql, C, {complete, _Type}} ->
  +        {Ref, {complete, _Type}} ->
               {ok, Cols, lists:reverse(Rows)};
  -        {pgsql, C, done} ->
  +        {Ref, done} ->
               done;
  -        {pgsql, C, timeout} ->
  +        {Ref, timeout} ->
               throw({error, timeout});
           {'EXIT', C, _Reason} ->
               throw({error, closed})
       end.
   
  -receive_extended_result(C)->
  -    receive_extended_result(C, []).
  -
  -receive_extended_result(C, Rows) ->
  -    receive
  -        {pgsql, C, {data, Row}} ->
  -            receive_extended_result(C, [Row | Rows]);
  -        {pgsql, C, {error, _E} = Error} ->
  -            Error;
  -        {pgsql, C, suspended} ->
  +receive_extended_result(C, Ref)->
  +    receive_extended_result(C, Ref, []).
  +
  +receive_extended_result(C, Ref, Rows) ->
  +    receive
  +        {Ref, {data, Row}} ->
  +            receive_extended_result(C, Ref, [Row | Rows]);
  +        {Ref, {error, _E} = Error} ->
  +            Error;
  +        {Ref, suspended} ->
               {partial, lists:reverse(Rows)};
  -        {pgsql, C, {complete, {_Type, Count}}} ->
  +        {Ref, {complete, {_Type, Count}}} ->
               case Rows of
                   [] -> {ok, Count};
                   _L -> {ok, Count, lists:reverse(Rows)}
               end;
  -        {pgsql, C, {complete, _Type}} ->
  +        {Ref, {complete, _Type}} ->
               {ok, lists:reverse(Rows)};
  -        {pgsql, C, timeout} ->
  +        {Ref, timeout} ->
               {error, timeout};
           {'EXIT', C, _Reason} ->
               {error, closed}
       end.
  +
  +receive_describe(C, Ref, Statement = #statement{}) ->
  +    receive
  +        {Ref, {types, Types}} ->
  +            receive_describe(C, Ref, Statement#statement{types = Types});
  +        {Ref, {columns, Columns}} ->
  +            Statement#statement{columns = Columns};
  +        {Ref, no_data} ->
  +            Statement#statement{columns = []};
  +        {Ref, Error = {error, _}} ->
  +            Error;
  +        {'EXIT', C, _Reason} ->
  +            {error, closed}
  +    end.
  
positive.code:     execute(C, S, "", N).
  
  execute(C, S, PortalName, N) ->
      pgsql_sock:execute(C, S, PortalName, N),
      receive_extended_result(C).
  
  %% statement/portal functions
  
  describe(C, #statement{name = Name}) ->
      pgsql_sock:describe(C, statement, Name).
  
  describe(C, Type, Name) ->
      pgsql_sock:describe(C, Type, Name).
  
negative.code: 
  equery(C, Sql, Parameters) ->
      case parse(C, Sql) of
          {ok, #statement{types = Types} = S} ->
              Typed_Parameters = lists:zip(Types, Parameters),
              Ref = pgsql_sock:equery(C, S, Typed_Parameters),
              receive_result(C, Ref, undefined);
          Error ->
              Error
      end.
  