How can I explicitly close/release the result of an ExecuteSQL statement when querying a Spatialite database with OGR via Python? I have a simple query to return the SRID of a dataset. This works as expected. However, subsequent calls to
ds.ExecuteSQL fail with the error 'SQL logic error or missing database' unless I iterate all the way through the result rows.
ogr.UseExceptions() # This query returns a single row sql = 'select distinct srid(geometry) from foo' result = ds.ExecuteSQL(sql) row = result.next() epsg = row.GetField(0) # This call fails ds.ExecuteSQL('drop table bar')
Completing the iteration avoids the error:
_ = [r for r in result]
This is fine for simple cases, but not very explicit. I've tried calling
row=None; result=None but these do not help. What is it that I'm missing here?
UPDATE The exception is only raised when I enable ogr.UseExceptions(). Otherwise the error passes silently and the drop table statement has no affect.