diff 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
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/dgm.py	Wed Feb 20 10:38:17 2013 +0100
+++ b/flys-backend/contrib/shpimporter/dgm.py	Wed Feb 20 10:40:07 2013 +0100
@@ -26,8 +26,10 @@
 
 SQL_INSERT_DGT = "INSERT INTO dem (river_id, " + ", ".join(DGM_MAP.keys()) + \
         ") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
+SQL_INSERT_DGT_ORA = "INSERT INTO dem (river_id, " + ", ".join(DGM_MAP.keys()) + \
+        ") VALUES (:s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s)"
 
-def insertRiverDgm(dbconn, dgmfile, river_name, dry_run):
+def insertRiverDgm(dbconn, dgmfile, river_name, dry_run, oracle):
     with codecs.open(dgmfile, "r", "latin1") as csvfile:
         firstline = csvfile.readline()
         names = firstline.split(";")
@@ -37,7 +39,7 @@
             namedict[name] = field_nr
             field_nr += 1
 
-        river_id = utils.getRiverId(dbconn, river_name)
+        river_id = utils.getRiverId(dbconn, river_name, oracle)
         for line in csvfile:
             fields = line.split(";")
             if not fields: continue
@@ -52,7 +54,12 @@
                         values.append(unicode.encode(
                             fields[namedict[val]], "UTF-8"))
                 cur = dbconn.cursor()
-                cur.execute(SQL_INSERT_DGT, [river_id] + values)
+                if oracle:
+                    stmt = SQL_INSERT_DGT_ORA
+                else:
+                    stmt = SQL_INSERT_DGT
+
+                cur.execute(stmt, [river_id] + values)
 
         if not dry_run:
             dbconn.commit()

http://dive4elements.wald.intevation.org