comparison flys-backend/contrib/shpimporter/dgm.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 71e1b96f4794
children 4f46679e13d0
comparison
equal deleted inserted replaced
5035:1f33012cc02a 5036:d6860fca89e4
24 "path" : ("Pfad_Bestand", lambda x: x), 24 "path" : ("Pfad_Bestand", lambda x: x),
25 } 25 }
26 26
27 SQL_INSERT_DGT = "INSERT INTO dem (river_id, " + ", ".join(DGM_MAP.keys()) + \ 27 SQL_INSERT_DGT = "INSERT INTO dem (river_id, " + ", ".join(DGM_MAP.keys()) + \
28 ") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" 28 ") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
29 SQL_INSERT_DGT_ORA = "INSERT INTO dem (river_id, " + ", ".join(DGM_MAP.keys()) + \
30 ") VALUES (:s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s)"
29 31
30 def insertRiverDgm(dbconn, dgmfile, river_name, dry_run): 32 def insertRiverDgm(dbconn, dgmfile, river_name, dry_run, oracle):
31 with codecs.open(dgmfile, "r", "latin1") as csvfile: 33 with codecs.open(dgmfile, "r", "latin1") as csvfile:
32 firstline = csvfile.readline() 34 firstline = csvfile.readline()
33 names = firstline.split(";") 35 names = firstline.split(";")
34 namedict = {} 36 namedict = {}
35 field_nr = 0 37 field_nr = 0
36 for name in names: 38 for name in names:
37 namedict[name] = field_nr 39 namedict[name] = field_nr
38 field_nr += 1 40 field_nr += 1
39 41
40 river_id = utils.getRiverId(dbconn, river_name) 42 river_id = utils.getRiverId(dbconn, river_name, oracle)
41 for line in csvfile: 43 for line in csvfile:
42 fields = line.split(";") 44 fields = line.split(";")
43 if not fields: continue 45 if not fields: continue
44 if fields[namedict[latin("Gewässer")]] != river_name: 46 if fields[namedict[latin("Gewässer")]] != river_name:
45 continue 47 continue
50 values.append(val[1](fields[namedict[val[0]]])) 52 values.append(val[1](fields[namedict[val[0]]]))
51 else: 53 else:
52 values.append(unicode.encode( 54 values.append(unicode.encode(
53 fields[namedict[val]], "UTF-8")) 55 fields[namedict[val]], "UTF-8"))
54 cur = dbconn.cursor() 56 cur = dbconn.cursor()
55 cur.execute(SQL_INSERT_DGT, [river_id] + values) 57 if oracle:
58 stmt = SQL_INSERT_DGT_ORA
59 else:
60 stmt = SQL_INSERT_DGT
61
62 cur.execute(stmt, [river_id] + values)
56 63
57 if not dry_run: 64 if not dry_run:
58 dbconn.commit() 65 dbconn.commit()
59 66

http://dive4elements.wald.intevation.org