@@ -75,18 +75,16 @@ flex_table_column_t &flex_table_t::add_column(std::string const &name,
7575
7676std::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
9290std::string flex_table_t::build_sql_create_table (table_type ttype,
@@ -225,14 +223,10 @@ void table_connection_t::stop(bool updateable, bool append)
225223 table ().geom_column ().name ());
226224 }
227225
228- auto const res = m_db_connection->query (
229- PGRES_TUPLES_OK,
230- " SELECT regexp_split_to_table(postgis_lib_version(), '\\ .')" );
231- auto const postgis_major = std::stoi (res.get_value_as_string (0 , 0 ));
232- auto const postgis_minor = std::stoi (res.get_value_as_string (1 , 0 ));
226+ auto const postgis_version = get_postgis_version (*m_db_connection);
233227
234228 sql += " ORDER BY " ;
235- if (postgis_major == 2 && postgis_minor < 4 ) {
229+ if (postgis_version. major == 2 && postgis_version. minor < 4 ) {
236230 fmt::print (stderr, " Using GeoHash for clustering\n " );
237231 if (table ().srid () == 4326 ) {
238232 sql += " ST_GeoHash({},10)" _format (table ().geom_column ().name ());
@@ -302,6 +296,14 @@ void table_connection_t::stop(bool updateable, bool append)
302296 teardown ();
303297}
304298
299+ void table_connection_t::prepare ()
300+ {
301+ assert (m_db_connection);
302+ if (table ().has_id_column () && table ().has_geom_column ()) {
303+ m_db_connection->exec (table ().build_sql_prepare_get_wkb ());
304+ }
305+ }
306+
305307pg_result_t table_connection_t::get_geom_by_id (osmium::item_type type,
306308 osmid_t id) const
307309{
0 commit comments