Skip to content

Commit

Permalink
Merge pull request #2097 from joto/modernize-use-string-view
Browse files Browse the repository at this point in the history
Refactor: Modernize get_count and require_has_table
  • Loading branch information
lonvia authored Oct 30, 2023
2 parents 5991844 + 368fbcc commit bbff9f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions tests/common-pg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cstdlib>
#include <stdexcept>
#include <string>
#include <string_view>

#include "format.hpp"
#include "options.hpp"
Expand Down Expand Up @@ -75,7 +76,8 @@ class conn_t : public pg_conn_t
return res;
}

int get_count(char const *table_name, std::string const &where = "") const
int get_count(std::string_view table_name,
std::string_view where = "") const
{
auto const query =
fmt::format("SELECT count(*) FROM {} {} {}", table_name,
Expand All @@ -84,7 +86,7 @@ class conn_t : public pg_conn_t
return result_as_int(query);
}

void require_has_table(char const *table_name) const
void require_has_table(std::string_view table_name) const
{
auto const where = fmt::format("oid = '{}'::regclass", table_name);

Expand Down
10 changes: 5 additions & 5 deletions tests/test-properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ TEST_CASE("Store and retrieve properties (with database)")
std::string const full_table_name =
(schema.empty() ? "" : schema + ".") + "osm2pgsql_properties";

REQUIRE(conn.get_count(full_table_name.c_str()) == 4);
REQUIRE(conn.get_count(full_table_name.c_str(),
REQUIRE(conn.get_count(full_table_name) == 4);
REQUIRE(conn.get_count(full_table_name,
"property='foo' AND value='bar'") == 1);
REQUIRE(conn.get_count(full_table_name.c_str(),
REQUIRE(conn.get_count(full_table_name,
"property='empty' AND value=''") == 1);
REQUIRE(conn.get_count(full_table_name.c_str(),
REQUIRE(conn.get_count(full_table_name,
"property='number' AND value='123'") == 1);
REQUIRE(conn.get_count(full_table_name.c_str(),
REQUIRE(conn.get_count(full_table_name,
"property='decide' AND value='true'") == 1);

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

0 comments on commit bbff9f3

Please sign in to comment.