Mercurial > dive4elements > river
comparison flys-backend/contrib/shpimporter/utils.py @ 4976:a6ee62a070b0 dami
I'm learning how to use cursors \o/
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 13 Feb 2013 17:49:30 +0100 |
parents | 174fbaa3d344 |
children | 998b29c8d2fd |
comparison
equal
deleted
inserted
replaced
4975:9eea3cd22ee7 | 4976:a6ee62a070b0 |
---|---|
5 from osgeo import ogr | 5 from osgeo import ogr |
6 except ImportErrror: | 6 except ImportErrror: |
7 import ogr | 7 import ogr |
8 | 8 |
9 SHP='.shp' | 9 SHP='.shp' |
10 SQL_SELECT_ID="SELECT id FROM %s WHERE %s = '%s'" | 10 SQL_SELECT_RIVER_ID="SELECT id FROM rivers WHERE name = %s" |
11 | 11 |
12 def findShapefiles(path): | 12 def findShapefiles(path): |
13 shapes = [] | 13 shapes = [] |
14 | 14 |
15 for root, dirs, files in os.walk(path): | 15 for root, dirs, files in os.walk(path): |
29 """ | 29 """ |
30 Returns the id of the river "name" | 30 Returns the id of the river "name" |
31 Dbconn must be a python database connection api compliant object | 31 Dbconn must be a python database connection api compliant object |
32 """ | 32 """ |
33 cur = dbconn.cursor() | 33 cur = dbconn.cursor() |
34 select_stmt = SQL_SELECT_ID % ("rivers", "name", name) | 34 cur.execute(SQL_SELECT_RIVER_ID, (name,)) |
35 cur.execute(select_stmt) | |
36 row = cur.fetchone() | 35 row = cur.fetchone() |
37 if row: | 36 if row: |
38 return row[0] | 37 return row[0] |
39 else: | 38 else: |
40 return 0 | 39 return 0 |