2

I am getting an error "ogr error committing transaction: sqlite3_exe(COMMIT) failed: database is locked" when trying to edit a feature on a geopackage layer using pyqgis. It is a QGIS plugin. Everything works fine on my hard drive, the problem occurs when I load the file to a server.

I have found https://github.com/r-spatial/sf/issues/628 which seems similar. This also - How to update attributes on spatialite table programmatically: SQLite Error

def save_point(self):
    try:

        node_lyr_name = 'points'

        node_point = QgsPoint(-83.433, 44.466, 725.000)
        point_id = "2001"

        node_lyr = QgsProject.instance().mapLayersByName(node_lyr_name)[0]

        features = node_lyr.getFeatures()
        node_lyr.startEditing()
        for feature1 in features:
            if feature1['ID'] == point_id:
                feature1.setGeometry(node_point)
                feature1['Name'] = self.dlg.le_yourname.text()
                node_lyr.updateFeature(feature1)
                break

        node_lyr.commitChanges()
        node_lyr.triggerRepaint()

    except Exception as inst:
            self.popMsg(str(inst) + "\n Exception #1561 for row in save_point(): \n" )
            print(type(inst)) 
            print(inst.args)
            print(inst, ' #1604')

Is there anything different I need to do when working with a geopackage?

[EDIT] the below code also fails with the same error. :(

vectorLayer = iface.activeLayer()

features = vectorLayer.getFeatures()
fid = int()
    for feature in features:
    if feature['ID'] == "2016":
        fid= feature.id()
        break

field = vectorLayer.fields().indexFromName('Name')
print(f'Field {field}')
with edit(vectorLayer):
    vectorLayer.changeAttributeValue(fid, field, 'Hello')
5

SQLite documentation does not recommend to keep SQLite database files on network drives.

https://sqlite.org/lockingv3.html

SQLite uses POSIX advisory locks to implement locking on Unix. On Windows it uses the LockFile(), LockFileEx(), and UnlockFile() system calls. SQLite assumes that these system calls all work as advertised. If that is not the case, then database corruption can result. One should note that POSIX advisory locking is known to be buggy or even unimplemented on many NFS implementations (including recent versions of Mac OS X) and that there are reports of locking problems for network filesystems under Windows. Your best defense is to not use SQLite for files on a network filesystem.

If SQLite is used as read-only there should be no risk of corruption even if locking does not work as supposed.

1
  • That is great information. I was trying to use geopackage to replace Shapefile. This seems to be a major limitation to geopackage. I will look for a better way.Thanks user30184. – Cary H Jun 28 '19 at 13:54
0

A simple workaround is to stop map rendering (little checkbox bottom right under the map) before saving your changes. But it is not satisfactory and should be natively implemented in QGIS.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.