I've got a PyQGIS 3 project up and running with a .sqlite database, with which I'm adding layers to with a QgsVectorFileWriter, without too many issues so far.

However I've noticed that once a Vector- or Raster layer has been removed from the scene (using QgsProject.instance().removeMapLayers(ids)) the layer is removed properly, but its data in the database remains unchanged.

Is there any way to get the database to delete the table associated with the layer that's being removed?

I see the QgsVectorFileWriter has a deleteShapeFile() method for removing layers in .shp files, and a CanDeleteLayer option in the ActionOnExistingFile enumerator, but it's not at all obvious how these should be used.

I have not found an option in the data provider to force the driver to remove the sqlite tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.