postgres provider: improve owner check (fixes #9844)

This commit is contained in:
Juergen E. Fischer 2015-01-24 22:11:51 +01:00
parent 4afdf553e7
commit f8f2713571
2 changed files with 9 additions and 5 deletions

View File

@ -894,12 +894,15 @@ bool QgsPostgresConn::openCursor( QString cursorName, QString sql )
{
if ( mOpenCursors++ == 0 && !mTransaction )
{
QgsDebugMsg( "Starting read-only transaction" );
QgsDebugMsg( QString( "Starting read-only transaction: %1" ).arg( mPostgresqlVersion ) );
if ( mPostgresqlVersion >= 80000 )
PQexecNR( "BEGIN READ ONLY" );
else
PQexecNR( "BEGIN" );
}
QgsDebugMsgLevel( QString( "Binary cursor %1 for %2" ).arg( cursorName ).arg( sql ), 3 );
return PQexecNR( QString( "DECLARE %1 BINARY CURSOR %2 FOR %3" ).
arg( cursorName ).arg( !mTransaction ? QString() : QString( "WITH HOLD" ) ).arg( sql ) );
arg( cursorName ).arg( !mTransaction ? "" : QString( "WITH HOLD" ) ).arg( sql ) );
}
bool QgsPostgresConn::closeCursor( QString cursorName )

View File

@ -976,10 +976,11 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
sql = QString( "SELECT 1 FROM pg_class,pg_namespace WHERE "
"pg_class.relnamespace=pg_namespace.oid AND "
"pg_get_userbyid(relowner)=current_user AND "
"%3 AND "
"relname=%1 AND nspname=%2" )
.arg( quotedValue( mTableName ) )
.arg( quotedValue( mSchemaName ) );
.arg( quotedValue( mSchemaName ) )
.arg( connectionRO()->pgVersion() < 80100 ? "pg_get_userbyid(relowner)=current_user" : "pg_has_role(relowner,'MEMBER')" );
testAccess = connectionRO()->PQexec( sql );
if ( testAccess.PQresultStatus() == PGRES_TUPLES_OK && testAccess.PQntuples() == 1 )
{