File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -231,11 +231,32 @@ get_postgresql_settings(pg_conn_t const &db_connection)
231231 return settings;
232232}
233233
234+ static std::string get_database_name (pg_conn_t const &db_connection)
235+ {
236+ auto const res =
237+ db_connection.query (PGRES_TUPLES_OK, " SELECT current_catalog" );
238+
239+ if (res.num_tuples () != 1 ) {
240+ throw std::runtime_error{
241+ " Database error: Can not access database name." };
242+ }
243+
244+ return res.get_value_as_string (0 , 0 );
245+ }
246+
234247postgis_version get_postgis_version (pg_conn_t const &db_connection)
235248{
236249 auto const res = db_connection.query (
237- PGRES_TUPLES_OK,
238- " SELECT regexp_split_to_table(postgis_lib_version(), '\\ .')" );
250+ PGRES_TUPLES_OK, " SELECT regexp_split_to_table(extversion, '\\ .') FROM"
251+ " pg_extension WHERE extname='postgis'" );
252+
253+ if (res.num_tuples () == 0 ) {
254+ throw std::runtime_error{
255+ " The postgis extension is not enabled on the database '{}'."
256+ " Are you using the correct database?"
257+ " Enable with 'CREATE EXTENSION postgis;'" _format (
258+ get_database_name (db_connection))};
259+ }
239260
240261 return {std::stoi (res.get_value_as_string (0 , 0 )),
241262 std::stoi (res.get_value_as_string (1 , 0 ))};
You can’t perform that action at this time.
0 commit comments