Skip to content
Permalink
Browse files

[ogr] Pass default value (-1) for fid columns

  • Loading branch information
elpaso committed Nov 20, 2017
1 parent f97b5a5 commit 53dd5ef52aa01f7a1164ead1cecc4842a4c3fccf
Showing with 17 additions and 0 deletions.
  1. +16 −0 src/providers/ogr/qgsogrprovider.cpp
  2. +1 −0 src/providers/ogr/qgsogrprovider.h
@@ -948,6 +948,10 @@ void QgsOgrProvider::loadFields()
mAttributeFields.append(
fidField
);
// Set default value for fid, this is needed because
// the attribute form will not accept a NULL value, passing
// -1 will delegate to the back-end.
mDefaultValues.insert( 0, QStringLiteral( "-1" ) );
}

for ( int i = 0; i < fdef.GetFieldCount(); ++i )
@@ -1201,6 +1205,18 @@ QVariant QgsOgrProvider::defaultValue( int fieldId ) const
return resultVar;
}

QString QgsOgrProvider::defaultValueClause( int fieldIndex ) const
{
QString defVal = mDefaultValues.value( fieldIndex, QString() );

if ( !providerProperty( EvaluateDefaultValues, false ).toBool() && !defVal.isEmpty() )
{
return defVal;
}

return QString();
}

void QgsOgrProvider::updateExtents()
{
invalidateCachedExtent( true );
@@ -109,6 +109,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
virtual QgsFields fields() const override;
virtual QgsRectangle extent() const override;
QVariant defaultValue( int fieldId ) const override;
QString defaultValueClause( int fieldIndex ) const override;
virtual void updateExtents() override;
virtual bool addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flags flags = 0 ) override;
virtual bool deleteFeatures( const QgsFeatureIds &id ) override;

0 comments on commit 53dd5ef

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