Skip to content
Permalink
Browse files
postgres provider: improve owner check (fixes #9844)
  • Loading branch information
jef-n committed Jan 24, 2015
1 parent 4afdf55 commit f8f2713571f9690ffe8b5b643c939c0c0c1650f5
Showing with 9 additions and 5 deletions.
  1. +6 −3 src/providers/postgres/qgspostgresconn.cpp
  2. +3 −2 src/providers/postgres/qgspostgresprovider.cpp
@@ -894,12 +894,15 @@ bool QgsPostgresConn::openCursor( QString cursorName, QString sql )
{
if ( mOpenCursors++ == 0 && !mTransaction )
{
QgsDebugMsg( "Starting read-only transaction" );
PQexecNR( "BEGIN READ ONLY" );
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 )
@@ -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 )
{

0 comments on commit f8f2713

Please sign in to comment.