@@ -268,6 +268,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
268
268
, valid( false )
269
269
, featuresCounted( -1 )
270
270
, mDataModified( false )
271
+ , mWriteAccess( false )
271
272
{
272
273
QgsCPLErrorHandler handler;
273
274
@@ -368,7 +369,11 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
368
369
if ( !openReadOnly )
369
370
ogrDataSource = OGROpen ( TO8F ( mFilePath ), true , &ogrDriver );
370
371
371
- if ( !ogrDataSource )
372
+ if ( ogrDataSource )
373
+ {
374
+ mWriteAccess = true ;
375
+ }
376
+ else
372
377
{
373
378
QgsDebugMsg ( " OGR failed to opened in update mode, trying in read-only mode" );
374
379
@@ -1442,19 +1447,19 @@ int QgsOgrProvider::capabilities() const
1442
1447
ability |= QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
1443
1448
}
1444
1449
1445
- if ( OGR_L_TestCapability ( ogrLayer, " SequentialWrite" ) )
1450
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " SequentialWrite" ) )
1446
1451
// true if the CreateFeature() method works for this layer.
1447
1452
{
1448
1453
ability |= QgsVectorDataProvider::AddFeatures;
1449
1454
}
1450
1455
1451
- if ( OGR_L_TestCapability ( ogrLayer, " DeleteFeature" ) )
1456
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " DeleteFeature" ) )
1452
1457
// true if this layer can delete its features
1453
1458
{
1454
1459
ability |= DeleteFeatures;
1455
1460
}
1456
1461
1457
- if ( OGR_L_TestCapability ( ogrLayer, " RandomWrite" ) )
1462
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " RandomWrite" ) )
1458
1463
// true if the SetFeature() method is operational on this layer.
1459
1464
{
1460
1465
// TODO According to http://shapelib.maptools.org/ (Shapefile C Library V1.2)
@@ -1502,12 +1507,12 @@ int QgsOgrProvider::capabilities() const
1502
1507
}
1503
1508
#endif
1504
1509
1505
- if ( OGR_L_TestCapability ( ogrLayer, " CreateField" ) )
1510
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " CreateField" ) )
1506
1511
{
1507
1512
ability |= AddAttributes;
1508
1513
}
1509
1514
1510
- if ( OGR_L_TestCapability ( ogrLayer, " DeleteField" ) )
1515
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " DeleteField" ) )
1511
1516
{
1512
1517
ability |= DeleteAttributes;
1513
1518
}
0 commit comments