Skip to content

Commit e42621e

Browse files
authored
Merge pull request #1197 from joto/fix-update-table-without-geom
Fix in flex output: Updating tables without geometry should work
2 parents 835728d + ed4b57c commit e42621e

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

src/output-flex.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,18 @@ void output_flex_t::delete_from_table(table_connection_t *table_connection,
11151115
{
11161116
assert(table_connection);
11171117
auto const id = table_connection->table().map_id(type, osm_id);
1118-
auto const result = table_connection->get_geom_by_id(type, id);
1119-
if (m_expire.from_result(result, id) != 0) {
1120-
table_connection->delete_rows_with(type, id);
1118+
1119+
if (table_connection->table().has_geom_column()) {
1120+
auto const result = table_connection->get_geom_by_id(type, id);
1121+
1122+
if (result.num_tuples() == 0) {
1123+
return;
1124+
}
1125+
1126+
m_expire.from_result(result, id);
11211127
}
1128+
1129+
table_connection->delete_rows_with(type, id);
11221130
}
11231131

11241132
void output_flex_t::delete_from_tables(osmium::item_type type, osmid_t osm_id)

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ if (HAVE_LUA)
7878
set_test(test-output-flex-extra)
7979
set_test(test-output-flex-invalid-geom)
8080
set_test(test-output-flex-lua-fail)
81+
set_test(test-output-flex-nogeom)
8182
set_test(test-output-flex-uni)
8283
set_test(test-output-flex-tablespace LABELS Tablespace)
8384
set_test(test-output-flex-types)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
local pois = osm2pgsql.define_node_table('osm2pgsql_test_pois', {
3+
{ column = 'tags', type = 'hstore' },
4+
})
5+
6+
function osm2pgsql.process_node(object)
7+
pois:add_row{ tags = object.tags }
8+
end
9+

tests/test-output-flex-nogeom.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <catch.hpp>
2+
3+
#include "common-import.hpp"
4+
#include "common-options.hpp"
5+
6+
static testing::db::import_t db;
7+
8+
TEST_CASE("updating table without geometry should work")
9+
{
10+
testing::opt_t options = testing::opt_t()
11+
.slim()
12+
.flex("test_output_flex_nogeom.lua")
13+
.srs(PROJ_LATLONG);
14+
15+
REQUIRE_NOTHROW(db.run_import(options,
16+
"n10 v1 dV Tamenity=restaurant x10.0 y10.0\n"
17+
"n11 v1 dV Tamenity=post_box x10.0 y10.2\n"));
18+
19+
auto conn = db.db().connect();
20+
21+
CHECK(2 == conn.get_count("osm2pgsql_test_pois"));
22+
23+
REQUIRE_NOTHROW(db.run_import(
24+
options.append(),
25+
"n10 v2 dV Tamenity=restaurant,name=Schwanen x10.0 y10.0\n"));
26+
27+
CHECK(2 == conn.get_count("osm2pgsql_test_pois"));
28+
}
29+

0 commit comments

Comments
 (0)