[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Maposmatic-dev] [PATCH] Cosmetics and better exception-safety for pgsql
From: |
David Decotigny |
Subject: |
[Maposmatic-dev] [PATCH] Cosmetics and better exception-safety for pgsql connection object in nomismatim api. |
Date: |
Sun, 20 Dec 2009 22:22:46 +0100 |
---
www/maposmatic/nominatim.py | 39 +++++++++++++++++++++------------------
1 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/www/maposmatic/nominatim.py b/www/maposmatic/nominatim.py
index 3a54a84..c3a9dd0 100644
--- a/www/maposmatic/nominatim.py
+++ b/www/maposmatic/nominatim.py
@@ -66,26 +66,29 @@ def _retrieve_missing_data_from_GIS(entries):
www.settings.DATABASE_USER,
www.settings.DATABASE_HOST,
www.settings.DATABASE_PASSWORD))
- cursor = conn.cursor()
except psycopg2.OperationalError:
return entries
- for entry in entries:
- if ( (entry.get("class", None) != "boundary")
- or (entry.get("type", None) != "administrative") ):
- continue
-
- for table_name in ("polygon", "line"):
- cursor.execute("""select osm_id, admin_level
- from planet_osm_%s
- where osm_id in (%s,-%s)""" \
- % (table_name,
- entry["osm_id"],entry["osm_id"]))
- result = tuple(set(cursor.fetchall()))
- if len(result) == 1:
- entry["ocitysmap_params"] = dict(table=table_name,
- id=result[0][0],
- admin_level=result[0][1])
- break
+ try:
+ cursor = conn.cursor()
+ for entry in entries:
+ if ( (entry.get("class", None) != "boundary")
+ or (entry.get("type", None) != "administrative") ):
+ continue
+
+ for table_name in ("polygon", "line"):
+ cursor.execute("""select osm_id, admin_level
+ from planet_osm_%s
+ where osm_id in (%s,-%s)""" \
+ % (table_name,
+ entry["osm_id"],entry["osm_id"]))
+ result = tuple(set(cursor.fetchall()))
+ if len(result) == 1:
+ entry["ocitysmap_params"] = dict(table=table_name,
+ id=result[0][0],
+ admin_level=result[0][1])
+ break
+ finally:
+ conn.close()
return entries
--
1.6.3.3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Maposmatic-dev] [PATCH] Cosmetics and better exception-safety for pgsql connection object in nomismatim api.,
David Decotigny <=