Using PyQGIS and QGIS version 2.18.11
I have the following code:
def updateDestination(self, importLayer):
print "updateDestination called"
masterName = importLayer.masterLayer
masterLayer = Utils.getLayerByName(masterName)
(filePath, fileName) = os.path.split(masterLayer.dataProvider().dataSourceUri())
filePath = Utils.processTempFilePath(filePath)
print "Merging into path", filePath
print "fileName is", fileName
fileName = fileName[:fileName.index("'")]
print "fileName is", fileName
temp = Utils.getLayerByName('Merged')
print temp
output = filePath + "/" + fileName
print "Writing to ", output
crs = self.iface.mapCanvas().mapRenderer().destinationCrs()
print crs
QgsVectorFileWriter.writeAsVectorFormat(temp, output, 'utf-8', crs, 'SQLite', False, None, ['SPATIALITE=YES'])
QgsMapLayerRegistry.instance().removeMapLayers([temp.id()] )
I already have an existing Spatialite file containing a table with the same name as the file. Let's call it file1.sqlite.
If I change the output to save to "file2.sqlite" it writes perfectly, giving me a new spatialite. I can then import that as a new layer.
My objective is to have it write to file1.sqlite, and override the existing table inside that file with one of the same name, containing the new data (It's the same columns, but has had new rows appended onto the bottom).
When I attempt this, I get no error and no complaints, but it doesn't write. Is there some way to force this, or perhaps a viable workaround?