aboutsummaryrefslogtreecommitdiffstats
path: root/import_source.py
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2026-03-05 16:29:39 +0100
committerGuilhem Moulin <guilhem@fripost.org>2026-03-05 16:38:04 +0100
commit05ac5b52a224d6eddb23d748a9d8e3ee5571341b (patch)
treed90472278f19b356b6669a3183879d355c9b694c /import_source.py
parent3dc943e6972c93825c34b81fda89511a4763fffb (diff)
ExecuteSQL: Use the context manager instead of calling ReleaseResultSet() manually.
This assumes gdal ≥3.7, see https://gdal.org/en/stable/api/python/raster_api.html#osgeo.gdal.Dataset.ExecuteSQL .
Diffstat (limited to 'import_source.py')
-rw-r--r--import_source.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/import_source.py b/import_source.py
index 1271981..c04390e 100644
--- a/import_source.py
+++ b/import_source.py
@@ -984,18 +984,15 @@ def updateLayerCache(lyr : ogr.Layer, cache : ogr.Layer,
struct_dgst : Final = struct.Struct('@qq').pack
logging.debug('%s', query)
ds = lyr.GetDataset()
- lyr2 = ds.ExecuteSQL(query)
- try:
- assert lyr2.GetLayerDefn().GetFieldDefn(0).GetName() == 'hash_properties'
- assert lyr2.GetLayerDefn().GetFieldDefn(1).GetName() == 'hash_geom'
+ with ds.ExecuteSQL(query) as lyr2:
+ defn2 = lyr2.GetLayerDefn()
+ assert defn2.GetFieldDefn(0).GetName() == 'hash_properties'
+ assert defn2.GetFieldDefn(1).GetName() == 'hash_geom'
feature = lyr2.GetNextFeature()
while feature is not None:
dgst.update(struct_dgst(feature.GetFID(), feature.GetFieldAsInteger64(0)))
dgst.update(feature.GetFieldAsBinary(1))
feature = lyr2.GetNextFeature()
- finally:
- ds.ReleaseResultSet(lyr2)
- lyr2 = None
fingerprint = dgst.digest()
attributeFilter = 'layername = ' + escape_literal_str(layername)