summaryrefslogtreecommitdiff
path: root/src/db/FaceLocationTable.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-06-14 20:36:37 +0200
committerJörg Frings-Fürst <debian@jff.email>2023-06-14 20:36:37 +0200
commitbb80d3feebdc9acc52e3f4ad24084d8425f043a2 (patch)
tree2084a84c39f159c6aea254775dc0880d52579d45 /src/db/FaceLocationTable.vala
parentb26ff0798252a1a8072dd2c7a67f6205de9fde11 (diff)
parent31804433d72460cbe0a39f9f8ea5e76058d84cda (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'src/db/FaceLocationTable.vala')
-rw-r--r--src/db/FaceLocationTable.vala75
1 files changed, 71 insertions, 4 deletions
diff --git a/src/db/FaceLocationTable.vala b/src/db/FaceLocationTable.vala
index 8398616..f4c88d7 100644
--- a/src/db/FaceLocationTable.vala
+++ b/src/db/FaceLocationTable.vala
@@ -27,6 +27,7 @@ public class FaceLocationRow {
public FaceID face_id;
public PhotoID photo_id;
public string geometry;
+ public string vec;
}
public class FaceLocationTable : DatabaseTable {
@@ -42,7 +43,9 @@ public class FaceLocationTable : DatabaseTable {
+ "id INTEGER NOT NULL PRIMARY KEY, "
+ "face_id INTEGER NOT NULL, "
+ "photo_id INTEGER NOT NULL, "
- + "geometry TEXT"
+ + "geometry TEXT, "
+ + "vec TEXT, "
+ + "guess INTEGER DEFAULT 0"
+ ")", -1, out stmt);
assert(res == Sqlite.OK);
@@ -58,10 +61,10 @@ public class FaceLocationTable : DatabaseTable {
return instance;
}
- public FaceLocationRow add(FaceID face_id, PhotoID photo_id, string geometry) throws DatabaseError {
+ public FaceLocationRow add(FaceID face_id, PhotoID photo_id, string geometry, string? vec = null) throws DatabaseError {
Sqlite.Statement stmt;
int res = db.prepare_v2(
- "INSERT INTO FaceLocationTable (face_id, photo_id, geometry) VALUES (?, ?, ?)",
+ "INSERT INTO FaceLocationTable (face_id, photo_id, geometry, vec) VALUES (?, ?, ?, ?)",
-1, out stmt);
assert(res == Sqlite.OK);
@@ -71,6 +74,9 @@ public class FaceLocationTable : DatabaseTable {
assert(res == Sqlite.OK);
res = stmt.bind_text(3, geometry);
assert(res == Sqlite.OK);
+ if (vec == null) vec = "";
+ res = stmt.bind_text(4, vec);
+ assert(res == Sqlite.OK);
res = stmt.step();
if (res != Sqlite.DONE)
@@ -81,6 +87,7 @@ public class FaceLocationTable : DatabaseTable {
row.face_id = face_id;
row.photo_id = photo_id;
row.geometry = geometry;
+ row.vec = vec;
return row;
}
@@ -88,7 +95,7 @@ public class FaceLocationTable : DatabaseTable {
public Gee.List<FaceLocationRow?> get_all_rows() throws DatabaseError {
Sqlite.Statement stmt;
int res = db.prepare_v2(
- "SELECT id, face_id, photo_id, geometry FROM FaceLocationTable",
+ "SELECT id, face_id, photo_id, geometry, vec FROM FaceLocationTable",
-1, out stmt);
assert(res == Sqlite.OK);
@@ -107,6 +114,7 @@ public class FaceLocationTable : DatabaseTable {
row.face_id = FaceID(stmt.column_int64(1));
row.photo_id = PhotoID(stmt.column_int64(2));
row.geometry = stmt.column_text(3);
+ row.vec = stmt.column_text(4);
rows.add(row);
}
@@ -195,4 +203,63 @@ public class FaceLocationTable : DatabaseTable {
if (res != Sqlite.DONE)
throw_error("FaceLocationTable.update_face_location_serialized_geometry", res);
}
+
+ public void update_face_location_face_data(FaceLocation face_location)
+ throws DatabaseError {
+ Sqlite.Statement stmt;
+ int res = db.prepare_v2("UPDATE FaceLocationTable SET geometry=?, vec=? WHERE id=?", -1, out stmt);
+ assert(res == Sqlite.OK);
+
+ FaceLocationData face_data = face_location.get_face_data();
+ res = stmt.bind_text(1, face_data.geometry);
+ assert(res == Sqlite.OK);
+ res = stmt.bind_text(2, face_data.vec);
+ assert(res == Sqlite.OK);
+ res = stmt.bind_int64(3, face_location.get_face_location_id().id);
+ assert(res == Sqlite.OK);
+
+ res = stmt.step();
+ if (res != Sqlite.DONE)
+ throw_error("FaceLocationTable.update_face_location_serialized_geometry", res);
+ }
+ public Gee.List<FaceLocationRow?> get_face_ref_vecs(Gee.List<FaceRow?> face_rows)
+ throws DatabaseError {
+ Sqlite.Statement stmt;
+
+ string[] where_in = {};
+ foreach (var r in face_rows) {
+ if (r != null) where_in += "?";
+ }
+ int res = db.prepare_v2(
+ "SELECT id, face_id, photo_id, geometry, vec FROM FaceLocationTable WHERE photo_id IN (%s)"
+ .printf(string.joinv(",", where_in)),
+ -1, out stmt);
+ assert(res == Sqlite.OK);
+ int c = 1;
+ foreach (var r in face_rows) {
+ if (r != null) {
+ res = stmt.bind_int64(c, r.ref.id);
+ assert(res == Sqlite.OK);
+ }
+ c++;
+ }
+
+ Gee.List<FaceLocationRow?> rows = new Gee.ArrayList<FaceLocationRow?>();
+ for (;;) {
+ res = stmt.step();
+ if (res == Sqlite.DONE)
+ break;
+ else if (res != Sqlite.ROW)
+ throw_error("FaceLocationTable.get_face_ref_vecs", res);
+
+ FaceLocationRow row = new FaceLocationRow();
+ row.face_location_id = FaceLocationID(stmt.column_int64(0));
+ row.face_id = FaceID(stmt.column_int64(1));
+ row.photo_id = PhotoID(stmt.column_int64(2));
+ row.geometry = stmt.column_text(3);
+ row.vec = stmt.column_text(4);
+ rows.add(row);
+ }
+ return rows;
+ }
}