Line data Source code
1 : /* File: data_database_head.inl; Copyright and License: see below */
2 :
3 : #include "u8/u8_trace.h"
4 : #include "u8/u8_log.h"
5 : #include <assert.h>
6 :
7 : static inline u8_error_t data_database_head_delete_value_by_key ( data_database_head_t *this_,
8 : const char *key,
9 : bool ignore_not_found,
10 : data_head_t *out_old_head )
11 : {
12 : u8_error_t result;
13 : data_head_t head;
14 : result = data_database_head_read_value_by_key( this_, key, &head );
15 : if ( result == U8_ERROR_NONE )
16 : {
17 : if ( out_old_head != NULL )
18 : {
19 : data_head_replace( out_old_head, &head );
20 : }
21 : result |= data_database_head_delete_value( this_, data_head_get_row_id( &head ), NULL );
22 : }
23 : else if ( result == U8_ERROR_NOT_FOUND )
24 : {
25 : if ( out_old_head != NULL )
26 : {
27 : data_head_init_new( out_old_head, key, "" );
28 : }
29 : if ( ignore_not_found )
30 : {
31 : result = U8_ERROR_NONE;
32 : }
33 : }
34 : return result;
35 : }
36 :
37 0 : static inline u8_error_t data_database_head_update_value_by_key ( data_database_head_t *this_,
38 : const char *key,
39 : const char* new_head_value,
40 : bool create_if_not_found,
41 : data_head_t *out_old_head )
42 : {
43 : u8_error_t result;
44 : data_head_t head;
45 0 : result = data_database_head_read_value_by_key( this_, key, &head );
46 0 : if ( result == U8_ERROR_NONE )
47 : {
48 0 : if ( out_old_head != NULL )
49 : {
50 0 : data_head_replace( out_old_head, &head );
51 : }
52 0 : result |= data_database_head_update_value( this_, data_head_get_row_id( &head ), new_head_value, NULL );
53 : }
54 0 : else if ( result == U8_ERROR_NOT_FOUND )
55 : {
56 0 : if ( out_old_head != NULL )
57 : {
58 0 : data_head_init_new( out_old_head, key, "" );
59 : }
60 0 : if ( create_if_not_found )
61 : {
62 0 : result = U8_ERROR_NONE;
63 0 : data_head_init_new( &head, key, "" );
64 0 : result |= data_database_head_create_value( this_, &head, NULL );
65 0 : data_head_destroy( &head );
66 : }
67 : }
68 0 : return result;
69 : }
70 :
71 :
72 : /*
73 : Copyright 2025-2025 Andreas Warnke
74 :
75 : Licensed under the Apache License, Version 2.0 (the "License");
76 : you may not use this file except in compliance with the License.
77 : You may obtain a copy of the License at
78 :
79 : http://www.apache.org/licenses/LICENSE-2.0
80 :
81 : Unless required by applicable law or agreed to in writing, software
82 : distributed under the License is distributed on an "AS IS" BASIS,
83 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
84 : See the License for the specific language governing permissions and
85 : limitations under the License.
86 : */
|