summaryrefslogtreecommitdiffstats
path: root/src/database/database.vala
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2015-02-16 00:28:02 +0100
committerSebastian Reichel <sre@ring0.de>2015-02-16 00:28:02 +0100
commited197e2a5d7ac73ef21d1c8c1db88fb9ddb5f8ca (patch)
tree893bd75cde8e5a9cee071d483612249d8b079d5b /src/database/database.vala
parent21d2375adf68c62feb19f7d5b93adf94337fe82c (diff)
downloadserial-barcode-scanner-ed197e2a5d7ac73ef21d1c8c1db88fb9ddb5f8ca.tar.bz2
web: support setting product deprecation state
Diffstat (limited to 'src/database/database.vala')
-rw-r--r--src/database/database.vala30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/database/database.vala b/src/database/database.vala
index 9335b35..9c4e495 100644
--- a/src/database/database.vala
+++ b/src/database/database.vala
@@ -83,6 +83,8 @@ public class DataBase : Object {
/* setup queries */
queries["product_name"] = "SELECT name FROM products WHERE id = ?";
queries["product_amount"] = "SELECT amount FROM products WHERE id = ?";
+ queries["product_deprecated"]= "SELECT deprecated FROM products WHERE id = ?";
+ queries["product_set_deprecated"] = "UPDATE products SET deprecated=? WHERE id = ?";
queries["products"] = "SELECT id, name, amount FROM products ORDER BY name";
queries["purchase"] = "INSERT INTO sales ('user', 'product', 'timestamp') VALUES (?, ?, ?)";
queries["last_purchase"] = "SELECT product FROM sales WHERE user = ? ORDER BY timestamp DESC LIMIT 1";
@@ -367,6 +369,34 @@ public class DataBase : Object {
}
}
+ public bool get_product_deprecated(uint64 article) throws DatabaseError {
+ statements["product_deprecated"].reset();
+ statements["product_deprecated"].bind_text(1, "%llu".printf(article));
+
+ int rc = statements["product_deprecated"].step();
+
+ switch(rc) {
+ case Sqlite.ROW:
+ return statements["product_deprecated"].column_int(0) == 1;
+ case Sqlite.DONE:
+ throw new DatabaseError.PRODUCT_NOT_FOUND("unknown product: %llu", article);
+ default:
+ throw new DatabaseError.INTERNAL_ERROR("internal error: %d", rc);
+ }
+ }
+
+ public void product_deprecate(uint64 article, bool value) throws DatabaseError {
+ int rc;
+
+ statements["product_set_deprecated"].reset();
+ statements["product_set_deprecated"].bind_int(1, value ? 1 : 0);
+ statements["product_set_deprecated"].bind_text(2, "%llu".printf(article));
+
+ rc = statements["product_set_deprecated"].step();
+ if(rc != Sqlite.DONE)
+ throw new DatabaseError.INTERNAL_ERROR("internal error: %d", rc);
+ }
+
public Price get_product_price(int user, uint64 article) throws DatabaseError {
int64 timestamp = (new DateTime.now_utc()).to_unix();
bool member = user != 0;