syncdb_increment_lifetime_TR.c (2513B)
1 /* 2 This file is part of TALER 3 (C) 2014--2022 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Lesser General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file syncdb/syncdb_increment_lifetime_TR.c 18 * @brief increment account lifetime after payment 19 * @author Christian Grothoff 20 */ 21 #include "syncdb_pg.h" 22 23 24 enum SYNC_DB_QueryStatus 25 SYNCDB_increment_lifetime_TR ( 26 const struct SYNC_AccountPublicKeyP *account_pub, 27 const char *order_id, 28 struct GNUNET_TIME_Relative lifetime) 29 { 30 struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get (); 31 bool no_payment; 32 struct GNUNET_PQ_QueryParam params[] = { 33 GNUNET_PQ_query_param_auto_from_type (account_pub), 34 GNUNET_PQ_query_param_string (order_id), 35 GNUNET_PQ_query_param_relative_time (&lifetime), 36 GNUNET_PQ_query_param_timestamp (&now), 37 GNUNET_PQ_query_param_end 38 }; 39 struct GNUNET_PQ_ResultSpec rs[] = { 40 GNUNET_PQ_result_spec_bool ("out_no_payment", 41 &no_payment), 42 GNUNET_PQ_result_spec_end 43 }; 44 enum GNUNET_DB_QueryStatus qs; 45 46 SYNCDB_preflight (); 47 PREPARE ("do_increment_lifetime", 48 "SELECT" 49 " out_no_payment" 50 " FROM sync_do_increment_lifetime" 51 " ($1,$2,$3,$4);"); 52 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 53 "do_increment_lifetime", 54 params, 55 rs); 56 switch (qs) 57 { 58 case GNUNET_DB_STATUS_HARD_ERROR: 59 return SYNC_DB_HARD_ERROR; 60 case GNUNET_DB_STATUS_SOFT_ERROR: 61 return SYNC_DB_SOFT_ERROR; 62 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 63 GNUNET_break (0); 64 return SYNC_DB_HARD_ERROR; 65 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 66 if (no_payment) 67 return SYNC_DB_NO_RESULTS; 68 return SYNC_DB_ONE_RESULT; 69 default: 70 GNUNET_break (0); 71 return SYNC_DB_HARD_ERROR; 72 } 73 } 74 75 76 /* end of syncdb_increment_lifetime_TR.c */