Skip to content

Commit

Permalink
Do not check primary key unicity on views when trustProject option is…
Browse files Browse the repository at this point in the history
… activated
  • Loading branch information
pblottiere committed Sep 6, 2017
1 parent 4a084bf commit b55c134
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -37,6 +37,7 @@
#include "qgspostgrestransaction.h"
#include "qgslogger.h"
#include "qgsfeedback.h"
#include "qgssettings.h"

#ifdef HAVE_GUI
#include "qgspgsourceselect.h"
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresprovider.h
Expand Up @@ -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;
Expand Down

0 comments on commit b55c134

Please sign in to comment.