mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
ogr provider: reopen the data source if a REPACK failed (fixes #7540)
This commit is contained in:
parent
aca3dfaf77
commit
78b04df91a
@ -969,6 +969,7 @@ bool QgsOgrProvider::addFeatures( QgsFeatureList & flist )
|
||||
{
|
||||
returnvalue = false;
|
||||
}
|
||||
|
||||
recalculateFeatureCount();
|
||||
|
||||
if ( returnvalue )
|
||||
@ -1139,7 +1140,10 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
|
||||
}
|
||||
}
|
||||
|
||||
OGR_L_SyncToDisk( ogrLayer );
|
||||
if ( OGR_L_SyncToDisk( ogrLayer ) != OGRERR_NONE )
|
||||
{
|
||||
pushError( tr( "OGR error syncing to disk: %1" ).arg( CPLGetLastErrorMsg() ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1254,11 +1258,39 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
|
||||
returnvalue = false;
|
||||
}
|
||||
|
||||
QString layerName = FROM8( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) ) );
|
||||
// run REPACK on shape files
|
||||
if ( ogrDriverName == "ESRI Shapefile" )
|
||||
{
|
||||
QString layerName = FROM8( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) ) );
|
||||
|
||||
QString sql = QString( "REPACK %1" ).arg( layerName ); // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
|
||||
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
|
||||
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).constData(), NULL, NULL );
|
||||
QString sql = QString( "REPACK %1" ).arg( layerName ); // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
|
||||
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
|
||||
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).constData(), NULL, NULL );
|
||||
|
||||
if ( mFilePath.endsWith( ".shp", Qt::CaseInsensitive ) || mFilePath.endsWith( ".dbf", Qt::CaseInsensitive ) )
|
||||
{
|
||||
QString packedDbf( mFilePath.left( mFilePath.size() - 4 ) + "_packed.dbf" );
|
||||
if ( QFile::exists( packedDbf ) )
|
||||
{
|
||||
QgsMessageLog::logMessage( tr( "Possible corruption after REPACK detected. %1 still exists. This may point to a permission or locking problem of the original DBF." ).arg( packedDbf ), tr( "OGR" ), QgsMessageLog::CRITICAL );
|
||||
|
||||
OGR_DS_Destroy( ogrDataSource );
|
||||
|
||||
ogrDataSource = OGROpen( TO8F( mFilePath ), true, NULL );
|
||||
|
||||
if ( mLayerName.isNull() )
|
||||
{
|
||||
ogrOrigLayer = OGR_DS_GetLayer( ogrDataSource, mLayerIndex );
|
||||
}
|
||||
else
|
||||
{
|
||||
ogrOrigLayer = OGR_DS_GetLayerByName( ogrDataSource, TO8( mLayerName ) );
|
||||
}
|
||||
|
||||
ogrLayer = ogrOrigLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recalculateFeatureCount();
|
||||
|
||||
@ -2254,7 +2286,10 @@ QString QgsOgrProvider::quotedIdentifier( QString field )
|
||||
|
||||
bool QgsOgrProvider::syncToDisc()
|
||||
{
|
||||
OGR_L_SyncToDisk( ogrLayer );
|
||||
if ( OGR_L_SyncToDisk( ogrLayer ) != OGRERR_NONE )
|
||||
{
|
||||
pushError( tr( "OGR error syncing to disk: %1" ).arg( CPLGetLastErrorMsg() ) );
|
||||
}
|
||||
|
||||
//for shapefiles: is there already a spatial index?
|
||||
if ( !mFilePath.isEmpty() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user