@@ -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
@@ -1446,19 +1451,19 @@ int QgsOgrProvider::capabilities() const
1446
1451
ability |= QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
1447
1452
}
1448
1453
1449
- if ( OGR_L_TestCapability ( ogrLayer, " SequentialWrite" ) )
1454
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " SequentialWrite" ) )
1450
1455
// true if the CreateFeature() method works for this layer.
1451
1456
{
1452
1457
ability |= QgsVectorDataProvider::AddFeatures;
1453
1458
}
1454
1459
1455
- if ( OGR_L_TestCapability ( ogrLayer, " DeleteFeature" ) )
1460
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " DeleteFeature" ) )
1456
1461
// true if this layer can delete its features
1457
1462
{
1458
1463
ability |= DeleteFeatures;
1459
1464
}
1460
1465
1461
- if ( OGR_L_TestCapability ( ogrLayer, " RandomWrite" ) )
1466
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " RandomWrite" ) )
1462
1467
// true if the SetFeature() method is operational on this layer.
1463
1468
{
1464
1469
// TODO According to http://shapelib.maptools.org/ (Shapefile C Library V1.2)
@@ -1506,12 +1511,12 @@ int QgsOgrProvider::capabilities() const
1506
1511
}
1507
1512
#endif
1508
1513
1509
- if ( OGR_L_TestCapability ( ogrLayer, " CreateField" ) )
1514
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " CreateField" ) )
1510
1515
{
1511
1516
ability |= AddAttributes;
1512
1517
}
1513
1518
1514
- if ( OGR_L_TestCapability ( ogrLayer, " DeleteField" ) )
1519
+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " DeleteField" ) )
1515
1520
{
1516
1521
ability |= DeleteAttributes;
1517
1522
}
0 commit comments