changeset 5352:f1009aa7dcd1

Fix id handling in dgm import
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 20 Mar 2013 17:20:19 +0100
parents 292f00337015
children d086ce6c13d3
files flys-backend/contrib/shpimporter/dgm.py
diffstat 1 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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:

http://dive4elements.wald.intevation.org