[QGIS Commit] r9381 - in trunk/qgis/src: core providers/postgres

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Sep 23 01:42:44 EDT 2008


Author: jef
Date: 2008-09-23 01:42:44 -0400 (Tue, 23 Sep 2008)
New Revision: 9381

Modified:
   trunk/qgis/src/core/qgsvectorlayer.cpp
   trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
Log:
vector bugfixes
- QgsVectorLayer::commitChanges: handle deleted added features
- QgsPostgresProvider:
  - update ids of added features only, when they were actually inserted
  - deallocate prepared statements after rollback (fixes #1328)



Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2008-09-22 22:51:54 UTC (rev 9380)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2008-09-23 05:42:44 UTC (rev 9381)
@@ -2747,6 +2747,18 @@
     {
       for ( QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter )
       {
+        if ( mDeletedFeatureIds.contains( iter->featureId() ) )
+        {
+          mDeletedFeatureIds.remove( iter->featureId() );
+
+          if ( mChangedGeometries.contains( iter->featureId() ) )
+            mChangedGeometries.remove( iter->featureId() );
+
+          mAddedFeatures.erase( iter );
+
+          continue;
+        }
+
         if ( mChangedGeometries.contains( iter->featureId() ) )
         {
           iter->setGeometry( mChangedGeometries.take( iter->featureId() ) );

Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2008-09-22 22:51:54 UTC (rev 9380)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2008-09-23 05:42:44 UTC (rev 9381)
@@ -1821,6 +1821,7 @@
     PQclear( stmt );
 
     int primaryKeyHighWater = maxPrimaryKeyValue();
+    QList<int> newIds;
 
     for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); features++ )
     {
@@ -1832,8 +1833,9 @@
       QStringList params;
       params << geomParam;
       params << QString( "%1" ).arg( ++primaryKeyHighWater );
-      features->setFeatureId( primaryKeyHighWater );
 
+      newIds << primaryKeyHighWater;
+
       for ( int i = 0; i < fieldId.size(); i++ )
         params << paramValue( attributevec[ fieldId[i] ].toString(), defaultValue[i] );
 
@@ -1843,14 +1845,17 @@
       PQclear( result );
     }
 
+    for ( int i = 0; i < flist.size(); i++ )
+      flist[i].setFeatureId( newIds[i] );
+
     connectionRW->PQexecNR( "DEALLOCATE addfeatures" );
     connectionRW->PQexecNR( "COMMIT" );
   }
   catch ( PGException &e )
   {
     e.showErrorMessage( tr( "Error while adding features" ) );
+    connectionRW->PQexecNR( "ROLLBACK" );
     connectionRW->PQexecNR( "DEALLOCATE addfeatures" );
-    connectionRW->PQexecNR( "ROLLBACK" );
     returnvalue = false;
   }
 
@@ -2121,8 +2126,8 @@
   catch ( PGException &e )
   {
     e.showErrorMessage( tr( "Error while changing geometry values" ) );
+    connectionRW->PQexecNR( "ROLLBACK" );
     connectionRW->PQexecNR( "DEALLOCATE updatefeatures" );
-    connectionRW->PQexecNR( "ROLLBACK" );
     returnvalue = false;
   }
 



More information about the QGIS-commit mailing list