Mercurial > dive4elements > river
changeset 5301:7d29c277000e
Do not explicitly set id for ranges and time_intervals
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 14 Mar 2013 15:01:36 +0100 |
parents | a82b621d87b0 |
children | 71a24278322c |
files | flys-backend/contrib/shpimporter/dgm.py |
diffstat | 1 files changed, 12 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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: