1 /* 2 Copyright (C) 2015-2021, Dirk Krause 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by the dkct program (see 8 http://dktools.sourceforge.net/ for details). 9 Changes you make here will be lost if dkct is run again! 10 You should modify the original source and run dkct on it. 11 Original source: dk4dbit.ctr 12 */ 13 14 #ifndef DK4DBIT_H_INCLUDED 15 /** Avoid multiple inclusions. */ 16 #define DK4DBIT_H_INCLUDED 1 17 18 19 /** @file dk4dbit.h Text (dkChar) in database. 20 */ 21 22 #ifndef DK4CONF_H_INCLUDED 23 #if DK4_BUILDING_DKTOOLS4 24 #include "dk4conf.h" 25 #else 26 #include <dktools-4/dk4conf.h> 27 #endif 28 #endif 29 30 #ifndef DK4DBI_H_INCLUDED 31 #if DK4_BUILDING_DKTOOLS4 32 #include <libdk4dbi/dk4dbi.h> 33 #else 34 #include <dktools-4/dk4dbi.h> 35 #endif 36 #endif 37 38 #ifndef DK4DBIT8_H_INCLUDED 39 #if DK4_BUILDING_DKTOOLS4 40 #include <libdk4dbi/dk4dbit8.h> 41 #else 42 #include <dktools-4/dk4dbit8.h> 43 #endif 44 #endif 45 46 #ifndef DK4DBITW_H_INCLUDED 47 #if DK4_BUILDING_DKTOOLS4 48 #include <libdk4dbi/dk4dbitw.h> 49 #else 50 #include <dktools-4/dk4dbitw.h> 51 #endif 52 #endif 53 54 #if DK4_CHAR_SIZE > 1 55 /** Function to traverse text database. 56 */ 57 typedef dk4dbi_wc_traverse_fct_t dk4dbi_text_traverse_fct; 58 #else 59 /** Function to traverse text database. 60 */ 61 typedef dk4dbi_c8_traverse_fct_t dk4dbi_text_traverse_fct; 62 #endif 63 64 65 #ifdef __cplusplus 66 extern "C" { 67 #endif 68 69 /** Set text entry. 70 @param db Database to modify. 71 @param k Key text. 72 @param v Value text. 73 @param erp Error report, may be NULL. 74 @return 1 on success, 0 on error. 75 76 Error codes: 77 - DK4_E_INVALID_ARGUMENTS<br> 78 if db, k or vis NULL, 79 - DK4_E_SYNTAX<br> 80 if the database was opened read-only or k or v 81 is too long. 82 - DK4_E_MATH_OVERFLOW<br> 83 on numeric overflow in size calculation, 84 - DK4_E_NOT_SUPPORTED<br> 85 if db indicates an unsupported backend, 86 - DK4_E_NOT_FOUND<br> 87 if no record to delete was found, 88 - DK4_E_MEMORY_ALLOCATION_FAILED<br> 89 with mem.elsize and mem.nelem 90 set if there is not enough memory available, 91 - DK4_E_WRITE_FAILED<br> 92 if modification of the database failed. 93 */ 94 int 95 dk4dbi_text_set( 96 dk4_dbi_t *db, 97 const dkChar *k, 98 const dkChar *v, 99 dk4_er_t *erp 100 ); 101 102 /** Retrieve text entry. 103 @param db Database to query. 104 @param k Key text. 105 @param vbuf Result buffer address. 106 @param vsz Pointer to size variable (in: size, out: used), 107 number of dkChar. 108 @param erp Error report, may be NULL. 109 @return 1 on success, 0 on error. 110 111 Error codes: 112 - DK4_E_INVALID_ARGUMENTS<br> 113 if db, k or vbufis NULL or vsz is 0, 114 or the length of k exceeds the key size limit, 115 - DK4_E_MATH_OVERFLOW<br> 116 on numeric overflow in size calculation, 117 - DK4_E_NOT_SUPPORTED<br> 118 if db indicates an unsupported backend, 119 - DK4_E_NOT_FOUND<br> 120 if no record was found for the key, 121 - DK4_E_BUFFER_TOO_SMALL<br> 122 if the destination buffer is too small. 123 */ 124 int 125 dk4dbi_text_get( 126 dk4_dbi_t *db, 127 const dkChar *k, 128 dkChar *vbuf, 129 size_t vsz, 130 dk4_er_t *erp 131 ); 132 133 /** Delete text entry. 134 @param db Database to modify. 135 @param k Key text. 136 @param erp Error report, may be NULL. 137 @return 1 on success, 0 on error. 138 139 Error codes: 140 - DK4_E_INVALID_ARGUMENTS<br> 141 if db or k is NULL, 142 - DK4_E_SYNTAX<br> 143 if the database is opened read-only or the length of 144 k exceeds the key size limit, 145 - DK4_E_MATH_OVERFLOW<br> 146 on numeric overflow in size calculation, 147 - DK4_E_NOT_SUPPORTED<br> 148 if db indicates an unsupported backend, 149 - DK4_E_WRITE_FAILED<br> 150 if modification of the database failed, 151 - DK4_E_NOT_FOUND<br> 152 if no record for the specified key is in the database. 153 */ 154 int 155 dk4dbi_text_del( 156 dk4_dbi_t *db, 157 const dkChar *k, 158 dk4_er_t *erp 159 ); 160 161 /** Traverse database, apply function to all text entries. 162 @param db Database to traverse. 163 @param obj Object to modify during traversal. 164 @param fct Function to apply to all text entries. 165 @return 1 on success, 0 on error (database traversed), 166 -1 on error (traversal aborted). 167 */ 168 int 169 dk4dbi_text_traverse( 170 dk4_dbi_t *db, 171 void *obj, 172 dk4dbi_text_traverse_fct *fct 173 ); 174 175 #ifdef __cplusplus 176 } 177 #endif 178 179 180 #endif 181