[Qgis-developer] set a feature's primary key after an insert

Stefanie Tellex stefie10 at media.mit.edu
Tue Jun 3 08:54:26 EDT 2008


I created these two patches (against r8576) because I wanted to get the 
primary key of newly inserted features from python.

The first patch is a one liner that sets the feature's primary key to
the new value (using primaryKeyHighWater).

The second one changes the python interface to pass by reference instead
of pass by value, so the new value can be read from python.

Stefanie

-------------- next part --------------
Index: qgis/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- qgis.orig/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp	2008-06-02 15:25:26.000000000 -0400
+++ qgis/qgis_unstable/src/providers/postgres/qgspostgresprovider.cpp	2008-06-02 15:42:49.000000000 -0400
@@ -1843,6 +1843,7 @@
       QList<QByteArray> qparam;
       qparam.append( geomParam.toUtf8() );
       qparam.append( QString("%1").arg( ++primaryKeyHighWater ).toUtf8() );
+      features->setFeatureId(primaryKeyHighWater);
       param[0] = qparam[0];
       param[1] = qparam[1];
 

-------------- next part --------------
Index: qgis/qgis_unstable/python/core/qgsvectordataprovider.sip
===================================================================
--- qgis.orig/qgis_unstable/python/core/qgsvectordataprovider.sip	2008-04-30 10:56:27.000000000 -0400
+++ qgis/qgis_unstable/python/core/qgsvectordataprovider.sip	2008-04-30 11:06:49.000000000 -0400
@@ -148,7 +148,7 @@
        * Adds a list of features
        * @return true in case of success and false in case of failure
        */
-      virtual bool addFeatures(QList<QgsFeature> & flist);
+      virtual bool addFeatures(QList<QgsFeature> & flist /In,Out/);
 
       /** 
        * Deletes a feature



More information about the Qgis-developer mailing list