[Dive4elements-commits] [PATCH] Do not explicitly set id for ranges and time_intervals

Wald Commits scm-commit at wald.intevation.org
Thu Mar 14 15:01:40 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1363269696 -3600
# Node ID 7d29c277000e18b9e1794a29fea83ca0891c15e1
# Parent  a82b621d87b03c83a84cc3a090a8a4dfdd85ab6e
Do not explicitly set id for ranges and time_intervals

diff -r a82b621d87b0 -r 7d29c277000e flys-backend/contrib/shpimporter/dgm.py
--- a/flys-backend/contrib/shpimporter/dgm.py	Thu Mar 14 14:36:32 2013 +0100
+++ b/flys-backend/contrib/shpimporter/dgm.py	Thu Mar 14 15:01:36 2013 +0100
@@ -34,34 +34,34 @@
 SELECT id FROM time_intervals WHERE start_time = %s AND stop_time = %s
 """
 SQL_INSERT_TIME_ID = """
-INSERT INTO time_intervals (id, start_time, stop_time) VALUES (%s, %s, %s)
+INSERT INTO time_intervals (start_time, stop_time) VALUES (%s, %s)
 """
 SQL_SELECT_TIME_ID_ORA = """
 SELECT id FROM time_intervals WHERE start_time = :s AND stop_time = :s
 """
 SQL_INSERT_TIME_ID_ORA = """
-INSERT INTO time_intervals (id, start_time, stop_time) VALUES (:s, :s, :s)
+INSERT INTO time_intervals (start_time, stop_time) VALUES (:s, :s)
 """
 SQL_SELECT_RANGE_ID = """
 SELECT id FROM ranges WHERE river_id = %s AND a = %s AND b = %s
 """
 SQL_INSERT_RANGE_ID = """
-INSERT INTO ranges (id, river_id, a, b) VALUES (%s, %s, %s, %s)
+INSERT INTO ranges (river_id, a, b) VALUES (%s, %s, %s)
 """
 SQL_SELECT_RANGE_ID_ORA = """
 SELECT id FROM ranges WHERE river_id = :s AND a = :s AND b = :s
 """
 SQL_INSERT_RANGE_ID_ORA = """
-INSERT INTO ranges (id, river_id, a, b) VALUES (:s, :s, :s, :s)
+INSERT INTO ranges (river_id, a, b) VALUES (:s, :s, :s)
 """
-SQL_NEXT_ID     = "SELECT coalesce(max(id), -1) + 1 FROM %s"
+SQL_NEW_ID     = "SELECT max(id) FROM %s"
 
 
 NEXT_IDS = {}
 def next_id(cur, relation):
     idx = NEXT_IDS.get(relation)
     if idx is None:
-        cur.execute(SQL_NEXT_ID % relation)
+        cur.execute(SQL_NEW_ID % relation)
         idx = cur.fetchone()[0]
     NEXT_IDS[relation] = idx + 1
     return idx
@@ -73,13 +73,12 @@
         cur.execute(SQL_SELECT_RANGE_ID, (river_id, a, b))
     row = cur.fetchone()
     if row: return row[0]
-    idx = next_id(cur, "ranges")
     if oracle:
-        cur.execute(SQL_INSERT_RANGE_ID_ORA, (idx, river_id, a, b))
+        cur.execute(SQL_INSERT_RANGE_ID_ORA, (river_id, a, b))
     else:
-        cur.execute(SQL_INSERT_RANGE_ID, (idx, river_id, a, b))
+        cur.execute(SQL_INSERT_RANGE_ID, (river_id, a, b))
     cur.connection.commit()
-    return idx
+    return next_id(cur, "ranges")
 
 def get_time_interval_id(cur, a, b, oracle):
     if not a or not b:
@@ -90,13 +89,12 @@
         cur.execute(SQL_SELECT_TIME_ID, (a, b))
     row = cur.fetchone()
     if row: return row[0]
-    idx = next_id(cur, "time_intervals")
     if oracle:
-        cur.execute(SQL_INSERT_TIME_ID_ORA, (idx, a, b))
+        cur.execute(SQL_INSERT_TIME_ID_ORA, (a, b))
     else:
-        cur.execute(SQL_INSERT_TIME_ID, (idx, a, b))
+        cur.execute(SQL_INSERT_TIME_ID, (a, b))
     cur.connection.commit()
-    return idx
+    return next_id(cur, "time_intervals")
 
 def insertRiverDgm(dbconn, dgmfile, river_name, dry_run, oracle):
     with codecs.open(dgmfile, "r", "latin1") as csvfile:


More information about the Dive4elements-commits mailing list