@@ -268,6 +268,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
268268 , valid( false )
269269 , featuresCounted( -1 )
270270 , mDataModified( false )
271+ , mWriteAccess( false )
271272{
272273 QgsCPLErrorHandler handler;
273274
@@ -368,7 +369,11 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
368369 if ( !openReadOnly )
369370 ogrDataSource = OGROpen ( TO8F ( mFilePath ), true , &ogrDriver );
370371
371- if ( !ogrDataSource )
372+ if ( ogrDataSource )
373+ {
374+ mWriteAccess = true ;
375+ }
376+ else
372377 {
373378 QgsDebugMsg ( " OGR failed to opened in update mode, trying in read-only mode" );
374379
@@ -1442,19 +1447,19 @@ int QgsOgrProvider::capabilities() const
14421447 ability |= QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
14431448 }
14441449
1445- if ( OGR_L_TestCapability ( ogrLayer, " SequentialWrite" ) )
1450+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " SequentialWrite" ) )
14461451 // true if the CreateFeature() method works for this layer.
14471452 {
14481453 ability |= QgsVectorDataProvider::AddFeatures;
14491454 }
14501455
1451- if ( OGR_L_TestCapability ( ogrLayer, " DeleteFeature" ) )
1456+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " DeleteFeature" ) )
14521457 // true if this layer can delete its features
14531458 {
14541459 ability |= DeleteFeatures;
14551460 }
14561461
1457- if ( OGR_L_TestCapability ( ogrLayer, " RandomWrite" ) )
1462+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " RandomWrite" ) )
14581463 // true if the SetFeature() method is operational on this layer.
14591464 {
14601465 // TODO According to http://shapelib.maptools.org/ (Shapefile C Library V1.2)
@@ -1502,12 +1507,12 @@ int QgsOgrProvider::capabilities() const
15021507 }
15031508#endif
15041509
1505- if ( OGR_L_TestCapability ( ogrLayer, " CreateField" ) )
1510+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " CreateField" ) )
15061511 {
15071512 ability |= AddAttributes;
15081513 }
15091514
1510- if ( OGR_L_TestCapability ( ogrLayer, " DeleteField" ) )
1515+ if ( mWriteAccess && OGR_L_TestCapability ( ogrLayer, " DeleteField" ) )
15111516 {
15121517 ability |= DeleteAttributes;
15131518 }
0 commit comments