Use ptr not ref for mutable param of add_row/array/hash() helpers

HEAD
Jochen Topf 2022-03-14 15:34:05 +01:00
parent 2247dfd41d
commit 684aff8e62
1 changed files with 29 additions and 29 deletions

View File

@ -35,47 +35,47 @@ static std::shared_ptr<db_target_descr_t> setup_table(std::string const &cols)
}
template <typename... ARGS>
void add_row(copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> const &t,
void add_row(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t,
ARGS &&... args)
{
mgr.new_line(t);
mgr.add_columns(std::forward<ARGS>(args)...);
mgr.finish_line();
mgr->new_line(t);
mgr->add_columns(std::forward<ARGS>(args)...);
mgr->finish_line();
mgr.sync();
mgr->sync();
}
template <typename T>
void add_array(copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> const &t,
void add_array(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t,
int id, std::vector<T> const &values)
{
mgr.new_line(t);
mgr.add_column(id);
mgr.new_array();
mgr->new_line(t);
mgr->add_column(id);
mgr->new_array();
for (auto const &v : values) {
mgr.add_array_elem(v);
mgr->add_array_elem(v);
}
mgr.finish_array();
mgr.finish_line();
mgr->finish_array();
mgr->finish_line();
mgr.sync();
mgr->sync();
}
static void
add_hash(copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> const &t, int id,
add_hash(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t, int id,
std::vector<std::pair<std::string, std::string>> const &values)
{
mgr.new_line(t);
mgr->new_line(t);
mgr.add_column(id);
mgr.new_hash();
mgr->add_column(id);
mgr->new_hash();
for (auto const &v : values) {
mgr.add_hash_elem(v.first, v.second);
mgr->add_hash_elem(v.first, v.second);
}
mgr.finish_hash();
mgr.finish_line();
mgr->finish_hash();
mgr->finish_line();
mgr.sync();
mgr->sync();
}
static void check_row(std::vector<std::string> const &row)
@ -114,7 +114,7 @@ TEST_CASE("copy_mgr_t")
{
auto t = setup_table("big int8, small smallint");
add_row(mgr, t, 34, 0xfff12345678ULL, -4457);
add_row(&mgr, t, 34, 0xfff12345678ULL, -4457);
check_row({"34", "17588196497016", "-4457"});
}
@ -124,25 +124,25 @@ TEST_CASE("copy_mgr_t")
SECTION("Simple strings")
{
add_row(mgr, t, -2, "foo", "l");
add_row(&mgr, t, -2, "foo", "l");
check_row({"-2", "foo", "l"});
}
SECTION("Strings with special characters")
{
add_row(mgr, t, -2, "va\tr", "meme\n");
add_row(&mgr, t, -2, "va\tr", "meme\n");
check_row({"-2", "va\tr", "meme\n"});
}
SECTION("Strings with more special characters")
{
add_row(mgr, t, -2, "\rrun", "K\\P");
add_row(&mgr, t, -2, "\rrun", "K\\P");
check_row({"-2", "\rrun", "K\\P"});
}
SECTION("Strings with space and quote")
{
add_row(mgr, t, 1, "with space", "name \"quoted\"");
add_row(&mgr, t, 1, "with space", "name \"quoted\"");
check_row({"1", "with space", "name \"quoted\""});
}
}
@ -151,7 +151,7 @@ TEST_CASE("copy_mgr_t")
{
auto t = setup_table("a int[]");
add_array<int>(mgr, t, -9000, {45, -2, 0, 56});
add_array<int>(&mgr, t, -9000, {45, -2, 0, 56});
check_row({"-9000", "{45,-2,0,56}"});
}
@ -159,7 +159,7 @@ TEST_CASE("copy_mgr_t")
{
auto t = setup_table("a text[]");
add_array<std::string>(mgr, t, 3,
add_array<std::string>(&mgr, t, 3,
{"foo", "", "with space", "with \"quote\"",
"the\t", "line\nbreak", "rr\rrr", "s\\l"});
check_row({"3", "{foo,\"\",\"with space\",\"with "
@ -186,7 +186,7 @@ TEST_CASE("copy_mgr_t")
{"key\n3", "value\n3"}, {"key\r4", "value\r4"},
{"key\\5", "value\\5"}};
add_hash(mgr, t, 42, values);
add_hash(&mgr, t, 42, values);
auto c = db.connect();