mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Model, Geometry: Save and load geometry into SQLite.
This commit is contained in:
1 parent
a4acbdce16
commit
1921889309
7 files changed
+143
-21
No files matched your search
@@ -21,7 +21,8 @@ class PointXYZ(Point, SQLSubModel):
|
||||
def _sql_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE geometry_pointXYZ(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
ind INTEGER NOT NULL,
|
||||
name TEXT,
|
||||
x INTEGER NOT NULL,
|
||||
y INTEGER NOT NULL,
|
||||
@@ -41,9 +42,54 @@ class PointXYZ(Point, SQLSubModel):
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
return None
|
||||
points = []
|
||||
|
||||
status = data["status"]
|
||||
profile = data["profile"]
|
||||
|
||||
table = execute(
|
||||
"SELECT ind, name, x, y, z " +
|
||||
"FROM geometry_pointXYZ " +
|
||||
f"WHERE profile = {profile}"
|
||||
)
|
||||
|
||||
# Create points list
|
||||
for _ in table:
|
||||
points.append(None)
|
||||
|
||||
# Fill points list with new point
|
||||
for row in table:
|
||||
ind = row[0]
|
||||
name = row[1]
|
||||
x = row[2]
|
||||
y = row[3]
|
||||
z = row[4]
|
||||
|
||||
new = cls(
|
||||
name = name,
|
||||
x = x, y = y, z = z,
|
||||
status = status
|
||||
)
|
||||
|
||||
points[ind] = new
|
||||
|
||||
return points
|
||||
|
||||
def _sql_save(self, execute, data = None):
|
||||
profile = data["profile"]
|
||||
ind = data["ind"]
|
||||
|
||||
sql = (
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"geometry_pointXYZ(ind, name, x, y, z, profile) "+
|
||||
"VALUES (" +
|
||||
f"{ind}, '{self._sql_format(self._name)}', " +
|
||||
f"{self.x}, {self.y}, {self.z}, " +
|
||||
f"{profile}" +
|
||||
")"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user