maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH 2/2] Slightly more robust city name query


From: David Decotigny
Subject: [Maposmatic-dev] [PATCH 2/2] Slightly more robust city name query
Date: Sun, 20 Dec 2009 01:11:37 +0100

This will make sure the connection object is closed when done with the
query
---
 www/maposmatic/views.py |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/www/maposmatic/views.py b/www/maposmatic/views.py
index ac6663c..739a785 100644
--- a/www/maposmatic/views.py
+++ b/www/maposmatic/views.py
@@ -69,14 +69,18 @@ def city_exists(city):
     except psycopg2.OperationalError:
         return False
 
-    cursor = conn.cursor()
-    cursor.execute("""select count(*) from planet_osm_line where
+    try:
+        cursor = conn.cursor()
+        cursor.execute("""select count(*) from planet_osm_line where
                         boundary='administrative' and
                         admin_level='8' and
                         name=%s""",
-                   (city,))
-    result = cursor.fetchall()
-    return (result[0][0] == 1)
+                       (city,))
+        result = cursor.fetchall()
+        return (result[0][0] == 1)
+    finally:
+        conn.close()
+
 
 class MapRenderingJobForm(ModelForm):
     class Meta:
-- 
1.6.3.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]