Skip to content

Commit 9c6ed68

Browse files
committed
Store -O/--output setting in properties and use for append
1 parent 27aa584 commit 9c6ed68

File tree

7 files changed

+75
-11
lines changed

7 files changed

+75
-11
lines changed

src/command-line-parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ options_t parse_command_line(int argc, char *argv[])
652652
break;
653653
case 'O': // --output
654654
options.output_backend = optarg;
655+
options.output_backend_set = true;
655656
break;
656657
case 'x': // --extra-attributes
657658
options.extra_attributes = true;

src/options.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ struct options_t
184184
bool parallel_indexing = true;
185185
bool create = false;
186186
bool pass_prompt = false;
187+
188+
bool output_backend_set = false;
187189
}; // struct options_t
188190

189191
#endif // OSM2PGSQL_OPTIONS_HPP

src/osm2pgsql.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static void store_properties(properties_t *properties, options_t const &options)
113113
properties->set_bool("updatable", options.slim && !options.droptemp);
114114
properties->set_string("version", get_osm2pgsql_short_version());
115115
properties->set_int("db_format", options.middle_database_format);
116+
properties->set_string("output", options.output_backend);
116117

117118
properties->store();
118119
}
@@ -241,6 +242,25 @@ static void check_db_format(properties_t const &properties, options_t *options)
241242
options->middle_database_format = format;
242243
}
243244

