mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
SL: Save sl fk in database for point and profile.
This commit is contained in:
1 parent
c5402ebb55
commit
b87977a2d8
5 files changed
+64
-14
No files matched your search
@@ -37,6 +37,17 @@ class PointXYZ(Point, SQLSubModel):
|
||||
@classmethod
|
||||
def _sql_update(cls, execute, version):
|
||||
cls._update_submodel(execute, version)
|
||||
|
||||
major, minor, release = version.strip().split(".")
|
||||
if major == minor == "0":
|
||||
if int(release) < 2:
|
||||
execute(
|
||||
"""
|
||||
ALTER TABLE geometry_pointXYZ
|
||||
ADD COLUMN sl INTEGER
|
||||
REFERENCES sedimentary_layer(id)
|
||||
"""
|
||||
)
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
@@ -47,7 +58,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||
profile = data["profile"]
|
||||
|
||||
table = execute(
|
||||
"SELECT ind, name, x, y, z " +
|
||||
"SELECT ind, name, x, y, z, sl " +
|
||||
"FROM geometry_pointXYZ " +
|
||||
f"WHERE profile = {profile.id}"
|
||||
)
|
||||
@@ -63,6 +74,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||
x = row[2]
|
||||
y = row[3]
|
||||
z = row[4]
|
||||
sl = row[5]
|
||||
|
||||
new = cls(
|
||||
name = name,
|
||||
@@ -71,6 +83,16 @@ class PointXYZ(Point, SQLSubModel):
|
||||
status = status
|
||||
)
|
||||
|
||||
if sl == -1 or sl == None:
|
||||
new._sl = None
|
||||
else:
|
||||
new._sl = next(
|
||||
filter(
|
||||
lambda s: s.id == sl,
|
||||
data["sediment_layers_list"].sediment_layers
|
||||
)
|
||||
)
|
||||
|
||||
points[ind] = new
|
||||
|
||||
return points
|
||||
@@ -79,13 +101,15 @@ class PointXYZ(Point, SQLSubModel):
|
||||
profile = data["profile"]
|
||||
ind = data["ind"]
|
||||
|
||||
sl = self._sl.id if self._sl is not None else -1
|
||||
|
||||
sql = (
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"geometry_pointXYZ(ind, name, x, y, z, profile) "+
|
||||
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) "+
|
||||
"VALUES (" +
|
||||
f"{ind}, '{self._sql_format(self._name)}', " +
|
||||
f"{self.x}, {self.y}, {self.z}, " +
|
||||
f"{profile.id}" +
|
||||
f"{profile.id}, {sl}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
Reference in new issue
Block a user