Skip to content

Commit

Permalink
Remove all primary keys when RegeneratePrimaryKey is set, not just th…
Browse files Browse the repository at this point in the history
…ose for GPKG
  • Loading branch information
nyalldawson committed Oct 15, 2020
1 parent db7b977 commit f0bee04
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/core/qgsvectorlayerutils.cpp
Expand Up @@ -743,12 +743,15 @@ QgsFeatureList QgsVectorLayerUtils::makeFeatureCompatible( const QgsFeature &fea
// Fix attributes
QgsVectorLayerUtils::matchAttributesToFields( newF, layer->fields( ) );

if ( sinkFlags & QgsFeatureSink::RegeneratePrimaryKey && layer->storageType() == QLatin1String( "GPKG" ) )
if ( sinkFlags & QgsFeatureSink::RegeneratePrimaryKey )
{
// drop incoming fid value, let it be regenerated
const int fidIndex = layer->fields().lookupField( QStringLiteral( "fid" ) );
if ( fidIndex >= 0 )
newF.setAttribute( fidIndex, QVariant() );
// drop incoming primary key values, let them be regenerated
const QgsAttributeList pkIndexes = layer->dataProvider()->pkAttributeIndexes();
for ( int index : pkIndexes )
{
if ( index >= 0 )
newF.setAttribute( index, QVariant() );
}
}

// Does geometry need transformations?
Expand Down

0 comments on commit f0bee04

Please sign in to comment.