|
29 | 29 | #include "pgsql-helper.hpp" |
30 | 30 | #include "util.hpp" |
31 | 31 |
|
32 | | -/** |
33 | | - * Iterate over the result from a pgsql query and call the func with all |
34 | | - * the ids from the first column. |
35 | | - * |
36 | | - * \param result The result to iterate over. |
37 | | - * \param func Lambda taking an osmid_t as only parameter. |
38 | | - */ |
39 | | -template <typename FUNC> |
40 | | -void for_each_id(pg_result_t const &result, FUNC &&func) |
41 | | -{ |
42 | | - for (int i = 0; i < result.num_tuples(); ++i) { |
43 | | - auto const id = osmium::string_to_object_id(result.get_value(i, 0)); |
44 | | - std::forward<FUNC>(func)(id); |
45 | | - } |
46 | | -} |
47 | | - |
48 | 32 | static std::string build_sql(options_t const &options, char const *templ) |
49 | 33 | { |
50 | 34 | std::string const using_tablespace{options.tblsslim_index.empty() |
@@ -402,30 +386,19 @@ void middle_pgsql_t::node_delete(osmid_t osm_id) |
402 | 386 | } |
403 | 387 | } |
404 | 388 |
|
405 | | -idlist_t middle_pgsql_t::get_ids(const char* stmt, osmid_t osm_id) |
406 | | -{ |
407 | | - idlist_t ids; |
408 | | - |
409 | | - auto const res = m_db_connection.exec_prepared(stmt, osm_id); |
410 | | - ids.reserve(res.num_tuples()); |
411 | | - for_each_id(res, [&ids](osmid_t id) { ids.push_back(id); }); |
412 | | - |
413 | | - return ids; |
414 | | -} |
415 | | - |
416 | 389 | idlist_t middle_pgsql_t::get_ways_by_node(osmid_t osm_id) |
417 | 390 | { |
418 | | - return get_ids("mark_ways_by_node", osm_id); |
| 391 | + return get_ids_from_db(&m_db_connection, "mark_ways_by_node", osm_id); |
419 | 392 | } |
420 | 393 |
|
421 | 394 | idlist_t middle_pgsql_t::get_rels_by_node(osmid_t osm_id) |
422 | 395 | { |
423 | | - return get_ids("mark_rels_by_node", osm_id); |
| 396 | + return get_ids_from_db(&m_db_connection, "mark_rels_by_node", osm_id); |
424 | 397 | } |
425 | 398 |
|
426 | 399 | idlist_t middle_pgsql_t::get_rels_by_way(osmid_t osm_id) |
427 | 400 | { |
428 | | - return get_ids("mark_rels_by_way", osm_id); |
| 401 | + return get_ids_from_db(&m_db_connection, "mark_rels_by_way", osm_id); |
429 | 402 | } |
430 | 403 |
|
431 | 404 | void middle_pgsql_t::way_set(osmium::Way const &way) |
@@ -486,10 +459,7 @@ middle_query_pgsql_t::rel_way_members_get(osmium::Relation const &rel, |
486 | 459 | } |
487 | 460 |
|
488 | 461 | auto const res = m_sql_conn.exec_prepared("get_way_list", id_list.get()); |
489 | | - idlist_t wayidspg; |
490 | | - for_each_id(res, [&wayidspg](osmid_t id) { |
491 | | - wayidspg.push_back(id); |
492 | | - }); |
| 462 | + idlist_t const wayidspg = get_ids_from_result(res); |
493 | 463 |
|
494 | 464 | // Match the list of ways coming from postgres in a different order |
495 | 465 | // back to the list of ways given by the caller */ |
|
0 commit comments