syncdb_update_block_TR.c (5053B)
1 /* 2 This file is part of TALER 3 (C) 2026 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_update_block_TR.c 18 * @brief update contents of a block in the DLL 19 * @author Iván Ávalos 20 */ 21 #include "syncdb_pg.h" 22 23 24 enum SYNC_DB_QueryStatus 25 SYNCDB_update_block_TR ( 26 const struct SYNC_AccountPublicKeyP *account_pub, 27 const struct SYNC_BlockNonce *block_nonce, 28 const struct SYNC_BlockNonce *prev_nonce, 29 const struct SYNC_BlockNonce *next_nonce, 30 const struct GNUNET_HashCode *old_data_hash, 31 const struct GNUNET_HashCode *new_data_hash, 32 size_t data_size, 33 const void *data, 34 unsigned int refs_length, 35 const struct SYNC_ObjectUID *object_uids, 36 const int16_t *object_incs, 37 const struct SYNC_AccountSignatureP *upload_sig, 38 const struct GNUNET_HashCode *refs_hash) 39 { 40 bool account_missing; 41 bool block_missing; 42 bool outdated_write; 43 bool negative_refcount; 44 bool refs_missing; 45 bool updated; 46 bool no_change; 47 bool refs_updated; 48 struct GNUNET_PQ_QueryParam params[] = { 49 GNUNET_PQ_query_param_auto_from_type (account_pub), 50 GNUNET_PQ_query_param_auto_from_type (block_nonce), 51 (NULL != prev_nonce) 52 ? GNUNET_PQ_query_param_auto_from_type (prev_nonce) 53 : GNUNET_PQ_query_param_null (), 54 (NULL != next_nonce) 55 ? GNUNET_PQ_query_param_auto_from_type (next_nonce) 56 : GNUNET_PQ_query_param_null (), 57 GNUNET_PQ_query_param_auto_from_type (old_data_hash), 58 GNUNET_PQ_query_param_auto_from_type (new_data_hash), 59 GNUNET_PQ_query_param_fixed_size (data, 60 data_size), 61 GNUNET_PQ_query_param_array_auto_from_type (refs_length, 62 object_uids, 63 pg->conn), 64 GNUNET_PQ_query_param_array_uint16 (refs_length, 65 (const uint16_t *) object_incs, 66 pg->conn), 67 GNUNET_PQ_query_param_auto_from_type (upload_sig), 68 GNUNET_PQ_query_param_auto_from_type (refs_hash), 69 GNUNET_PQ_query_param_end, 70 }; 71 struct GNUNET_PQ_ResultSpec rs[] = { 72 GNUNET_PQ_result_spec_bool ("out_account_missing", 73 &account_missing), 74 GNUNET_PQ_result_spec_bool ("out_block_missing", 75 &block_missing), 76 GNUNET_PQ_result_spec_bool ("out_outdated_write", 77 &outdated_write), 78 GNUNET_PQ_result_spec_bool ("out_negative_refcount", 79 &negative_refcount), 80 GNUNET_PQ_result_spec_bool ("out_refs_missing", 81 &refs_missing), 82 GNUNET_PQ_result_spec_bool ("out_updated", 83 &updated), 84 GNUNET_PQ_result_spec_bool ("out_no_change", 85 &no_change), 86 GNUNET_PQ_result_spec_bool ("out_refs_updated", 87 &refs_updated), 88 GNUNET_PQ_result_spec_end, 89 }; 90 enum GNUNET_DB_QueryStatus qs; 91 92 SYNCDB_preflight (); 93 PREPARE ("do_update_block", 94 "SELECT" 95 " out_account_missing" 96 ",out_block_missing" 97 ",out_outdated_write" 98 ",out_negative_refcount" 99 ",out_refs_missing" 100 ",out_updated" 101 ",out_no_change" 102 ",out_refs_updated" 103 " FROM sync_do_update_block" 104 " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)"); 105 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 106 "do_update_block", 107 params, 108 rs); 109 110 switch (qs) 111 { 112 case GNUNET_DB_STATUS_HARD_ERROR: 113 return SYNC_DB_HARD_ERROR; 114 case GNUNET_DB_STATUS_SOFT_ERROR: 115 GNUNET_break (0); 116 return SYNC_DB_SOFT_ERROR; 117 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 118 GNUNET_break (0); 119 return SYNC_DB_HARD_ERROR; 120 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 121 if (updated) 122 return SYNC_DB_ONE_RESULT; 123 if (account_missing) 124 return SYNC_DB_PAYMENT_REQUIRED; 125 if (block_missing) 126 return SYNC_DB_TARGET_MISSING; 127 if (outdated_write) 128 return SYNC_DB_OUTDATED_WRITE; 129 if (no_change) 130 return SYNC_DB_NO_RESULTS; 131 if (negative_refcount || refs_missing) 132 return SYNC_DB_INCONSISTENT_BACKUP; 133 GNUNET_break (0); 134 return SYNC_DB_HARD_ERROR; 135 default: 136 GNUNET_break (0); 137 return SYNC_DB_HARD_ERROR; 138 } 139 }