diff --git a/src/Model/InitialConditions/InitialConditions.py b/src/Model/InitialConditions/InitialConditions.py index 9b2264879009d420618c3cb568b8fe6cf31ada63..bb106662d485005854d93327de781e3c133f7c04 100644 --- a/src/Model/InitialConditions/InitialConditions.py +++ b/src/Model/InitialConditions/InitialConditions.py @@ -169,7 +169,7 @@ class Data(SQLSubModel): def _update_from_discharge(self): min = self._update_get_min() - print("TODO") + # print("TODO") def __setitem__(self, key, value): if key == "name": diff --git a/src/Model/River.py b/src/Model/River.py index f1aaa613efdda5b31cffab542b58c3dd15eea780..9f5505ade0f43199e4b82ec0244969760846207d 100644 --- a/src/Model/River.py +++ b/src/Model/River.py @@ -170,6 +170,8 @@ class RiverReach(Edge, SQLSubModel): if data is None: data = {} + data["reach"] = self + objs = [self._reach, self._sections] return self._save_submodel(execute, objs, data) diff --git a/src/Model/Section/Section.py b/src/Model/Section/Section.py index 82bd454bc0bf6dd4ddc50a435a8446603ea83da8..86bdff48ffa00e9b656411dbf98c7248823f43e1 100644 --- a/src/Model/Section/Section.py +++ b/src/Model/Section/Section.py @@ -57,9 +57,11 @@ class Section(SQLSubModel): for row in table: ind = row[0] + # Get stricklers bs = next(filter(lambda s: s.id == row[3], stricklers)) es = next(filter(lambda s: s.id == row[4], stricklers)) + # Create section sec = cls(status = status) sec.edge = reach sec.begin_kp = row[1] @@ -74,7 +76,7 @@ class Section(SQLSubModel): def _sql_save(self, execute, data = None): ind = data["ind"] execute( - "INSERT OR REPLACE INTO " + + "INSERT INTO " + "section(ind, begin_kp, end_kp, reach, begin_strickler, end_strickler) " + "VALUES (" + f"{ind}, {self._begin_kp}, {self._end_kp}, " + diff --git a/src/Model/Section/SectionList.py b/src/Model/Section/SectionList.py index 0f018f66a214cd422d05cae3bb4726c25aaebb26..d1f88f0899aa24da0b5972905a45ac99211af0dd 100644 --- a/src/Model/Section/SectionList.py +++ b/src/Model/Section/SectionList.py @@ -36,6 +36,9 @@ class SectionList(SQLSubModel): return new def _sql_save(self, execute, data = None): + reach = data["reach"] + execute(f"DELETE FROM section WHERE reach = {reach.id}") + ok = True ind = 0 for section in self._sections: diff --git a/src/tools.py b/src/tools.py index 27127754b67592bc3170b8dfba83671896008e58..34c4b9b237b4023282ae410924bdd12ed706acd8 100644 --- a/src/tools.py +++ b/src/tools.py @@ -233,7 +233,7 @@ class SQL(object): @timer def execute(self, cmd, fetch_one = True, commit = False): - print(f"[SQL] {cmd}") + # print(f"[SQL] {cmd}") res = self._cur.execute(cmd) if commit: