Skip to content

Commit 0e0570d

Browse files
authored
Merge pull request #1203 from joto/fix-get-wkb-unitable
Fix flex backend expire for tables with type/id columns
2 parents fcbf6c5 + 40f67ee commit 0e0570d

File tree

3 files changed

+150
-128
lines changed

3 files changed

+150
-128
lines changed

src/flex-table.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ std::string flex_table_t::build_sql_prepare_get_wkb() const
7777
{
7878
if (has_geom_column()) {
7979
if (has_multicolumn_id_index()) {
80-
return "PREPARE get_wkb(text, bigint) AS"
81-
" SELECT \"{}\" FROM {} WHERE \"{}\" = '$1' AND \"{}\" = $2"_format(
80+
return "PREPARE get_wkb(char(1), bigint) AS"
81+
" SELECT \"{}\" FROM {} WHERE \"{}\" = $1 AND \"{}\" = $2"_format(
8282
geom_column().name(), full_name(), m_columns[0].name(),
8383
m_columns[1].name());
8484
}

tests/test-output-flex-uni.cpp

Lines changed: 74 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,40 @@
55

66
static testing::db::import_t db;
77

8-
TEST_CASE("updating a node")
8+
struct options_slim_default
99
{
10+
static options_t options()
11+
{
12+
return testing::opt_t().slim().flex("test_output_flex_uni.lua");
13+
}
14+
};
15+
16+
struct options_slim_expire
17+
{
18+
static options_t options()
19+
{
20+
options_t o = options_slim_default::options();
21+
o.expire_tiles_zoom = 10;
22+
return o;
23+
}
24+
};
25+
26+
TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
27+
options_slim_expire)
28+
{
29+
options_t options = TestType::options();
30+
1031
// import a node...
11-
REQUIRE_NOTHROW(
12-
db.run_import(testing::opt_t().slim().flex("test_output_flex_uni.lua"),
13-
"n10 v1 dV x10 y10\n"));
32+
REQUIRE_NOTHROW(db.run_import(options, "n10 v1 dV x10 y10\n"));
1433

1534
auto conn = db.db().connect();
1635

1736
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type = 'N'"));
1837

1938
// give the node a tag...
20-
REQUIRE_NOTHROW(db.run_import(
21-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
22-
"n10 v2 dV x10 y10 Tamenity=restaurant\n"));
39+
options.append = true;
40+
REQUIRE_NOTHROW(
41+
db.run_import(options, "n10 v2 dV x10 y10 Tamenity=restaurant\n"));
2342

2443
REQUIRE(1 == conn.get_count("osm2pgsql_test_data", "osm_type = 'N'"));
2544
REQUIRE(1 == conn.get_count("osm2pgsql_test_data",
@@ -28,29 +47,27 @@ TEST_CASE("updating a node")
2847

2948
SECTION("remove the tag from node")
3049
{
31-
REQUIRE_NOTHROW(db.run_import(
32-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
33-
"n10 v3 dV x10 y10\n"));
50+
REQUIRE_NOTHROW(db.run_import(options, "n10 v3 dV x10 y10\n"));
3451
}
3552

3653
SECTION("delete the node")
3754
{
38-
REQUIRE_NOTHROW(db.run_import(
39-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
40-
"n10 v3 dD\n"));
55+
REQUIRE_NOTHROW(db.run_import(options, "n10 v3 dD\n"));
4156
}
4257

4358
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type = 'N'"));
4459
}
4560

46-
TEST_CASE("updating a way")
61+
TEMPLATE_TEST_CASE("updating a way", "", options_slim_default,
62+
options_slim_expire)
4763
{
64+
options_t options = TestType::options();
65+
4866
// import a simple way...
49-
REQUIRE_NOTHROW(
50-
db.run_import(testing::opt_t().slim().flex("test_output_flex_uni.lua"),
51-
"n10 v1 dV x10.0 y10.1\n"
52-
"n11 v1 dV x10.1 y10.2\n"
53-
"w20 v1 dV Thighway=primary Nn10,n11\n"));
67+
REQUIRE_NOTHROW(db.run_import(options,
68+
"n10 v1 dV x10.0 y10.1\n"
69+
"n11 v1 dV x10.1 y10.2\n"
70+
"w20 v1 dV Thighway=primary Nn10,n11\n"));
5471

5572
auto conn = db.db().connect();
5673

@@ -64,9 +81,9 @@ TEST_CASE("updating a way")
6481
"AND ST_NumPoints(geom) = 2"));
6582

6683
// now change the way itself...
67-
REQUIRE_NOTHROW(db.run_import(
68-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
69-
"w20 v2 dV Thighway=secondary Nn10,n11\n"));
84+
options.append = true;
85+
REQUIRE_NOTHROW(
86+
db.run_import(options, "w20 v2 dV Thighway=secondary Nn10,n11\n"));
7087

7188
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type = 'N'"));
7289
REQUIRE(1 == conn.get_count("osm2pgsql_test_data", "osm_type = 'W'"));
@@ -76,9 +93,7 @@ TEST_CASE("updating a way")
7693
"'secondary' AND ST_NumPoints(geom) = 2"));
7794

7895
// now change a node in the way...
79-
REQUIRE_NOTHROW(db.run_import(
80-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
81-
"n10 v2 dV x10.0 y10.3\n"));
96+
REQUIRE_NOTHROW(db.run_import(options, "n10 v2 dV x10.0 y10.3\n"));
8297

8398
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type = 'N'"));
8499
REQUIRE(1 == conn.get_count("osm2pgsql_test_data", "osm_type = 'W'"));
@@ -89,9 +104,8 @@ TEST_CASE("updating a way")
89104

90105
// now add a node to the way...
91106
REQUIRE_NOTHROW(db.run_import(
92-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
93-
"n12 v1 dV x10.2 y10.1\n"
94-
"w20 v3 dV Thighway=residential Nn10,n11,n12\n"));
107+
options, "n12 v1 dV x10.2 y10.1\n"
108+
"w20 v3 dV Thighway=residential Nn10,n11,n12\n"));
95109

