From d443a3c2509889533ca812c163056bace396b586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 14 Jun 2023 20:35:58 +0200 Subject: New upstream version 0.32.1 --- src/db/FaceTable.vala | 56 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'src/db/FaceTable.vala') 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 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 rows = new Gee.ArrayList(); + + 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; + } } -- cgit v1.2.3