Skip to content

Commit 79bc89c

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 79bc89c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/pgsql-capabilities.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ 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+
}
106+
} catch (...) {
107+
// Fall through if std::stoi() fails in which case the version
108+
// is reported as 0.
109+
}
103110
}
104111

105112
} // anonymous namespace
@@ -114,8 +121,13 @@ void init_database_capabilities(pg_conn_t const &db_connection)
114121
try {
115122
log_info("Database version: {}",
116123
capabilities().settings.at("server_version"));
117-
log_info("PostGIS version: {}.{}", capabilities().postgis.major,
118-
capabilities().postgis.minor);
124+
125+
if (capabilities().postgis.major == 0) {
126+
log_info("PostGIS version: could not be detected");
127+
} else {
128+
log_info("PostGIS version: {}.{}", capabilities().postgis.major,
129+
capabilities().postgis.minor);
130+
}
119131

120132
auto const version_str =
121133
capabilities().settings.at("server_version_num");

0 commit comments

Comments
 (0)