comparison flys-backend/contrib/shpimporter/utils.py @ 5036:d6860fca89e4 dami

Pull information about the backend into dgm. While the api of cx_oracle and psycopg2 is compatible enough, the query syntax is not :(
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 20 Feb 2013 10:40:07 +0100
parents 769593a84606
children c5187ab9f571
comparison
equal deleted inserted replaced
5035:1f33012cc02a 5036:d6860fca89e4
9 9
10 logger = logging.getLogger("utils") 10 logger = logging.getLogger("utils")
11 11
12 SHP='.shp' 12 SHP='.shp'
13 SQL_SELECT_RIVER_ID="SELECT id FROM rivers WHERE name = %s" 13 SQL_SELECT_RIVER_ID="SELECT id FROM rivers WHERE name = %s"
14 SQL_SELECT_RIVER_ID_ORA="SELECT id FROM rivers WHERE name = :s"
14 15
15 def findShapefiles(path): 16 def findShapefiles(path):
16 shapes = [] 17 shapes = []
17 18
18 for root, dirs, files in os.walk(path): 19 for root, dirs, files in os.walk(path):
26 if (idx+len(SHP)) == len(f): 27 if (idx+len(SHP)) == len(f):
27 shapes.append((f.replace(SHP, ''), root + "/" + f)) 28 shapes.append((f.replace(SHP, ''), root + "/" + f))
28 29
29 return shapes 30 return shapes
30 31
31 def getRiverId(dbconn, name): 32 def getRiverId(dbconn, name, oracle):
32 """ 33 """
33 Returns the id of the river "name" 34 Returns the id of the river "name"
34 Dbconn must be a python database connection api compliant object 35 Dbconn must be a python database connection api compliant object
35 """ 36 """
36 cur = dbconn.cursor() 37 cur = dbconn.cursor()
37 cur.execute(SQL_SELECT_RIVER_ID, (name,)) 38 if oracle:
39 # This is stupid and shoudl not be neccessary. But I don't
40 # know how to make it work both ways. aheinecke - 02/2013
41 stmt = SQL_SELECT_RIVER_ID_ORA
42 else:
43 stmt = SQL_SELECT_RIVER_ID
44 cur.execute(stmt, (name,))
38 row = cur.fetchone() 45 row = cur.fetchone()
39 if row: 46 if row:
40 return row[0] 47 return row[0]
41 else: 48 else:
42 return 0 49 return 0

http://dive4elements.wald.intevation.org