Skip to content

Commit 8606e96

Browse files
committed
Do not create unnecessary pseudo-get-wkb pgsql function
The function is never called anyway. Also moves some code from .hpp file into .cpp file.
1 parent 2b07267 commit 8606e96

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/flex-table.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,16 @@ flex_table_column_t &flex_table_t::add_column(std::string const &name,
7575

7676
std::string flex_table_t::build_sql_prepare_get_wkb() const
7777
{
78-
if (has_geom_column()) {
79-
if (has_multicolumn_id_index()) {
80-
return "PREPARE get_wkb(char(1), bigint) AS"
81-
" SELECT \"{}\" FROM {} WHERE \"{}\" = $1 AND \"{}\" = $2"_format(
82-
geom_column().name(), full_name(), m_columns[0].name(),
83-
m_columns[1].name());
84-
}
85-
return "PREPARE get_wkb(bigint) AS"
86-
" SELECT \"{}\" FROM {} WHERE \"{}\" = $1"_format(
87-
geom_column().name(), full_name(), id_column_names());
78+
if (has_multicolumn_id_index()) {
79+
return "PREPARE get_wkb(char(1), bigint) AS"
80+
" SELECT \"{}\" FROM {} WHERE \"{}\" = $1 AND \"{}\" = $2"_format(
81+
geom_column().name(), full_name(), m_columns[0].name(),
82+
m_columns[1].name());
8883
}
89-
return "PREPARE get_wkb(bigint) AS SELECT ''";
84+
85+
return "PREPARE get_wkb(bigint) AS"
86+
" SELECT \"{}\" FROM {} WHERE \"{}\" = $1"_format(
87+
geom_column().name(), full_name(), id_column_names());
9088
}
9189

9290
std::string flex_table_t::build_sql_create_table(table_type ttype,
@@ -302,6 +300,14 @@ void table_connection_t::stop(bool updateable, bool append)
302300
teardown();
303301
}
304302

303+
void table_connection_t::prepare()
304+
{
305+
assert(m_db_connection);
306+
if (table().has_id_column() && table().has_geom_column()) {
307+
m_db_connection->exec(table().build_sql_prepare_get_wkb());
308+
}
309+
}
310+
305311
pg_result_t table_connection_t::get_geom_by_id(osmium::item_type type,
306312
osmid_t id) const
307313
{

src/flex-table.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,7 @@ class table_connection_t
213213

214214
void teardown() { m_db_connection.reset(); }
215215

216-
void prepare()
217-
{
218-
assert(m_db_connection);
219-
if (table().has_id_column()) {
220-
m_db_connection->exec(table().build_sql_prepare_get_wkb());
221-
}
222-
}
216+
void prepare();
223217

224218
void create_id_index()
225219
{

0 commit comments

Comments
 (0)