Skip to content

Commit 0e7f92a

Browse files
committed
Move params.[ch]pp and template.[ch]pp into main src directory
From the "gen" directory. As preparation for using this code in the main program.
1 parent 686d760 commit 0e7f92a

File tree

7 files changed

+39
-31
lines changed

7 files changed

+39
-31
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ else()
266266
src/gen/gen-tile-sql.cpp
267267
src/gen/gen-tile-vector.cpp
268268
src/gen/gen-tile.cpp
269-
src/gen/params.cpp
270269
src/gen/raster.cpp
271-
src/gen/template.cpp
272270
src/gen/tracer.cpp)
273271
target_link_libraries(osm2pgsql-gen osm2pgsql_lib ${LIBS} ${POTRACE_LIBRARY} ${OpenCV_LIBS})
274272
endif()

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ target_sources(osm2pgsql_lib PRIVATE
4747
output-null.cpp
4848
output-pgsql.cpp
4949
output.cpp
50+
params.cpp
5051
pgsql-capabilities.cpp
5152
pgsql-helper.cpp
5253
pgsql.cpp
@@ -58,6 +59,7 @@ target_sources(osm2pgsql_lib PRIVATE
5859
tagtransform-c.cpp
5960
tagtransform-lua.cpp
6061
tagtransform.cpp
62+
template.cpp
6163
thread-pool.cpp
6264
tile.cpp
6365
util.cpp

src/middle-pgsql.cpp

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "options.hpp"
4343
#include "osmtypes.hpp"
4444
#include "pgsql-helper.hpp"
45+
#include "template.hpp"
4546
#include "util.hpp"
4647

4748
namespace {
@@ -72,37 +73,44 @@ void load_id_list(pg_conn_t const &db_connection, std::string const &table,
7273

7374
std::string build_sql(options_t const &options, std::string const &templ)
7475
{
75-
std::string const using_tablespace{options.tblsslim_index.empty()
76-
? ""
77-
: "USING INDEX TABLESPACE " +
78-
options.tblsslim_index};
79-
8076
std::string const schema = "\"" + options.middle_dbschema + "\".";
8177

82-
return fmt::format(
83-
fmt::runtime(templ), fmt::arg("prefix", options.prefix),
84-
fmt::arg("schema", schema),
85-
fmt::arg("unlogged", options.droptemp ? "UNLOGGED" : ""),
86-
fmt::arg("using_tablespace", using_tablespace),
87-
fmt::arg("data_tablespace", tablespace_clause(options.tblsslim_data)),
88-
fmt::arg("index_tablespace", tablespace_clause(options.tblsslim_index)),
89-
fmt::arg("way_node_index_id_shift", 5),
90-
fmt::arg("attribute_columns_definition",
91-
options.extra_attributes ? " created timestamp with time zone,"
92-
" version int4,"
93-
" changeset_id int4,"
94-
" user_id int4,"
95-
: ""),
96-
fmt::arg("attribute_columns_use",
97-
options.extra_attributes
98-
? ", EXTRACT(EPOCH FROM created) AS created, version, "
99-
"changeset_id, user_id, u.name"
100-
: ""),
101-
fmt::arg("users_table_access",
102-
options.extra_attributes
103-
? "LEFT JOIN " + schema + '"' + options.prefix +
104-
"_users\" u ON o.user_id = u.id"
105-
: ""));
78+
params_t params;
79+
params.set("prefix", options.prefix);
80+
params.set("schema", schema);
81+
params.set("unlogged", options.droptemp ? "UNLOGGED" : "");
82+
params.set("data_tablespace", tablespace_clause(options.tblsslim_data));
83+
params.set("index_tablespace", tablespace_clause(options.tblsslim_index));
84+
params.set("way_node_index_id_shift", 5);
85+
86+
if (options.tblsslim_index.empty()) {
87+
params.set("using_tablespace", "");
88+
} else {
89+
params.set("using_tablespace",
90+
"USING INDEX TABLESPACE " + options.tblsslim_index);
91+
}
92+
93+
if (options.extra_attributes) {
94+
params.set("attribute_columns_definition",
95+
" created timestamp with time zone,"
96+
" version int4,"
97+
" changeset_id int4,"
98+
" user_id int4,");
99+
params.set("attribute_columns_use",
100+
", EXTRACT(EPOCH FROM created) AS created, version, "
101+
"changeset_id, user_id, u.name");
102+
params.set("users_table_access", "LEFT JOIN " + schema + '"' +
103+
options.prefix +
104+
"_users\" u ON o.user_id = u.id");
105+
} else {
106+
params.set("attribute_columns_definition", "");
107+
params.set("attribute_columns_use", "");
108+
params.set("users_table_access", "");
109+
}
110+
111+
template_t sql_template{templ};
112+
sql_template.set_params(params);
113+
return sql_template.render();
106114
}
107115

108116
std::vector<std::string> build_sql(options_t const &options,
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)