Skip to content
Permalink
Browse files

Do not check primary key unicity on views when trustProject option is…

… activated
  • Loading branch information
pblottiere committed Aug 21, 2017
1 parent 4a084bf commit b55c1349266f2954062c6087134c918296e94481
Showing with 11 additions and 4 deletions.
  1. +10 −3 src/providers/postgres/qgspostgresprovider.cpp
  2. +1 −1 src/providers/postgres/qgspostgresprovider.h
@@ -37,6 +37,7 @@
#include "qgspostgrestransaction.h"
#include "qgslogger.h"
#include "qgsfeedback.h"
#include "qgssettings.h"

#ifdef HAVE_GUI
#include "qgspgsourceselect.h"
@@ -1324,7 +1325,9 @@ bool QgsPostgresProvider::determinePrimaryKey()
}
else if ( type == Relkind::View || type == Relkind::MaterializedView )
{
determinePrimaryKeyFromUriKeyColumn();
QgsSettings settings;
bool checkPrimaryKeyUnicity = !settings.value( QStringLiteral( "/qgis/trustProject" ), false ).toBool();
determinePrimaryKeyFromUriKeyColumn( checkPrimaryKeyUnicity );
}
else
{
@@ -1453,7 +1456,7 @@ QStringList QgsPostgresProvider::parseUriKey( const QString &key )
return cols;
}

void QgsPostgresProvider::determinePrimaryKeyFromUriKeyColumn()
void QgsPostgresProvider::determinePrimaryKeyFromUriKeyColumn( bool checkPrimaryKeyUnicity )
{
QString primaryKey = mUri.keyColumn();
mPrimaryKeyType = PktUnknown;
@@ -1485,7 +1488,11 @@ void QgsPostgresProvider::determinePrimaryKeyFromUriKeyColumn()

if ( !mPrimaryKeyAttrs.isEmpty() )
{
if ( mUseEstimatedMetadata || uniqueData( primaryKey ) )
bool unique = true;
if ( checkPrimaryKeyUnicity )
unique = uniqueData( primaryKey );

if ( mUseEstimatedMetadata || unique )
{
mPrimaryKeyType = PktFidMap; // Map by default
if ( mPrimaryKeyAttrs.size() == 1 )
@@ -133,7 +133,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
* Fills mPrimaryKeyType and mPrimaryKeyAttrs
* from mUri
*/
void determinePrimaryKeyFromUriKeyColumn();
void determinePrimaryKeyFromUriKeyColumn( bool checkPrimaryKeyUnicity = true );

QgsFields fields() const override;
QString dataComment() const override;

0 comments on commit b55c134

Please sign in to comment.
You can’t perform that action at this time.