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