anchor.diff:          {value, {_, <<"on">>}}  -> put(datetime_mod, pgsql_idatetime);
           {value, {_, <<"off">>}} -> put(datetime_mod, pgsql_fdatetime)
       end,
  -    State2 = State#state{handler = on_message,
  +    notify(State, ok),
  +    {noreply, State#state{handler = on_message,
                            txstatus = Status,
  -                         ready = true},
  -    {noreply, gen_reply(State2, {ok, self()})};
  +                         queue = queue:drop(Queue)}};
   
   initializing({error, _} = Error, State) ->
  -    {stop, normal, gen_reply(State, Error)};
  +    notify(State, Error), 
  +    {stop, normal, State};
   
   initializing(Other, State) ->
       on_message(Other, State).
  
positive.code:     put(password, Password),
      {noreply,
       State2#state{handler = auth,
                    queue = queue:in(From, Queue),
                    async = Async}};
  
  handle_call(stop, From, #state{queue = Queue} = State) ->
      %% TODO flush queue
      {stop, normal, ok, State};
  
  handle_call({parse, Name, Sql, Types}, From, State) ->
      #state{queue = Queue} = State,
      Bin = pgsql_wire:encode_types(Types),
      send(State, $P, [Name, 0, Sql, 0, Bin]),
      send(State, $D, [$S, Name, 0]),
      send(State, $H, []),
      S = #statement{name = Name},
      State2 = State#state{queue = queue:in(From, Queue)},
      {noreply, State2}.
  
  handle_cast(cancel, State = #state{backend = {Pid, Key}}) ->
      {ok, {Addr, Port}} = inet:peername(State#state.sock),
  
negative.code: start_link() ->
      gen_server:start_link(?MODULE, [], []).
  
  connect(C, From, Ref, Host, Username, Password, Opts) ->
      gen_server:cast(C, {connect, From, Ref, Host, Username, Password, Opts}).
  
  close(C) when is_pid(C) ->
      catch gen_server:cast(C, stop),
      ok.
  
  get_parameter(C, Name) ->
      gen_server:call(C, {get_parameter, to_binary(Name)}, infinity).
  
  squery(C, From, Ref, Sql) ->
      gen_server:cast(C, {squery, From, Ref, Sql}).
  
  equery(C, From, Ref, Statement, Parameters) ->
      gen_server:cast(C, {equery, From, Ref, Statement, Parameters}).
  
  parse(C, From, Ref, Name, Sql, Types) ->
      gen_server:cast(C, {parse, From, Ref, Name, Sql, Types}).
  
  bind(C, From, Ref, Statement, PortalName, Parameters) ->
      gen_server:cast(C, {bind, From, Ref, Statement, PortalName, Parameters}).
  
  execute(C, From, Ref, Statement, PortalName, MaxRows) ->
      gen_server:cast(C, {execute, From, Ref, Statement, PortalName, MaxRows}).
  
  describe(C, From, Ref, Type, Name) ->
      gen_server:cast(C, {describe, From, Ref, Type, Name}).
  
  close(C, From, Ref, Type, Name) ->
      gen_server:cast(C, {close, From, Ref, Type, Name}).
  
  sync(C, From, Ref) ->
      gen_server:cast(C, {sync, From, Ref}).
  
  cancel(S) ->
      gen_server:cast(S, cancel).
  