Skip to content

Commit

Permalink
Topology is unavailable when user cannot read topology tables
Browse files Browse the repository at this point in the history
Fixes determination of tables from metadata when user has no
privileges on topology. The bug was introduced by
commit bbdbca4

References #32002

Closes #32726
  • Loading branch information
strk authored and nyalldawson committed Nov 20, 2019
1 parent 657a8e0 commit 0558a5c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -1056,7 +1056,23 @@ QString QgsPostgresConn::postgisVersion()
mTopologyAvailable = false;
if ( mPostgisVersionMajor > 1 )
{
QgsPostgresResult result( PQexec( QStringLiteral( "SELECT EXISTS ( SELECT c.oid FROM pg_class AS c JOIN pg_namespace AS n ON c.relnamespace=n.oid WHERE n.nspname='topology' AND c.relname='topology' )" ) ) );
// NOTE: CASE syntax is used to avoid an exception when
// topology.topology does not exist
// See
// https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-EXPRESS-EVAL
QgsPostgresResult result(
PQexec(
QStringLiteral(
"SELECT has_schema_privilege(n.oid, 'usage')"
" AND has_table_privilege(t.oid, 'select')"
" AND has_table_privilege(l.oid, 'select')"
" FROM pg_namespace n, pg_class t, pg_class l"
" WHERE n.nspname = 'topology'"
" AND t.relnamespace = n.oid"
" AND l.relnamespace = n.oid"
" AND t.relname = 'topology'"
" AND l.relname = 'layer'"
) ) );
if ( result.PQntuples() >= 1 && result.PQgetvalue( 0, 0 ) == QLatin1String( "t" ) )
{
mTopologyAvailable = true;
Expand Down

0 comments on commit 0558a5c

Please sign in to comment.