anchor.diff:            Select("text[]", [<<"one">>, <<"two>">>])
         end).
   
  -text_format_test() ->
  -    with_connection(
  +text_format_test(Module) ->
  +    with_connection(
  +      Module,
         fun(C) ->
                 Select = fun(Type, V) ->
                                  V2 = list_to_binary(V),
                                  Query = "select $1::" ++ Type,
  -                               {ok, _Cols, [{V2}]} = pgsql:equery(C, Query, [V]),
  -                               {ok, _Cols, [{V2}]} = pgsql:equery(C, Query, [V2])
  +                               {ok, _Cols, [{V2}]} = Module:equery(C, Query, [V]),
  +                               {ok, _Cols, [{V2}]} = Module:equery(C, Query, [V2])
                          end,
                 Select("inet", "127.0.0.1"),
                 Select("numeric", "123456")
         end).
   
  -connect_timeout_test() ->
  -    {error, timeout} = pgsql:connect(?host, [{port, ?port}, {timeout, 0}]).
  -
  -query_timeout_test() ->
  -    with_connection(
  -      fun(C) ->
  -              {error, timeout} = pgsql:squery(C, "select pg_sleep(1)"),
  -              {error, timeout} = pgsql:equery(C, "select pg_sleep(2)"),
  -              {ok, _Cols, [{1}]} = pgsql:equery(C, "select 1")
  +connect_timeout_test(Module) ->
  +    {error, timeout} = Module:connect(?host, [{port, ?port}, {timeout, 0}]).
  +
  +query_timeout_test(Module) ->
  +    with_connection(
  +      Module,
  +      fun(C) ->
  +              {error, timeout} = Module:squery(C, "select pg_sleep(1)"),
  +              {error, timeout} = Module:equery(C, "select pg_sleep(2)"),
  +              {ok, _Cols, [{1}]} = Module:equery(C, "select 1")
         end,
         [{timeout, 10}]).
   
  -execute_timeout_test() ->
  -    with_connection(
  -      fun(C) ->
  -              {ok, S} = pgsql:parse(C, "select pg_sleep($1)"),
  -              ok = pgsql:bind(C, S, [2]),
  -              {error, timeout} = pgsql:execute(C, S, 0),
  -              ok = pgsql:bind(C, S, [0]),
  -              {ok, [{<<>>}]} = pgsql:execute(C, S, 0),
  -              ok = pgsql:close(C, S),
  -              ok = pgsql:sync(C)
  +execute_timeout_test(Module) ->
  +    with_connection(
  +      Module,
  +      fun(C) ->
  +              {ok, S} = Module:parse(C, "select pg_sleep($1)"),
  +              ok = Module:bind(C, S, [2]),
  +              {error, timeout} = Module:execute(C, S, 0),
  +              ok = Module:bind(C, S, [0]),
  +              {ok, [{<<>>}]} = Module:execute(C, S, 0),
  +              ok = Module:close(C, S),
  +              ok = Module:sync(C)
         end,
         [{timeout, 10}]).
   
  -connection_closed_test() ->
  +connection_closed_test(Module) ->
       P = self(),
       F = fun() ->
                   process_flag(trap_exit, true),
  -                {ok, C} = pgsql:connect(?host, [{port, ?port}]),
  +                {ok, C} = Module:connect(?host, [{port, ?port}]),
                   P ! {connected, C},
                   receive
                       Any -> P ! Any
  
positive.code:                         _ -> false
                      end
              end,
              ?MODULE:module_info(functions))).
  
  %% -- internal functions --
  
  connect_only(Args) ->
      TestOpts = [{port, ?port}],
      case Args of
          [User, Opts]       -> Args2 = [User, TestOpts ++ Opts];
          [User, Pass, Opts] -> Args2 = [User, Pass, TestOpts ++ Opts];
          Opts               -> Args2 = [TestOpts ++ Opts]
      end,
      {ok, C} = apply(pgsql, connect, [?host | Args2]),
      pgsql:close(C),
      flush().
  
  with_connection(F) ->
      with_connection(F, "epgsql_test", []).
  
  with_connection(F, Args) ->
      with_connection(F, "epgsql_test", Args).
  
  with_connection(F, Username, Args) ->
      Args2 = [{port, ?port}, {database, "epgsql_test_db1"} | Args],
      {ok, C} = pgsql:connect(?host, Username, Args2),
      try
          F(C)
      after
          pgsql:close(C)
      end,
      flush().
  
  with_rollback(F) ->
      with_connection(
        fun(C) ->
                try
                    pgsql:squery(C, "begin"),
                    F(C)
                    after
                        pgsql:squery(C, "rollback")
                    end
        end).
  
  with_min_version(Min, F, Args) ->
      with_connection(
        fun(C) ->
            {ok, Bin} = pgsql:get_parameter(C, <<"server_version">>),
            {ok, [{float, 1, Ver} | _], _} = erl_scan:string(binary_to_list(Bin)),
            case Ver >= Min of
                true  -> F(C);
  
negative.code:     end.
  
  
  connect_with_ssl_test(Module) ->
      lists:foreach(fun application:start/1, ?ssl_apps),
      with_connection(
        Module,
        fun(C) ->
                {ok, _Cols, [{true}]} = Module:equery(C, "select ssl_is_used()")
        end,
        "epgsql_test",
        [{ssl, true}]).
  
  connect_with_client_cert_test(Module) ->
      lists:foreach(fun application:start/1, ?ssl_apps),
      Dir = filename:join(filename:dirname(code:which(pgsql_tests)), "../test_data"),
      File = fun(Name) -> filename:join(Dir, Name) end,
  