syncdb_increment_lifetime_TR.c (2714B)
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 bool no_account; 33 struct GNUNET_PQ_QueryParam params[] = { 34 GNUNET_PQ_query_param_auto_from_type (account_pub), 35 GNUNET_PQ_query_param_string (order_id), 36 GNUNET_PQ_query_param_relative_time (&lifetime), 37 GNUNET_PQ_query_param_timestamp (&now), 38 GNUNET_PQ_query_param_end 39 }; 40 struct GNUNET_PQ_ResultSpec rs[] = { 41 GNUNET_PQ_result_spec_bool ("out_no_payment", 42 &no_payment), 43 GNUNET_PQ_result_spec_bool ("out_no_account", 44 &no_account), 45 GNUNET_PQ_result_spec_end 46 }; 47 enum GNUNET_DB_QueryStatus qs; 48 49 SYNCDB_preflight (); 50 PREPARE ("do_increment_lifetime", 51 "SELECT" 52 " out_no_payment" 53 ",out_no_account" 54 " FROM sync_do_increment_lifetime" 55 " ($1,$2,$3,$4);"); 56 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 57 "do_increment_lifetime", 58 params, 59 rs); 60 switch (qs) 61 { 62 case GNUNET_DB_STATUS_HARD_ERROR: 63 return SYNC_DB_HARD_ERROR; 64 case GNUNET_DB_STATUS_SOFT_ERROR: 65 return SYNC_DB_SOFT_ERROR; 66 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 67 GNUNET_break (0); 68 return SYNC_DB_HARD_ERROR; 69 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 70 if (no_payment) 71 return SYNC_DB_NO_RESULTS; 72 if (no_account) 73 return SYNC_DB_TARGET_MISSING; 74 return SYNC_DB_ONE_RESULT; 75 default: 76 GNUNET_break (0); 77 return SYNC_DB_HARD_ERROR; 78 } 79 } 80 81 82 /* end of syncdb_increment_lifetime_TR.c */