Skip to content

Commit 8d4b632

Browse files
committed
Fix problem when detecting PostGIS version
We are accessing data that doesn't exist if we don't get three rows from the SQL query. If the PostGIS version could not be detected, we report that.
1 parent f63421f commit 8d4b632

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/pgsql-capabilities.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,16 @@ void init_postgis_version(pg_conn_t const &db_connection)
9898
capabilities().database_name);
9999
}
100100

101-
capabilities().postgis = {std::stoi(std::string{res.get(0, 0)}),
102-
std::stoi(std::string{res.get(1, 0)})};
101+
try {
102+
if (res.num_tuples() >= 2) {
103+
capabilities().postgis = {std::stoi(std::string{res.get(0, 0)}),
104+
std::stoi(std::string{res.get(1, 0)})};
105+
return;
106+
}
107+
} catch (...) {
108+
// Fall through if std::stoi() fails in which case the version
109+
// is reported as 0.
110+
}
103111
}
104112

105113
} // anonymous namespace
@@ -114,8 +122,13 @@ void init_database_capabilities(pg_conn_t const &db_connection)
114122
try {
115123
log_info("Database version: {}",
116124
capabilities().settings.at("server_version"));
117-
log_info("PostGIS version: {}.{}", capabilities().postgis.major,
118-
capabilities().postgis.minor);
125+
126+
if (capabilities().postgis.major == 0) {
127+
log_info("PostGIS version: could not be detected");
128+
} else {
129+
log_info("PostGIS version: {}.{}", capabilities().postgis.major,
130+
capabilities().postgis.minor);
131+
}
119132

120133
auto const version_str =
121134
capabilities().settings.at("server_version_num");

0 commit comments

Comments
 (0)