[Dive4elements-commits] [PATCH 3 of 3] Fix id handling in dgm import

Wald Commits scm-commit at wald.intevation.org
Wed Mar 20 17:20:25 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1363796419 -3600
# Node ID f1009aa7dcd1d87ca3bdbe9bf87e2ebab45ee938
# Parent  292f003370154bd9cc7c80931d5db7b1a4ffeb6c
Fix id handling in dgm import

diff -r 292f00337015 -r f1009aa7dcd1 flys-backend/contrib/shpimporter/dgm.py
--- a/flys-backend/contrib/shpimporter/dgm.py	Wed Mar 20 17:07:52 2013 +0100
+++ b/flys-backend/contrib/shpimporter/dgm.py	Wed Mar 20 17:20:19 2013 +0100
@@ -54,16 +54,15 @@
 SQL_INSERT_RANGE_ID_ORA = """
 INSERT INTO ranges (id, river_id, a, b) VALUES (:s, :s, :s, :s)
 """
-SQL_NEXT_ID     = "SELECT coalesce(max(id), -1) + 1 FROM %s"
+SQL_NEXT_ID     = "select nextval('%s_ID_SEQ')"
+SQL_NEXT_ID_ORA = "select %s_ID_SEQ.nextval FROM dual"
 
-
-NEXT_IDS = {}
-def next_id(cur, relation):
-    idx = NEXT_IDS.get(relation)
-    if idx is None:
-        cur.execute(SQL_NEXT_ID % relation)
-        idx = cur.fetchone()[0]
-    NEXT_IDS[relation] = idx + 1
+def next_id(cur, relation, oracle):
+    if oracle:
+        cur.execute(SQL_NEXT_ID_ORA % relation.upper())
+    else:
+        cur.execute(SQL_NEXT_ID % relation.upper())
+    idx = cur.fetchone()[0]
     return idx
 
 def get_range_id(cur, river_id, a, b, oracle):
@@ -73,7 +72,7 @@
         cur.execute(SQL_SELECT_RANGE_ID, (river_id, a, b))
     row = cur.fetchone()
     if row: return row[0]
-    idx = next_id(cur, "ranges")
+    idx = next_id(cur, "ranges", oracle)
     if oracle:
         cur.execute(SQL_INSERT_RANGE_ID_ORA, (idx, river_id, a, b))
     else:
@@ -90,7 +89,7 @@
         cur.execute(SQL_SELECT_TIME_ID, (a, b))
     row = cur.fetchone()
     if row: return row[0]
-    idx = next_id(cur, "time_intervals")
+    idx = next_id(cur, "time_intervals", oracle)
     if oracle:
         cur.execute(SQL_INSERT_TIME_ID_ORA, (idx, a, b))
     else:


More information about the Dive4elements-commits mailing list