@@ -1521,6 +1521,31 @@ bool QgsOgrProvider::renameAttributes( const QgsFieldNameMap& renamedAttributes
1521
1521
#endif
1522
1522
}
1523
1523
1524
+ bool QgsOgrProvider::startTransaction ()
1525
+ {
1526
+ bool inTransaction = false ;
1527
+ if ( OGR_L_TestCapability ( ogrLayer, OLCTransactions ) )
1528
+ {
1529
+ // A transaction might already be active, so be robust on failed
1530
+ // StartTransaction.
1531
+ CPLPushErrorHandler ( CPLQuietErrorHandler );
1532
+ inTransaction = ( OGR_L_StartTransaction ( ogrLayer ) == OGRERR_NONE );
1533
+ CPLPopErrorHandler ();
1534
+ }
1535
+ return inTransaction;
1536
+ }
1537
+
1538
+
1539
+ bool QgsOgrProvider::commitTransaction ()
1540
+ {
1541
+ if ( OGR_L_CommitTransaction ( ogrLayer ) != OGRERR_NONE )
1542
+ {
1543
+ pushError ( tr ( " OGR error committing transaction: %1" ).arg ( CPLGetLastErrorMsg () ) );
1544
+ return false ;
1545
+ }
1546
+ return true ;
1547
+ }
1548
+
1524
1549
1525
1550
bool QgsOgrProvider::changeAttributeValues ( const QgsChangedAttributesMap &attr_map )
1526
1551
{
@@ -1534,6 +1559,8 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
1534
1559
1535
1560
setRelevantFields ( ogrLayer, true , attributeIndexes () );
1536
1561
1562
+ const bool inTransaction = startTransaction ();
1563
+
1537
1564
for ( QgsChangedAttributesMap::const_iterator it = attr_map.begin (); it != attr_map.end (); ++it )
1538
1565
{
1539
1566
QgsFeatureId fid = it.key ();
@@ -1649,6 +1676,11 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
1649
1676
OGR_F_Destroy ( of );
1650
1677
}
1651
1678
1679
+ if ( inTransaction )
1680
+ {
1681
+ commitTransaction ();
1682
+ }
1683
+
1652
1684
if ( OGR_L_SyncToDisk ( ogrLayer ) != OGRERR_NONE )
1653
1685
{
1654
1686
pushError ( tr ( " OGR error syncing to disk: %1" ).arg ( CPLGetLastErrorMsg () ) );
@@ -1664,6 +1696,8 @@ bool QgsOgrProvider::changeGeometryValues( const QgsGeometryMap &geometry_map )
1664
1696
1665
1697
setRelevantFields ( ogrLayer, true , attributeIndexes () );
1666
1698
1699
+ const bool inTransaction = startTransaction ();
1700
+
1667
1701
for ( QgsGeometryMap::const_iterator it = geometry_map.constBegin (); it != geometry_map.constEnd (); ++it )
1668
1702
{
1669
1703
if ( FID_TO_NUMBER ( it.key () ) > std::numeric_limits<long >::max () )
@@ -1731,6 +1765,12 @@ bool QgsOgrProvider::changeGeometryValues( const QgsGeometryMap &geometry_map )
1731
1765
1732
1766
OGR_F_Destroy ( theOGRFeature );
1733
1767
}
1768
+
1769
+ if ( inTransaction )
1770
+ {
1771
+ commitTransaction ();
1772
+ }
1773
+
1734
1774
QgsOgrConnPool::instance ()->invalidateConnections ( dataSourceUri () );
1735
1775
return syncToDisc ();
1736
1776
}
0 commit comments