summaryrefslogtreecommitdiff
path: root/src/db/FaceTable.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-06-14 20:35:58 +0200
committerJörg Frings-Fürst <debian@jff.email>2023-06-14 20:35:58 +0200
commitd443a3c2509889533ca812c163056bace396b586 (patch)
treee94ffc0d9c054ca4efb8fb327e18dfac88e15dc7 /src/db/FaceTable.vala
parentbb9797c14470641b082ebf635e2ae3cfd5f27a3b (diff)
New upstream version 0.32.1upstream/0.32.1
Diffstat (limited to 'src/db/FaceTable.vala')
-rw-r--r--src/db/FaceTable.vala56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/db/FaceTable.vala b/src/db/FaceTable.vala
index 4836910..e799f97 100644
--- a/src/db/FaceTable.vala
+++ b/src/db/FaceTable.vala
@@ -25,7 +25,9 @@ public struct FaceID {
public class FaceRow {
public FaceID face_id;
public string name;
- public time_t time_created;
+ public int64 time_created;
+ public PhotoID ref;
+ public string vec;
}
public class FaceTable : DatabaseTable {
@@ -40,7 +42,8 @@ public class FaceTable : DatabaseTable {
+ "("
+ "id INTEGER NOT NULL PRIMARY KEY, "
+ "name TEXT NOT NULL, "
- + "time_created TIMESTAMP"
+ + "time_created TIMESTAMP, "
+ + "ref INTEGER DEFAULT -1"
+ ")", -1, out stmt);
assert(res == Sqlite.OK);
@@ -62,7 +65,7 @@ public class FaceTable : DatabaseTable {
out stmt);
assert(res == Sqlite.OK);
- time_t time_created = (time_t) now_sec();
+ var time_created = now_sec();
res = stmt.bind_text(1, name);
assert(res == Sqlite.OK);
@@ -129,7 +132,7 @@ public class FaceTable : DatabaseTable {
FaceRow row = new FaceRow();
row.face_id = face_id;
row.name = stmt.column_text(0);
- row.time_created = (time_t) stmt.column_int64(1);
+ row.time_created = stmt.column_int64(1);
return row;
}
@@ -153,7 +156,7 @@ public class FaceTable : DatabaseTable {
FaceRow row = new FaceRow();
row.face_id = FaceID(stmt.column_int64(0));
row.name = stmt.column_text(1);
- row.time_created = (time_t) stmt.column_int64(2);
+ row.time_created = stmt.column_int64(2);
rows.add(row);
}
@@ -164,4 +167,47 @@ public class FaceTable : DatabaseTable {
public void rename(FaceID face_id, string new_name) throws DatabaseError {
update_text_by_id_2(face_id.id, "name", new_name);
}
+
+ public void set_reference(FaceID face_id, PhotoID photo_id)
+ throws DatabaseError {
+ Sqlite.Statement stmt;
+ int res = db.prepare_v2("UPDATE FaceTable SET ref=? WHERE id=?", -1, out stmt);
+ assert(res == Sqlite.OK);
+ res = stmt.bind_int64(1, photo_id.id);
+ assert(res == Sqlite.OK);
+ res = stmt.bind_int64(2, face_id.id);
+ assert(res == Sqlite.OK);
+
+ res = stmt.step();
+ if (res != Sqlite.DONE)
+ throw_error("FaceTable.set_reference", res);
+ }
+
+ public Gee.List<FaceRow?> get_ref_rows() throws DatabaseError {
+ Sqlite.Statement stmt;
+ int res = db.prepare_v2("SELECT id, name, time_created, ref FROM FaceTable WHERE ref != -1", -1,
+ out stmt);
+ assert(res == Sqlite.OK);
+
+ Gee.List<FaceRow?> rows = new Gee.ArrayList<FaceRow?>();
+
+ for (;;) {
+ res = stmt.step();
+ if (res == Sqlite.DONE)
+ break;
+ else if (res != Sqlite.ROW)
+ throw_error("FaceTable.get_all_rows", res);
+
+ // res == Sqlite.ROW
+ FaceRow row = new FaceRow();
+ row.face_id = FaceID(stmt.column_int64(0));
+ row.name = stmt.column_text(1);
+ row.time_created = stmt.column_int64(2);
+ row.ref = PhotoID(stmt.column_int64(3));
+
+ rows.add(row);
+ }
+
+ return rows;
+ }
}