96110
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type = 'N'"));
97111
REQUIRE(1 == conn.get_count("osm2pgsql_test_data", "osm_type = 'W'"));
@@ -101,24 +115,24 @@ TEST_CASE("updating a way")
101115
"'residential' AND ST_NumPoints(geom) = 3"));
102116

103117
// now delete the way...
104-
REQUIRE_NOTHROW(db.run_import(
105-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
106-
"w20 v4 dD\n"));
118+
REQUIRE_NOTHROW(db.run_import(options, "w20 v4 dD\n"));
107119

108120
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type = 'N'"));
109121
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type = 'W'"));
110122
}
111123

112-
TEST_CASE("ways as linestrings and polygons")
124+
TEMPLATE_TEST_CASE("ways as linestrings and polygons", "", options_slim_default,
125+
options_slim_expire)
113126
{
127+
options_t options = TestType::options();
128+
114129
// import a simple way...
115-
REQUIRE_NOTHROW(
116-
db.run_import(testing::opt_t().slim().flex("test_output_flex_uni.lua"),
117-
"n10 v1 dV x10.0 y10.0\n"
118-
"n11 v1 dV x10.0 y10.2\n"
119-
"n12 v1 dV x10.2 y10.2\n"
120-
"n13 v1 dV x10.2 y10.0\n"
121-
"w20 v1 dV Tbuilding=yes Nn10,n11,n12,n13,n10\n"));
130+
REQUIRE_NOTHROW(db.run_import(
131+
options, "n10 v1 dV x10.0 y10.0\n"
132+
"n11 v1 dV x10.0 y10.2\n"
133+
"n12 v1 dV x10.2 y10.2\n"
134+
"n13 v1 dV x10.2 y10.0\n"
135+
"w20 v1 dV Tbuilding=yes Nn10,n11,n12,n13,n10\n"));
122136

123137
auto conn = db.db().connect();
124138

@@ -137,9 +151,9 @@ TEST_CASE("ways as linestrings and polygons")
137151
"ST_GeometryType(geom) = 'ST_LineString'"));
138152

139153
// now change the way tags...
154+
options.append = true;
140155
REQUIRE_NOTHROW(db.run_import(
141-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
142-
"w20 v2 dV Thighway=secondary Nn10,n11,n12,n13,n10\n"));
156+
options, "w20 v2 dV Thighway=secondary Nn10,n11,n12,n13,n10\n"));
143157

