Skip to content

Commit 2f6c33c

Browse files
committedOct 8, 2020
Merge branch 'ogrprovider_remove_useless_resetreading' of https://github.com/rouault/QGIS into rouault-ogrprovider_remove_useless_resetreading
2 parents c9fb362 + d3d88e2 commit 2f6c33c

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed
 

‎src/core/providers/ogr/qgsogrprovider.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,22 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
22932293

22942294
const bool inTransaction = startTransaction();
22952295

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+
22962312
for ( QgsChangedAttributesMap::const_iterator it = attr_map.begin(); it != attr_map.end(); ++it )
22972313
{
22982314
QgsFeatureId fid = it.key();
@@ -2307,7 +2323,11 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
23072323
pushError( tr( "Feature %1 for attribute update not found." ).arg( fid ) );
23082324
continue;
23092325
}
2310-
mOgrLayer->ResetReading(); // needed for SQLite-based to clear iterator
2326+
2327+
if ( mayNeedResetReadingAfterGetFeature )
2328+
{
2329+
mOgrLayer->ResetReading();
2330+
}
23112331

23122332
QgsLocaleNumC l;
23132333

@@ -2476,6 +2496,22 @@ bool QgsOgrProvider::changeGeometryValues( const QgsGeometryMap &geometry_map )
24762496

24772497
const bool inTransaction = startTransaction();
24782498

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+
24792515
for ( QgsGeometryMap::const_iterator it = geometry_map.constBegin(); it != geometry_map.constEnd(); ++it )
24802516
{
24812517
gdal::ogr_feature_unique_ptr theOGRFeature( mOgrLayer->GetFeature( FID_TO_NUMBER( it.key() ) ) );
@@ -2484,7 +2520,11 @@ bool QgsOgrProvider::changeGeometryValues( const QgsGeometryMap &geometry_map )
24842520
pushError( tr( "OGR error changing geometry: feature %1 not found" ).arg( it.key() ) );
24852521
continue;
24862522
}
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+
}
24882528

24892529
OGRGeometryH newGeometry = nullptr;
24902530
QByteArray wkb = it->asWkb();

0 commit comments

Comments
 (0)
Please sign in to comment.