|
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() |
@@ -404,13 +388,8 @@ void middle_pgsql_t::node_delete(osmid_t osm_id) |
404 | 388 |
|
405 | 389 | idlist_t middle_pgsql_t::get_ids(const char* stmt, osmid_t osm_id) |
406 | 390 | { |
407 | | - idlist_t ids; |
408 | | - |
409 | 391 | 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; |
| 392 | + return get_ids_from_result(res); |
414 | 393 | } |
415 | 394 |
|
416 | 395 | idlist_t middle_pgsql_t::get_ways_by_node(osmid_t osm_id) |
@@ -486,10 +465,7 @@ middle_query_pgsql_t::rel_way_members_get(osmium::Relation const &rel, |
486 | 465 | } |
487 | 466 |
|
488 | 467 | 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 | | - }); |
| 468 | + idlist_t const wayidspg = get_ids_from_result(res); |
493 | 469 |
|
494 | 470 | // Match the list of ways coming from postgres in a different order |
495 | 471 | // back to the list of ways given by the caller */ |
|
0 commit comments