[gdal-dev] ds.DeleteLayer(idx) "failed: database table is locked"

Even Rouault even.rouault at spatialys.com
Thu Jan 30 10:47:14 PST 2025


Jessy,
>
> Trying to remove superfluous intermediate layers in a GPKG dataset.  
> The general logic is
>
> Ds = ogr.open(fp)
>
I assume you meant ogr.Open(fp, update=True) otherwise you'd got another 
type of error.


> Lyr = ds.executesql(query)
>
> Ds.DeleteLayer(idx) <- failed, database table is locked, may be caused 
> by “sqlite3_exec(DROP TABLE “rtree_layername_geom”) failed: database 
> table is locked
>
> Is layer deletion not supported while a “result set” from a SQL query 
> is on the dataset is active? Perhaps importantly, the query sources 
> the deleted layer.
>
Yes most likely. Calling ds.ReleaseResultSet(Lyr) before should make 
things work.

You could possibly also try to open the dataset after setting 
gdal.SetConfigOption("OGR_SQLITE_JOURNAL", "WAL") , but I'm not positive 
at all this would avoid this particular issue.

Even

-- 
http://www.spatialys.com
My software is free, but my time generally not.
Grumpy maintainer.
"De l'égo à l'égoût, il n'y a qu'une bouche mal refermée", André Isaac
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250130/7485c101/attachment.htm>


More information about the gdal-dev mailing list