Skip to content

Commit bbff9f3

Browse files
authored
Merge pull request #2097 from joto/modernize-use-string-view
Refactor: Modernize get_count and require_has_table
2 parents 5991844 + 368fbcc commit bbff9f3

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

tests/common-pg.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <cstdlib>
1515
#include <stdexcept>
1616
#include <string>
17+
#include <string_view>
1718

1819
#include "format.hpp"
1920
#include "options.hpp"
@@ -75,7 +76,8 @@ class conn_t : public pg_conn_t
7576
return res;
7677
}
7778

78-
int get_count(char const *table_name, std::string const &where = "") const
79+
int get_count(std::string_view table_name,
80+
std::string_view where = "") const
7981
{
8082
auto const query =
8183
fmt::format("SELECT count(*) FROM {} {} {}", table_name,
@@ -84,7 +86,7 @@ class conn_t : public pg_conn_t
8486
return result_as_int(query);
8587
}
8688

87-
void require_has_table(char const *table_name) const
89+
void require_has_table(std::string_view table_name) const
8890
{
8991
auto const where = fmt::format("oid = '{}'::regclass", table_name);
9092

tests/test-properties.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ TEST_CASE("Store and retrieve properties (with database)")
6767
std::string const full_table_name =
6868
(schema.empty() ? "" : schema + ".") + "osm2pgsql_properties";
6969

70-
REQUIRE(conn.get_count(full_table_name.c_str()) == 4);
71-
REQUIRE(conn.get_count(full_table_name.c_str(),
70+
REQUIRE(conn.get_count(full_table_name) == 4);
71+
REQUIRE(conn.get_count(full_table_name,
7272
"property='foo' AND value='bar'") == 1);
73-
REQUIRE(conn.get_count(full_table_name.c_str(),
73+
REQUIRE(conn.get_count(full_table_name,
7474
"property='empty' AND value=''") == 1);
75-
REQUIRE(conn.get_count(full_table_name.c_str(),
75+
REQUIRE(conn.get_count(full_table_name,
7676
"property='number' AND value='123'") == 1);
77-
REQUIRE(conn.get_count(full_table_name.c_str(),
77+
REQUIRE(conn.get_count(full_table_name,
7878
"property='decide' AND value='true'") == 1);
7979

8080
properties_t properties{db.conninfo(), schema};

0 commit comments

Comments
 (0)