QGIS/python/core/auto_generated/qgsfeaturesink.sip.in
Alessandro Pasotti 7fa6f38689 Memory provider: roll back on errors
Long story short: calling provider's addFeatures
is implemented for some providers in a way that
will roll back all changes on errors, leaving
the backend storage unchanged.

Adding a QgsFeatureSink flag to control this
behavior allows certain providers to support
partial feature addition.

The issue comes from QgsVectorDataProvider::commitChanges
that is documented to leave the provider unchanged (roll
back) on any error, giving the client code the possibility
to fix errors (in the editing buffer) and re-commit.

Without a full rollback implementation in the memory
provider and after the type check introduction in this
PR we ended up with situations like this:

vl = ... an empty memory layer
self.assertTrue(vl.addFeatures([valid, invalid]))
self.assertFalse(vl.commitChanges())
self.assertEqual(vl.featureCount(), 1)  <--- fails!
We actually had 3 features from vl.getFeatures():
[valid, invalid, valid] (the first from the provider
the second and third from the editing buffer).

On the other hand, QgsFeatureSink would probably assume
that addFeatures will allow partial additions.

BTW: This is for sure the longest commit message I've ever
     written.
2020-06-20 04:30:18 +10:00

89 lines
2.9 KiB
Plaintext

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfeaturesink.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsFeatureSink
{
%Docstring
An interface for objects which accept features via addFeature(s) methods.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsfeaturesink.h"
%End
public:
enum SinkFlag
{
RegeneratePrimaryKey,
};
typedef QFlags<QgsFeatureSink::SinkFlag> SinkFlags;
enum Flag
{
FastInsert,
RollBackOnErrors,
};
typedef QFlags<QgsFeatureSink::Flag> Flags;
virtual ~QgsFeatureSink();
virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() );
%Docstring
Adds a single ``feature`` to the sink. Feature addition behavior is controlled by the specified ``flags``.
.. seealso:: :py:func:`addFeatures`
:return: ``True`` in case of success and ``False`` in case of failure
%End
virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) = 0;
%Docstring
Adds a list of ``features`` to the sink. Feature addition behavior is controlled by the specified ``flags``.
.. seealso:: :py:func:`addFeature`
:return: ``True`` in case of success and ``False`` in case of failure
%End
virtual bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() );
%Docstring
Adds all features from the specified ``iterator`` to the sink. Feature addition behavior is controlled by the specified ``flags``.
:return: ``True`` if all features were added successfully, or ``False`` if any feature could not be added
%End
virtual bool flushBuffer();
%Docstring
Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to the sink's destination.
:return: ``False`` if any buffered features could not be added to the sink.
%End
};
QFlags<QgsFeatureSink::Flag> operator|(QgsFeatureSink::Flag f1, QFlags<QgsFeatureSink::Flag> f2);
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfeaturesink.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/