144158
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type != 'W'"));
145159
REQUIRE(
@@ -155,8 +169,7 @@ TEST_CASE("ways as linestrings and polygons")
155169

156170
// now remove a node from the way...
157171
REQUIRE_NOTHROW(db.run_import(
158-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
159-
"w20 v3 dV Thighway=secondary Nn10,n11,n12,n13\n"));
172+
options, "w20 v3 dV Thighway=secondary Nn10,n11,n12,n13\n"));
160173

161174
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type != 'W'"));
162175
REQUIRE(
@@ -171,16 +184,14 @@ TEST_CASE("ways as linestrings and polygons")
171184
"ST_GeometryType(geom) = 'ST_LineString'"));
172185

173186
// now change the tag back to an area tag (but the way is not closed)...
174-
REQUIRE_NOTHROW(db.run_import(
175-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
176-
"w20 v4 dV Tbuilding=yes Nn10,n11,n12,n13\n"));
187+
REQUIRE_NOTHROW(
188+
db.run_import(options, "w20 v4 dV Tbuilding=yes Nn10,n11,n12,n13\n"));
177189

178190
REQUIRE(0 == conn.get_count("osm2pgsql_test_data"));
179191

180192
// now close the way again
181193
REQUIRE_NOTHROW(db.run_import(
182-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
183-
"w20 v5 dV Tbuilding=yes Nn10,n11,n12,n13,n10\n"));
194+
options, "w20 v5 dV Tbuilding=yes Nn10,n11,n12,n13,n10\n"));
184195

185196
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type != 'W'"));
186197
REQUIRE(
@@ -191,17 +202,19 @@ TEST_CASE("ways as linestrings and polygons")
191202
"ST_GeometryType(geom) = 'ST_Polygon'"));
192203
}
193204

194-
TEST_CASE("multipolygons")
205+
TEMPLATE_TEST_CASE("multipolygons", "", options_slim_default,
206+
options_slim_expire)
195207
{
208+
options_t options = TestType::options();
209+
196210
// import a simple multipolygon relation...
197-
REQUIRE_NOTHROW(
198-
db.run_import(testing::opt_t().slim().flex("test_output_flex_uni.lua"),
199-
"n10 v1 dV x10.0 y10.0\n"
200-
"n11 v1 dV x10.0 y10.2\n"
201-
"n12 v1 dV x10.2 y10.2\n"
202-
"n13 v1 dV x10.2 y10.0\n"
203-
"w20 v1 dV Nn10,n11,n12,n13,n10\n"
204-
"r30 v1 dV Ttype=multipolygon,building=yes Mw20@\n"));
211+
REQUIRE_NOTHROW(db.run_import(
212+
options, "n10 v1 dV x10.0 y10.0\n"
213+
"n11 v1 dV x10.0 y10.2\n"
214+
"n12 v1 dV x10.2 y10.2\n"
215+
"n13 v1 dV x10.2 y10.0\n"
216+
"w20 v1 dV Nn10,n11,n12,n13,n10\n"
217+
"r30 v1 dV Ttype=multipolygon,building=yes Mw20@\n"));
205218

206219
auto conn = db.db().connect();
207220

@@ -216,8 +229,9 @@ TEST_CASE("multipolygons")
216229
"ST_GeometryType(geom) = 'ST_Polygon'"));
217230

218231
// change tags on that relation...
232+
options.append = true;
219233
REQUIRE_NOTHROW(db.run_import(
220-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
234+
options,
221235
"r30 v2 dV Ttype=multipolygon,building=yes,name=Shed Mw20@\n"));
222236

223237
REQUIRE(0 == conn.get_count("osm2pgsql_test_data", "osm_type = 'N'"));
@@ -232,16 +246,13 @@ TEST_CASE("multipolygons")
232246

233247
SECTION("remove relation")
234248
{
235-
REQUIRE_NOTHROW(db.run_import(
236-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
237-
"r30 v3 dD\n"));
249+
REQUIRE_NOTHROW(db.run_import(options, "r30 v3 dD\n"));
238250
}
239251

240252
SECTION("remove multipolygon tag")
241253
{
242254
REQUIRE_NOTHROW(db.run_import(
243-
testing::opt_t().slim().append().flex("test_output_flex_uni.lua"),
244-
"r30 v3 dV Tbuilding=yes,name=Shed Mw20@\n"));
255+
options, "r30 v3 dV Tbuilding=yes,name=Shed Mw20@\n"));
245256
}
246257

247258
REQUIRE(0 == conn.get_count("osm2pgsql_test_data"));

0 commit comments

Comments
 (0)