@@ -2293,6 +2293,22 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
2293
2293
2294
2294
const bool inTransaction = startTransaction ();
2295
2295
2296
+ // Some drivers may need to call ResetReading() after GetFeature(), such
2297
+ // as GPKG in GDAL < 2.3.0 to avoid letting the database in a locked state.
2298
+ // But this is undesirable in general, so don't do this when we know that
2299
+ // we don't need to.
2300
+ bool mayNeedResetReadingAfterGetFeature = true ;
2301
+ if ( mGDALDriverName == QLatin1String ( " ESRI Shapefile" ) )
2302
+ {
2303
+ mayNeedResetReadingAfterGetFeature = false ;
2304
+ }
2305
+ #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,3,0)
2306
+ else if ( mGDALDriverName == QLatin1String ( " GPKG" ) )
2307
+ {
2308
+ mayNeedResetReadingAfterGetFeature = false ;
2309
+ }
2310
+ #endif
2311
+
2296
2312
for ( QgsChangedAttributesMap::const_iterator it = attr_map.begin (); it != attr_map.end (); ++it )
2297
2313
{
2298
2314
QgsFeatureId fid = it.key ();
@@ -2307,7 +2323,11 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
2307
2323
pushError ( tr ( " Feature %1 for attribute update not found." ).arg ( fid ) );
2308
2324
continue ;
2309
2325
}
2310
- mOgrLayer ->ResetReading (); // needed for SQLite-based to clear iterator
2326
+
2327
+ if ( mayNeedResetReadingAfterGetFeature )
2328
+ {
2329
+ mOgrLayer ->ResetReading ();
2330
+ }
2311
2331
2312
2332
QgsLocaleNumC l;
2313
2333
@@ -2476,6 +2496,22 @@ bool QgsOgrProvider::changeGeometryValues( const QgsGeometryMap &geometry_map )
2476
2496
2477
2497
const bool inTransaction = startTransaction ();
2478
2498
2499
+ // Some drivers may need to call ResetReading() after GetFeature(), such
2500
+ // as GPKG in GDAL < 2.3.0 to avoid letting the database in a locked state.
2501
+ // But this is undesirable in general, so don't do this when we know that
2502
+ // we don't need to.
2503
+ bool mayNeedResetReadingAfterGetFeature = true ;
2504
+ if ( mGDALDriverName == QLatin1String ( " ESRI Shapefile" ) )
2505
+ {
2506
+ mayNeedResetReadingAfterGetFeature = false ;
2507
+ }
2508
+ #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,3,0)
2509
+ else if ( mGDALDriverName == QLatin1String ( " GPKG" ) )
2510
+ {
2511
+ mayNeedResetReadingAfterGetFeature = false ;
2512
+ }
2513
+ #endif
2514
+
2479
2515
for ( QgsGeometryMap::const_iterator it = geometry_map.constBegin (); it != geometry_map.constEnd (); ++it )
2480
2516
{
2481
2517
gdal::ogr_feature_unique_ptr theOGRFeature ( mOgrLayer ->GetFeature ( FID_TO_NUMBER ( it.key () ) ) );
@@ -2484,7 +2520,11 @@ bool QgsOgrProvider::changeGeometryValues( const QgsGeometryMap &geometry_map )
2484
2520
pushError ( tr ( " OGR error changing geometry: feature %1 not found" ).arg ( it.key () ) );
2485
2521
continue ;
2486
2522
}
2487
- mOgrLayer ->ResetReading (); // needed for SQLite-based to clear iterator
2523
+
2524
+ if ( mayNeedResetReadingAfterGetFeature )
2525
+ {
2526
+ mOgrLayer ->ResetReading (); // needed for SQLite-based to clear iterator, which could let the database in a locked state otherwise
2527
+ }
2488
2528
2489
2529
OGRGeometryH newGeometry = nullptr ;
2490
2530
QByteArray wkb = it->asWkb ();
0 commit comments