diff options
Diffstat (limited to 'src/backenddb/pg_lookup_orders.c')
-rw-r--r-- | src/backenddb/pg_lookup_orders.c | 1520 |
1 files changed, 760 insertions, 760 deletions
diff --git a/src/backenddb/pg_lookup_orders.c b/src/backenddb/pg_lookup_orders.c index 437ca8ca..48f1514e 100644 --- a/src/backenddb/pg_lookup_orders.c +++ b/src/backenddb/pg_lookup_orders.c @@ -139,782 +139,782 @@ TMH_PG_lookup_orders (void *cls, "_refunded", (TALER_EXCHANGE_YNA_ALL == of->wired) ? "" : "_wired"); PREPARE (pg, - "lookup_orders_inc", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " ORDER BY order_serial ASC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " ORDER BY order_serial ASC" - " LIMIT $2)" - " ORDER BY order_serial ASC" - " LIMIT $2"); + "lookup_orders_inc", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " ORDER BY order_serial ASC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " ORDER BY order_serial ASC" + " LIMIT $2)" + " ORDER BY order_serial ASC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_inc_paid", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial ASC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " BOOL($5) = paid" - " ORDER BY order_serial ASC" - " LIMIT $2)" - " ORDER BY order_serial ASC" - " LIMIT $2"); + "lookup_orders_inc_paid", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial ASC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " BOOL($5) = paid" + " ORDER BY order_serial ASC" + " LIMIT $2)" + " ORDER BY order_serial ASC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_inc_refunded", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial ASC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " CAST($6 as BOOL) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))" - " ORDER BY order_serial ASC" - " LIMIT $2)" - " ORDER BY order_serial ASC" - " LIMIT $2"); + "lookup_orders_inc_refunded", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial ASC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " CAST($6 as BOOL) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))" + " ORDER BY order_serial ASC" + " LIMIT $2)" + " ORDER BY order_serial ASC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_inc_wired", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial ASC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " BOOL($7) = wired" - " ORDER BY order_serial ASC" - " LIMIT $2)" - " ORDER BY order_serial ASC" - " LIMIT $2"); + "lookup_orders_inc_wired", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial ASC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " BOOL($7) = wired" + " ORDER BY order_serial ASC" + " LIMIT $2)" + " ORDER BY order_serial ASC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_inc_paid_refunded", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ - " AND" - " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial ASC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " BOOL($5) = paid" - " AND" - " BOOL($6) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))" - " ORDER BY order_serial ASC" - " LIMIT $2)" - " ORDER BY order_serial ASC" - " LIMIT $2"); + "lookup_orders_inc_paid_refunded", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ + " AND" + " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial ASC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " BOOL($5) = paid" + " AND" + " BOOL($6) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))" + " ORDER BY order_serial ASC" + " LIMIT $2)" + " ORDER BY order_serial ASC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_inc_paid_wired", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ - " AND" - " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial ASC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " BOOL($5) = paid" - " AND" - " BOOL($7) = wired" - " ORDER BY order_serial ASC" - " LIMIT $2)" - " ORDER BY order_serial ASC" - " LIMIT $2"); + "lookup_orders_inc_paid_wired", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ + " AND" + " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial ASC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " BOOL($5) = paid" + " AND" + " BOOL($7) = wired" + " ORDER BY order_serial ASC" + " LIMIT $2)" + " ORDER BY order_serial ASC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_inc_refunded_wired", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ - " AND" - " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial ASC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " BOOL($6) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))" - " AND" - " BOOL($7) = wired" - " ORDER BY order_serial ASC" - " LIMIT $2)" - " ORDER BY order_serial ASC" - " LIMIT $2"); + "lookup_orders_inc_refunded_wired", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ + " AND" + " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial ASC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " BOOL($6) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))" + " AND" + " BOOL($7) = wired" + " ORDER BY order_serial ASC" + " LIMIT $2)" + " ORDER BY order_serial ASC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_inc_paid_refunded_wired", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ - " AND" - " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ - " AND" - " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial ASC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial > $3" - " AND" - " creation_time > $4" - " AND" - " BOOL($5) = paid" - " AND" - " BOOL($6) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))" - " AND" - " BOOL($7) = wired" - " ORDER BY order_serial ASC" - " LIMIT $2)" - " ORDER BY order_serial ASC" - " LIMIT $2"); + "lookup_orders_inc_paid_refunded_wired", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ + " AND" + " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ + " AND" + " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial ASC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial > $3" + " AND" + " creation_time > $4" + " AND" + " BOOL($5) = paid" + " AND" + " BOOL($6) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))" + " AND" + " BOOL($7) = wired" + " ORDER BY order_serial ASC" + " LIMIT $2)" + " ORDER BY order_serial ASC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_dec", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " ORDER BY order_serial DESC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " ORDER BY order_serial DESC" - " LIMIT $2)" - " ORDER BY order_serial DESC" - " LIMIT $2"); + "lookup_orders_dec", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " ORDER BY order_serial DESC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " ORDER BY order_serial DESC" + " LIMIT $2)" + " ORDER BY order_serial DESC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_dec_paid", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial DESC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " BOOL($5) = paid" - " ORDER BY order_serial DESC" - " LIMIT $2)" - " ORDER BY order_serial DESC" - " LIMIT $2"); + "lookup_orders_dec_paid", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial DESC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " BOOL($5) = paid" + " ORDER BY order_serial DESC" + " LIMIT $2)" + " ORDER BY order_serial DESC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_dec_refunded", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial DESC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " BOOL($6) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))" - " ORDER BY order_serial DESC" - " LIMIT $2)" - " ORDER BY order_serial DESC" - " LIMIT $2"); + "lookup_orders_dec_refunded", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial DESC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " BOOL($6) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))" + " ORDER BY order_serial DESC" + " LIMIT $2)" + " ORDER BY order_serial DESC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_dec_wired", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial DESC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " BOOL($7) = wired" - " ORDER BY order_serial DESC" - " LIMIT $2)" - " ORDER BY order_serial DESC" - " LIMIT $2"); + "lookup_orders_dec_wired", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial DESC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " BOOL($7) = wired" + " ORDER BY order_serial DESC" + " LIMIT $2)" + " ORDER BY order_serial DESC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_dec_paid_refunded", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ - " AND" - " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial DESC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " BOOL($5) = paid" - " AND" - " BOOL($6) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))" - " ORDER BY order_serial DESC" - " LIMIT $2)" - " ORDER BY order_serial DESC" - " LIMIT $2"); + "lookup_orders_dec_paid_refunded", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ + " AND" + " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial DESC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " BOOL($5) = paid" + " AND" + " BOOL($6) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))" + " ORDER BY order_serial DESC" + " LIMIT $2)" + " ORDER BY order_serial DESC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_dec_paid_wired", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ - " AND" - " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial DESC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " BOOL($5) = paid" - " AND" - " BOOL($7) = wired" - " ORDER BY order_serial DESC" - " LIMIT $2)" - " ORDER BY order_serial DESC" - " LIMIT $2"); + "lookup_orders_dec_paid_wired", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ + " AND" + " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial DESC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($6 as BOOL)" /* otherwise $6 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " BOOL($5) = paid" + " AND" + " BOOL($7) = wired" + " ORDER BY order_serial DESC" + " LIMIT $2)" + " ORDER BY order_serial DESC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_dec_refunded_wired", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ - " AND" - " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial DESC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " BOOL($6) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))" - " AND" - " BOOL($7) = wired" - " ORDER BY order_serial DESC" - " LIMIT $2)" - " ORDER BY order_serial DESC" - " LIMIT $2"); + "lookup_orders_dec_refunded_wired", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ + " AND" + " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial DESC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " BOOL($6) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))" + " AND" + " BOOL($7) = wired" + " ORDER BY order_serial DESC" + " LIMIT $2)" + " ORDER BY order_serial DESC" + " LIMIT $2"); PREPARE (pg, - "lookup_orders_dec_paid_refunded_wired", - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - " FROM merchant_orders" - " WHERE merchant_orders.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ - " AND" - " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ - " AND" - " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " ORDER BY order_serial DESC" - " LIMIT $2)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - " FROM merchant_contract_terms" - " WHERE merchant_contract_terms.merchant_serial=" - " (SELECT merchant_serial " - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " order_serial < $3" - " AND" - " creation_time < $4" - " AND" - " BOOL($5) = paid" - " AND" - " BOOL($6) = (order_serial IN" - " (SELECT order_serial " + "lookup_orders_dec_paid_refunded_wired", + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + " FROM merchant_orders" + " WHERE merchant_orders.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " NOT CAST($5 as BOOL)" /* unclaimed orders are never paid */ + " AND" + " NOT CAST($6 as BOOL)"/* unclaimed orders are never refunded */ + " AND" + " NOT CAST($7 as BOOL)" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " ORDER BY order_serial DESC" + " LIMIT $2)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + " FROM merchant_contract_terms" + " WHERE merchant_contract_terms.merchant_serial=" + " (SELECT merchant_serial " + " FROM merchant_instances" + " WHERE merchant_id=$1)" + " AND" + " order_serial < $3" + " AND" + " creation_time < $4" + " AND" + " BOOL($5) = paid" + " AND" + " BOOL($6) = (order_serial IN" + " (SELECT order_serial " - " FROM merchant_refunds))" - " AND" - " BOOL($7) = wired" - " ORDER BY order_serial DESC" - " LIMIT $2)" - " ORDER BY order_serial DESC" - " LIMIT $2"); + " FROM merchant_refunds))" + " AND" + " BOOL($7) = wired" + " ORDER BY order_serial DESC" + " LIMIT $2)" + " ORDER BY order_serial DESC" + " LIMIT $2"); qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, stmt, params, |