experimental fix to #6452: merge two SQL statements into one
This commit is contained in:
parent
a97983ddb1
commit
6503a9fe35
@ -399,6 +399,30 @@ postgres_get_session (void *cls)
|
|||||||
" WHERE"
|
" WHERE"
|
||||||
" reserve_pub=$5;",
|
" reserve_pub=$5;",
|
||||||
5),
|
5),
|
||||||
|
/* Used in #insert_withdraw_info() when coins are withdrawn from the reserve */
|
||||||
|
GNUNET_PQ_make_prepare ("reserve_reduce",
|
||||||
|
"UPDATE reserves"
|
||||||
|
" SET"
|
||||||
|
" gc_date="
|
||||||
|
" CASE WHEN (reserves.gc_date > $2)"
|
||||||
|
" THEN reserves.gc_date"
|
||||||
|
" ELSE $2"
|
||||||
|
" END"
|
||||||
|
",current_balance_val="
|
||||||
|
" CASE WHEN (reserves.current_balance_frac >= $4)"
|
||||||
|
" THEN reserves.current_balance_val - $3"
|
||||||
|
" ELSE reserves.current_balance_val - $3 - 1"
|
||||||
|
" END"
|
||||||
|
",current_balance_frac="
|
||||||
|
" CASE WHEN (reserves.current_balance_frac >= $4)"
|
||||||
|
" THEN reserves.current_balance_frac - $4"
|
||||||
|
" ELSE 100000000 + reserves.current_balance_frac - $4"
|
||||||
|
" END"
|
||||||
|
" WHERE reserve_pub=$1"
|
||||||
|
" AND current_balance_val >= $3"
|
||||||
|
" AND ( (current_balance_frac >= $4) OR"
|
||||||
|
" (current_balance_val > $3) )",
|
||||||
|
4),
|
||||||
/* Used in #postgres_reserves_in_insert() to store transaction details */
|
/* Used in #postgres_reserves_in_insert() to store transaction details */
|
||||||
GNUNET_PQ_make_prepare ("reserves_in_add_transaction",
|
GNUNET_PQ_make_prepare ("reserves_in_add_transaction",
|
||||||
"INSERT INTO reserves_in "
|
"INSERT INTO reserves_in "
|
||||||
@ -2154,6 +2178,7 @@ postgres_insert_withdraw_info (
|
|||||||
return qs;
|
return qs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* update reserve balance */
|
/* update reserve balance */
|
||||||
reserve.pub = collectable->reserve_pub;
|
reserve.pub = collectable->reserve_pub;
|
||||||
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
|
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
|
||||||
@ -2178,7 +2203,7 @@ postgres_insert_withdraw_info (
|
|||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"Withdrawal from reserve `%s' refused due to balance mismatch. Retrying.\n",
|
"Withdrawal from reserve `%s' refused due to balance mismatch. Retrying.\n",
|
||||||
TALER_B2S (&collectable->reserve_pub));
|
TALER_B2S (&collectable->reserve_pub));
|
||||||
return GNUNET_DB_STATUS_SOFT_ERROR;
|
return GNUNET_DB_STATUS_SOFT_ERROR; // FIXME: really soft error? would retry help!?
|
||||||
}
|
}
|
||||||
expiry = GNUNET_TIME_absolute_add (now,
|
expiry = GNUNET_TIME_absolute_add (now,
|
||||||
pg->legal_reserve_expiration_time);
|
pg->legal_reserve_expiration_time);
|
||||||
@ -2194,6 +2219,30 @@ postgres_insert_withdraw_info (
|
|||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
qs = GNUNET_DB_STATUS_HARD_ERROR;
|
qs = GNUNET_DB_STATUS_HARD_ERROR;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
|
GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_pub),
|
||||||
|
TALER_PQ_query_param_absolute_time (&expiry),
|
||||||
|
TALER_PQ_query_param_amount (&collectable->amount_with_fee),
|
||||||
|
GNUNET_PQ_query_param_end
|
||||||
|
};
|
||||||
|
|
||||||
|
expiry = GNUNET_TIME_absolute_add (now,
|
||||||
|
pg->legal_reserve_expiration_time);
|
||||||
|
qs = GNUNET_PQ_eval_prepared_non_select (session->conn,
|
||||||
|
"reserve_reduce",
|
||||||
|
params);
|
||||||
|
if (0 == qs)
|
||||||
|
{
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
|
"Withdrawal from reserve `%s' refused due to balance mismatch.\n",
|
||||||
|
TALER_B2S (&collectable->reserve_pub));
|
||||||
|
return GNUNET_DB_STATUS_HARD_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
return qs;
|
return qs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user