245+
static void check_output(properties_t const &properties, options_t *options)
246+
{
247+
auto const output = properties.get_string("output", "pgsql");
248+
249+
if (!options->output_backend_set) {
250+
options->output_backend = output;
251+
log_info("Using output '{}' (same as on import).", output);
252+
return;
253+
}
254+
255+
if (options->output_backend == output) {
256+
return;
257+
}
258+
259+
throw fmt_error("Different output specified on command line ('{}')"
260+
" then used on import ('{}').",
261+
options->output_backend, output);
262+
}
263+
244264
// This is called in "append" mode to check that the command line options are
245265
// compatible with the properties stored in the database.
246266
static void check_and_update_properties(properties_t *properties,
@@ -251,6 +271,7 @@ static void check_and_update_properties(properties_t *properties,
251271
check_and_update_flat_node_file(properties, options);
252272
check_prefix(*properties, options);
253273
check_db_format(*properties, options);
274+
check_output(*properties, options);
254275
}
255276

256277
// If we are in append mode and the middle nodes table isn't there, it probably

tests/bdd/regression/properties.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ Feature: Updates to the test database with properties check
2626
| --slim | --flat-nodes=x | Database was imported without flat node file |
2727

2828

29+
Scenario: Append without output on null output
30+
When running osm2pgsql null with parameters
31+
| -c |
32+
| --slim |
33+
34+
Given the input file '000466354.osc.gz'
35+
When running osm2pgsql nooutput with parameters
36+
| -a |
37+
| --slim |
38+
Then the error output contains
39+
"""
40+
Using output 'null' (same as on import).
41+
"""
42+
43+
2944
Scenario Outline: Create/append with various parameters
3045
When running osm2pgsql pgsql with parameters
3146
| --slim |
@@ -50,3 +65,17 @@ Feature: Updates to the test database with properties check
5065
| --flat-nodes=x | --flat-nodes=y | Using the flat node file you specified |
5166
| --prefix=abc | | Using prefix 'abc' (same as on import). |
5267

68+
69+
Scenario: Create with different output than append
70+
When running osm2pgsql pgsql with parameters
71+
| --slim |
72+
73+
Given the input file '000466354.osc.gz'
74+
Then running osm2pgsql null with parameters fails
75+
| -a |
76+
| --slim |
77+
And the error output contains
78+
"""
79+
Different output specified on command line
80+
"""
81+

tests/bdd/regression/timestamps.feature

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
99
"""
1010
When running osm2pgsql pgsql
1111

12-
Then table osm2pgsql_properties has 8 rows
12+
Then table osm2pgsql_properties has 9 rows
1313
And table osm2pgsql_properties contains
1414
| property | value |
1515
| attributes | false |
@@ -19,6 +19,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
1919
| updatable | false |
2020
| import_timestamp | 2020-01-02T03:04:06Z |
2121
| current_timestamp | 2020-01-02T03:04:06Z |
22+
| output | pgsql |
2223

2324
Scenario: Create database without timestamps
2425
Given the OSM data
@@ -29,14 +30,15 @@ Feature: Timestamps in properties table should reflect timestamps in input file
2930
"""
3031
When running osm2pgsql pgsql
3132

32-
Then table osm2pgsql_properties has 6 rows
33+
Then table osm2pgsql_properties has 7 rows
3334
Then table osm2pgsql_properties contains
3435
| property | value |
3536
| attributes | false |
3637
| db_format | 0 |
3738
| flat_node_file | |
3839
| prefix | planet_osm |
3940
| updatable | false |
41+
| output | pgsql |
4042

4143
Scenario: Create and update database with timestamps
4244
Given the OSM data
@@ -49,7 +51,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
4951
When running osm2pgsql pgsql with parameters
5052
| --create | --slim |
5153

52-
Then table osm2pgsql_properties has 8 rows
54+
Then table osm2pgsql_properties has 9 rows
5355
And table osm2pgsql_properties contains
5456
| property | value |
5557
| attributes | false |
@@ -59,6 +61,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
5961
| updatable | true |
6062
| import_timestamp | 2020-01-02T03:04:06Z |
6163
| current_timestamp | 2020-01-02T03:04:06Z |
64+
| output | pgsql |
6265

6366
Given the OSM data
6467
"""
@@ -69,7 +72,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
6972
When running osm2pgsql pgsql with parameters
7073
| --append | --slim |
7174

72-
Then table osm2pgsql_properties has 8 rows
75+
Then table osm2pgsql_properties has 9 rows
7376
And table osm2pgsql_properties contains
7477
| property | value |
7578
| attributes | false |
@@ -79,6 +82,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
7982
| updatable | true |
8083
| import_timestamp | 2020-01-02T03:04:06Z |
8184
| current_timestamp | 2020-01-02T03:06:05Z |
85+
| output | pgsql |
8286

8387
Scenario: Create database with timestamps and update without timestamps
8488
Given the OSM data
@@ -91,7 +95,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
9195
When running osm2pgsql pgsql with parameters
9296
| --create | --slim |
9397

94-
Then table osm2pgsql_properties has 8 rows
98+
Then table osm2pgsql_properties has 9 rows
9599
And table osm2pgsql_properties contains
96100
| property | value |
97101
| attributes | false |
@@ -101,6 +105,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
101105
| updatable | true |
102106
| import_timestamp | 2020-01-02T03:04:06Z |
103107
| current_timestamp | 2020-01-02T03:04:06Z |
108+
| output | pgsql |
104109

105110
Given the OSM data
106111
"""
@@ -111,7 +116,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
111116
When running osm2pgsql pgsql with parameters
112117
| --append | --slim |
113118

114-
Then table osm2pgsql_properties has 8 rows
119+
Then table osm2pgsql_properties has 9 rows
115120
And table osm2pgsql_properties contains
116121
| property | value |
117122
| attributes | false |
@@ -121,6 +126,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
121126
| updatable | true |
122127
| import_timestamp | 2020-01-02T03:04:06Z |
123128
| current_timestamp | 2020-01-02T03:04:06Z |
129+
| output | pgsql |
124130

125131
Scenario: Create database without timestamps and update with timestamps
126132
Given the OSM data
@@ -133,14 +139,15 @@ Feature: Timestamps in properties table should reflect timestamps in input file
133139
When running osm2pgsql pgsql with parameters
134140
| --create | --slim |
135141

136-
Then table osm2pgsql_properties has 6 rows
142+
Then table osm2pgsql_properties has 7 rows
137143
And table osm2pgsql_properties contains
138144
| property | value |
139145
| attributes | false |
140146
| db_format | 1 |
141147
| flat_node_file | |
142148
| prefix | planet_osm |
143149
| updatable | true |
150+
| output | pgsql |
144151

145152
Given the OSM data
146153
"""
@@ -151,7 +158,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file
151158
When running osm2pgsql pgsql with parameters
152159
| --append | --slim |
153160

154-
Then table osm2pgsql_properties has 7 rows
161+
Then table osm2pgsql_properties has 8 rows
155162
And table osm2pgsql_properties contains
156163
| property | value |
157164
| attributes | false |
@@ -160,4 +167,5 @@ Feature: Timestamps in properties table should reflect timestamps in input file
160167
| prefix | planet_osm |
161168
| updatable | true |
162169
| current_timestamp | 2020-01-02T03:06:05Z |
170+
| output | pgsql |
163171

tests/bdd/regression/update.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Feature: Updates to the test database
2222
And table planet_osm_line has 3274 rows
2323
And table planet_osm_roads has 380 rows
2424
And table planet_osm_polygon has 4277 rows
25-
And table osm2pgsql_properties has 11 rows
25+
And table osm2pgsql_properties has 12 rows
2626

2727
Examples:
2828
| param1 | param2 | param3 |

tests/bdd/steps/steps_execute.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ def get_import_file(context):
3838

3939

4040
def run_osm2pgsql(context, output):
41-
assert output in ('flex', 'pgsql', 'gazetteer', 'none')
41+
assert output in ('flex', 'pgsql', 'gazetteer', 'null', 'nooutput')
4242

4343
cmdline = [str(Path(context.config.userdata['BINARY']).resolve())]
44-
cmdline.extend(('-O', output))
44+
45+
if output != 'nooutput':
46+
cmdline.extend(('-O', output))
47+
4548
cmdline.extend(context.osm2pgsql_params)
4649

4750
# convert table items to CLI arguments and inject constants to placeholders

0 commit comments

Comments
 (0)