summaryrefslogtreecommitdiff
path: root/src/backenddb/plugin_merchantdb_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-04-24 20:14:41 +0200
committerChristian Grothoff <christian@grothoff.org>2021-04-24 20:14:41 +0200
commit50f2485ae6ce6e99dcf29712c2008eae17e3ddc3 (patch)
treea6a6456df9edc0d5519ddaa40776accefc5d3241 /src/backenddb/plugin_merchantdb_postgres.c
parent77c92672cd0f83964e8a6992295595653b0f31db (diff)
downloadmerchant-50f2485ae6ce6e99dcf29712c2008eae17e3ddc3.tar.gz
merchant-50f2485ae6ce6e99dcf29712c2008eae17e3ddc3.tar.bz2
merchant-50f2485ae6ce6e99dcf29712c2008eae17e3ddc3.zip
fix product update logic
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index efdfff9a..84c3827e 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1111,14 +1111,16 @@ postgres_update_product (void *cls,
GNUNET_PQ_query_param_string (pd->unit),
GNUNET_PQ_query_param_string (pd->image), /* $6 */
TALER_PQ_query_param_json (pd->taxes),
- TALER_PQ_query_param_amount (&pd->price),
- GNUNET_PQ_query_param_uint64 (&pd->total_stock),
- GNUNET_PQ_query_param_uint64 (&pd->total_lost), /* $10 */
+ TALER_PQ_query_param_amount (&pd->price), /* $8+$9 */
+ GNUNET_PQ_query_param_uint64 (&pd->total_stock), /* $10 */
+ GNUNET_PQ_query_param_uint64 (&pd->total_lost),
+ GNUNET_PQ_query_param_uint64 (&pd->total_sold),
TALER_PQ_query_param_json (pd->address),
GNUNET_PQ_query_param_absolute_time (&pd->next_restock),
GNUNET_PQ_query_param_end
};
+ GNUNET_assert (pd->total_stock >= pd->total_lost + pd->total_sold);
check_connection (pg);
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"update_product",
@@ -6317,17 +6319,18 @@ postgres_connect (void *cls)
",price_frac=$9"
",total_stock=$10"
",total_lost=$11"
- ",address=$12"
- ",next_restock=$13"
+ ",total_sold=$12"
+ ",address=$13"
+ ",next_restock=$14"
" WHERE merchant_serial="
" (SELECT merchant_serial"
" FROM merchant_instances"
" WHERE merchant_id=$1)"
" AND product_id=$2"
" AND total_stock <= $10"
- " AND $10 - total_sold >= $11"
+ " AND total_sold <= $12"
" AND total_lost <= $11",
- 13),
+ 14),
/* for postgres_lock_product() */
GNUNET_PQ_make_prepare ("lock_product",