Skip to content

Commit 91ddbb9

Browse files
committed
Check earlier that the database has the hstore extension
1 parent 6a6f91e commit 91ddbb9

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

src/flex-table-column.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "flex-table-column.hpp"
1111
#include "format.hpp"
12+
#include "pgsql-capabilities.hpp"
1213
#include "util.hpp"
1314

1415
#include <algorithm>
@@ -82,7 +83,14 @@ flex_table_column_t::flex_table_column_t(std::string name,
8283
: m_name(std::move(name)), m_type_name(lowercase(type)),
8384
m_sql_type(std::move(sql_type)),
8485
m_type(get_column_type_from_string(m_type_name))
85-
{}
86+
{
87+
if (m_type == table_column_type::hstore) {
88+
if (!has_extension("hstore")) {
89+
throw std::runtime_error{"Extension 'hstore' not available. Use "
90+
"'CREATE EXTENSION hstore;' to load it."};
91+
}
92+
}
93+
}
8694

8795
void flex_table_column_t::set_projection(char const *projection)
8896
{

src/flex-table.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ bool flex_table_t::has_id_column() const noexcept
7474
(m_columns[0].type() == table_column_type::id_num);
7575
}
7676

77-
bool flex_table_t::has_hstore_column() const noexcept
78-
{
79-
auto const it = std::find_if(begin(), end(), [&](auto const &column) {
80-
return column.type() == table_column_type::hstore;
81-
});
82-
return it != end();
83-
}
84-
8577
bool flex_table_t::matches_type(osmium::item_type type) const noexcept
8678
{
8779
// This table takes any type -> okay
@@ -277,13 +269,6 @@ void table_connection_t::start(bool append)
277269
}
278270
}
279271

280-
if (table().has_hstore_column()) {
281-
if (!has_extension("hstore")) {
282-
throw std::runtime_error{"Extension 'hstore' not available. Use "
283-
"'CREATE EXTENSION hstore;' to load it."};
284-
}
285-
}
286-
287272
m_db_connection->exec("SET client_min_messages = WARNING");
288273

289274
if (!append) {

src/flex-table.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ class flex_table_t
104104
return m_geom_column != std::numeric_limits<std::size_t>::max();
105105
}
106106

107-
bool has_hstore_column() const noexcept;
108-
109107
/// Get the (first, if there are multiple) geometry column.
110108
flex_table_column_t const &geom_column() const noexcept
111109
{

0 commit comments

Comments
 (0)