Skip to content

Commit f8f2713

Browse files
committed
postgres provider: improve owner check (fixes #9844)
1 parent 4afdf55 commit f8f2713

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/providers/postgres/qgspostgresconn.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,15 @@ bool QgsPostgresConn::openCursor( QString cursorName, QString sql )
894894
{
895895
if ( mOpenCursors++ == 0 && !mTransaction )
896896
{
897-
QgsDebugMsg( "Starting read-only transaction" );
898-
PQexecNR( "BEGIN READ ONLY" );
897+
QgsDebugMsg( QString( "Starting read-only transaction: %1" ).arg( mPostgresqlVersion ) );
898+
if ( mPostgresqlVersion >= 80000 )
899+
PQexecNR( "BEGIN READ ONLY" );
900+
else
901+
PQexecNR( "BEGIN" );
899902
}
900903
QgsDebugMsgLevel( QString( "Binary cursor %1 for %2" ).arg( cursorName ).arg( sql ), 3 );
901904
return PQexecNR( QString( "DECLARE %1 BINARY CURSOR %2 FOR %3" ).
902-
arg( cursorName ).arg( !mTransaction ? QString() : QString( "WITH HOLD" ) ).arg( sql ) );
905+
arg( cursorName ).arg( !mTransaction ? "" : QString( "WITH HOLD" ) ).arg( sql ) );
903906
}
904907

905908
bool QgsPostgresConn::closeCursor( QString cursorName )

src/providers/postgres/qgspostgresprovider.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,11 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
976976

977977
sql = QString( "SELECT 1 FROM pg_class,pg_namespace WHERE "
978978
"pg_class.relnamespace=pg_namespace.oid AND "
979-
"pg_get_userbyid(relowner)=current_user AND "
979+
"%3 AND "
980980
"relname=%1 AND nspname=%2" )
981981
.arg( quotedValue( mTableName ) )
982-
.arg( quotedValue( mSchemaName ) );
982+
.arg( quotedValue( mSchemaName ) )
983+
.arg( connectionRO()->pgVersion() < 80100 ? "pg_get_userbyid(relowner)=current_user" : "pg_has_role(relowner,'MEMBER')" );
983984
testAccess = connectionRO()->PQexec( sql );
984985
if ( testAccess.PQresultStatus() == PGRES_TUPLES_OK && testAccess.PQntuples() == 1 )
985986
{

0 commit comments

Comments
 (0)