aboutsummaryrefslogtreecommitdiff
path: root/src/backenddb/pg_lookup_product.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-05-26 15:21:50 +0200
committerChristian Grothoff <christian@grothoff.org>2024-05-26 15:21:50 +0200
commitc4936ee74300fd2a8503530a3aa8c43cf04b455c (patch)
tree51831f4f21c597603cf13bae267e622250305e16 /src/backenddb/pg_lookup_product.c
parentffdfeb863a03cc2cf9a92731f7b44b0c058d6a2d (diff)
-finish implementation of protocol v16, still undertested
Diffstat (limited to 'src/backenddb/pg_lookup_product.c')
-rw-r--r--src/backenddb/pg_lookup_product.c57
1 files changed, 36 insertions, 21 deletions
diff --git a/src/backenddb/pg_lookup_product.c b/src/backenddb/pg_lookup_product.c
index a078cf8e..2948e6ca 100644
--- a/src/backenddb/pg_lookup_product.c
+++ b/src/backenddb/pg_lookup_product.c
@@ -29,7 +29,9 @@ enum GNUNET_DB_QueryStatus
TMH_PG_lookup_product (void *cls,
const char *instance_id,
const char *product_id,
- struct TALER_MERCHANTDB_ProductDetails *pd)
+ struct TALER_MERCHANTDB_ProductDetails *pd,
+ size_t *num_categories,
+ uint64_t **categories)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
@@ -38,6 +40,35 @@ TMH_PG_lookup_product (void *cls,
GNUNET_PQ_query_param_end
};
+ PREPARE (pg,
+ "lookup_product",
+ "SELECT"
+ " mi.description"
+ ",mi.description_i18n"
+ ",mi.unit"
+ ",mi.price"
+ ",mi.taxes"
+ ",mi.total_stock"
+ ",mi.total_sold"
+ ",mi.total_lost"
+ ",mi.image"
+ ",mi.address"
+ ",mi.next_restock"
+ ",mi.minimum_age"
+ ",t.category_array AS categories"
+ " FROM merchant_inventory mi"
+ " JOIN merchant_instances inst"
+ " USING (merchant_serial)"
+ ",LATERAL ("
+ " SELECT ARRAY ("
+ " SELECT mpc.category_serial"
+ " FROM merchant_product_categories mpc"
+ " WHERE mpc.product_serial = mi.product_serial"
+ " ) AS category_array"
+ " ) t"
+ " WHERE inst.merchant_id=$1"
+ " AND mi.product_id=$2"
+ );
if (NULL == pd)
{
struct GNUNET_PQ_ResultSpec rs_null[] = {
@@ -77,30 +108,14 @@ TMH_PG_lookup_product (void *cls,
&pd->next_restock),
GNUNET_PQ_result_spec_uint32 ("minimum_age",
&pd->minimum_age),
+ GNUNET_PQ_result_spec_array_uint64 (pg->conn,
+ "categories",
+ num_categories,
+ categories),
GNUNET_PQ_result_spec_end
};
check_connection (pg);
- PREPARE (pg,
- "lookup_product",
- "SELECT"
- " description"
- ",description_i18n"
- ",unit"
- ",price"
- ",taxes"
- ",total_stock"
- ",total_sold"
- ",total_lost"
- ",image"
- ",merchant_inventory.address"
- ",next_restock"
- ",minimum_age"
- " FROM merchant_inventory"
- " JOIN merchant_instances"
- " USING (merchant_serial)"
- " WHERE merchant_instances.merchant_id=$1"
- " AND merchant_inventory.product_id=$2");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"lookup_product",
params,