Model, Geometry: Save and load geometry into SQLite.

This commit is contained in:
Pierre-Antoine Rouby committed 2023-06-30 10:38:55 +02:00
1 parent a4acbdce16
commit 1921889309
7 files changed
+143 -21

No files matched your search

+48 -2
View File
@@ -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