diff options
author | Sebastian Reichel <sre@ring0.de> | 2022-12-18 16:05:48 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2022-12-18 17:34:50 +0100 |
commit | 1479f8842ac81a8df51ddef2b89be5ecdc046948 (patch) | |
tree | 44819aef9ac49622057892efb81078db1ca251d2 /src | |
parent | 6ba3fe4bf2cd77147c940cbbf1f738b7a7ec6de1 (diff) | |
download | serial-barcode-scanner-master.tar.bz2 |
Diffstat (limited to 'src')
-rw-r--r-- | src/database/database.vala | 21 | ||||
-rw-r--r-- | src/database/db-interface.vala | 1 | ||||
-rw-r--r-- | src/web/web.vala | 7 |
3 files changed, 29 insertions, 0 deletions
diff --git a/src/database/database.vala b/src/database/database.vala index 52c5dd2..b361daf 100644 --- a/src/database/database.vala +++ b/src/database/database.vala @@ -141,6 +141,7 @@ public class DataBase : Object { queries["alias_ean_add"] = "INSERT OR IGNORE INTO ean_aliases (id, real_ean) VALUES (?, ?)"; queries["alias_ean_get"] = "SELECT real_ean FROM ean_aliases WHERE id = ?"; queries["alias_ean_list"] = "SELECT id, real_ean FROM ean_aliases ORDER BY id ASC"; + queries["alias_rev_lookup"] = "SELECT id FROM ean_aliases WHERE real_ean = ?"; queries["userid_rfid"] = "SELECT user FROM rfid_users WHERE rfid = ?"; queries["rfid_userid"] = "SELECT rfid FROM rfid_users WHERE user = ?"; queries["rfid_insert"] = "INSERT OR REPLACE INTO rfid_users ('user','rfid') VALUES (?,?)"; @@ -390,6 +391,26 @@ public class DataBase : Object { } } + public uint64[] get_product_aliases(uint64 article) throws DBusError, IOError, DatabaseError { + statements["alias_rev_lookup"].reset(); + statements["alias_rev_lookup"].bind_text(1, "%llu".printf(article)); + uint64[] result = null; + + while (true) { + int rc = statements["alias_rev_lookup"].step(); + + switch(rc) { + case Sqlite.ROW: + result += statements["alias_rev_lookup"].column_int64(0); + break; + case Sqlite.DONE: + return result; + default: + throw new DatabaseError.INTERNAL_ERROR(_("internal error: %d"), rc); + } + } + } + public string get_product_category(uint64 article) throws DBusError, IOError, DatabaseError { statements["product_category"].reset(); statements["product_category"].bind_text(1, "%llu".printf(article)); diff --git a/src/database/db-interface.vala b/src/database/db-interface.vala index 840f0a8..0db9521 100644 --- a/src/database/db-interface.vala +++ b/src/database/db-interface.vala @@ -22,6 +22,7 @@ public interface Database : Object { public abstract RestockEntry[] get_restocks(uint64 product, bool descending) throws DBusError, IOError; public abstract bool buy(int32 user, uint64 article) throws DBusError, IOError, DatabaseError; public abstract string get_product_name(uint64 article) throws DBusError, IOError, DatabaseError; + public abstract uint64[] get_product_aliases(uint64 article) throws DBusError, IOError, DatabaseError; public abstract string get_product_category(uint64 article) throws DBusError, IOError, DatabaseError; public abstract int get_product_amount(uint64 article) throws DBusError, IOError, DatabaseError; public abstract bool get_product_deprecated(uint64 article) throws DBusError, IOError, DatabaseError; diff --git a/src/web/web.vala b/src/web/web.vala index 0ed852d..414da5c 100644 --- a/src/web/web.vala +++ b/src/web/web.vala @@ -732,6 +732,13 @@ public class WebServer { /* ean */ t.replace("EAN", "%llu".printf(id)); + /* aliases */ + string aliases = ""; + foreach(var a in db.get_product_aliases(id)) { + aliases += "<li>%llu</li>".printf(a); + } + t.replace("ALIASES", aliases); + /* name */ string name = db.get_product_name(id); t.replace("NAME", name); |