anchor.diff:  return_connection(_C, _Context) -> 
       ok.
   
  +%% @doc Apply function F with a connection as parameter. Make sure the
  +%% connection is returned after usage.
  +with_connection(F, Context) ->
  +    with_connection(F, get_connection(Context), Context).
  +
  +    with_connection(F, none, _Context) -> 
  +        F(none);
  +    with_connection(F, Connection, Context) when is_pid(Connection) -> 
  +        try
  +            F(Connection)
  +        after
  +            return_connection(Connection, Context)
  +	end.
  +
   
   assoc_row(Sql, Context) ->
       assoc_row(Sql, [], Context).
  
positive.code:     insert(atom_to_list(Table), Context);
  insert(Table, Context) ->
      assert_table_name(Table),
      C = get_connection(Context),
      try
          pgsql:equery1(C, "insert into \""++Table++"\" default values returning id")
      after
          return_connection(C, Context)
      end.
  
  
  %% @doc Insert a row, setting the fields to the props.  Unknown columns are serialized in the props column.
  
negative.code:     assoc(Sql, [], Context).
  
  assoc(Sql, Parameters, Context) ->
      F = fun(C) when C =:= none -> [];
  	   (C) ->
                  {ok, Result} = pgsql:assoc(C, Sql, Parameters),
                  Result
  	end,
      with_connection(F, Context).
  
  
  assoc_props(Sql, Context) ->
      assoc_props(Sql, [], Context).
  
  assoc_props(Sql, Parameters, Context) ->
      F = fun(C) when C =:= none -> [];
  	   (C) ->
                  {ok, Result} = pgsql:assoc(C, Sql, Parameters),
                  merge_props(Result)
  	end,
      with_connection(F, Context).
  
  
  q(Sql, Context) ->
      q(Sql, [], Context).
  
  q(Sql, Parameters, Context) ->
      F = fun(C) when C =:= none -> [];
  	   (C) ->
                  case pgsql:equery(C, Sql, Parameters) of
                      {ok, _Affected, _Cols, Rows} -> Rows;
                      {ok, _Cols, Rows} -> Rows;
                      {ok, Rows} -> Rows
                  end
  	end,
      with_connection(F, Context).
  
  q1(Sql, Context) ->
      q1(Sql, [], Context).
  
  q1(Sql, Parameters, Context) ->
      F = fun(C) when C =:= none -> undefined;
  	   (C) ->
                  case pgsql:equery1(C, Sql, Parameters) of
                      {ok, Value} -> Value;
                      {error, noresult} -> undefined
                  end
  	end,
      with_connection(F, Context).
  	
  
  q_row(Sql, Context) ->
      q_row(Sql, [], Context).
  