HS: Use section ID instead of RK.

This commit is contained in:
Pierre-Antoine Rouby committed 2024-08-21 11:31:43 +02:00
1 parent 6225f8940e
commit 7f87d22249
7 files changed
+176 -60

No files matched your search

+47 -1
View File
@@ -44,7 +44,7 @@ class SQLModel(SQL):
if exists and is_new:
os.remove(db)
self._db = sqlite3.connect(db)
self._db = sqlite3.connect(db, check_same_thread=False)
self._cur = self._db.cursor()
if is_new:
@@ -244,6 +244,52 @@ class SQLSubModel(PamhyrID):
f"WHERE pamhyr_id = {pid}"
)
@classmethod
def _db_update_to_0_1_1_assoc_section_from_rk(
cls, execute, table,
reach_column="reach",
rk_column="rk",
section_column="section",
origin_version="0.1.0"):
kid = "pamhyr_id"
if origin_version == "0.0.*":
kid = "id"
els = execute(
"SELECT " +
f"{kid}, {reach_column}, {rk_column} " +
f"FROM {table}"
)
for row in els:
it = iter(row)
pid = next(it)
reach_id = next(it)
rk = next(it)
if reach_id == -1 or reach_id is None:
continue
section_id = -1
section = execute(
f"SELECT pamhyr_id FROM geometry_profileXYZ " +
f"WHERE reach == {reach_id} AND rk == {rk}"
)
if len(section) != 0:
section_id = section[0][0]
logger.info(
f"Update reach rk {rk}({reach_id}) to pid {section_id}"
)
execute(
f"UPDATE {table} " +
f"SET {section_column} = {section_id} " +
f"WHERE {kid} = {pid}"
)
@classmethod
def _db_load(cls, execute, data=None):
"""Load instance of this class from SQL data base