diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-05-19 13:30:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-05-19 13:30:48 +0000 |
commit | f1f8aa05f4c44042a4d59300b44955481bb3c2b0 (patch) | |
tree | 19231bb42bca3dea3434ed13861b391225fc61b7 /src/include | |
parent | 3599bb1053027ee2d72f92268963018b44562120 (diff) | |
download | gnunet-f1f8aa05f4c44042a4d59300b44955481bb3c2b0.tar.gz gnunet-f1f8aa05f4c44042a4d59300b44955481bb3c2b0.zip |
extending MY api to cover result extraction
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_my_lib.h | 104 |
1 files changed, 97 insertions, 7 deletions
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index 50826a700..b63ee9218 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h | |||
@@ -64,11 +64,6 @@ typedef int | |||
64 | const struct GNUNET_MY_QueryParam *qp, | 64 | const struct GNUNET_MY_QueryParam *qp, |
65 | MYSQL_BIND *qbind); | 65 | MYSQL_BIND *qbind); |
66 | 66 | ||
67 | /****** CREATE A NEW STRUCTURE ? *****/ | ||
68 | struct GNUNET_MY_Result | ||
69 | { | ||
70 | |||
71 | }; | ||
72 | 67 | ||
73 | /** | 68 | /** |
74 | * Information we pass to #GNUNET_MY_exec_prepared() to | 69 | * Information we pass to #GNUNET_MY_exec_prepared() to |
@@ -106,7 +101,7 @@ struct GNUNET_MY_QueryParam | |||
106 | 101 | ||
107 | 102 | ||
108 | /** | 103 | /** |
109 | * End of result parameter specification. | 104 | * End of query parameter specification. |
110 | * | 105 | * |
111 | * @return array last entry for the result specification to use | 106 | * @return array last entry for the result specification to use |
112 | */ | 107 | */ |
@@ -140,7 +135,102 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
140 | const struct GNUNET_MY_QueryParam *params); | 135 | const struct GNUNET_MY_QueryParam *params); |
141 | 136 | ||
142 | 137 | ||
143 | static int extract_result(MYSQL * result, int row) ; | 138 | /** |
139 | * Information we pass to #GNUNET_MY_extract_result() to | ||
140 | * initialize the arguments of the prepared statement. | ||
141 | */ | ||
142 | struct GNUNET_MY_ResultParam; | ||
143 | |||
144 | |||
145 | /** | ||
146 | * Function called to convert input argument into SQL parameters. | ||
147 | * | ||
148 | * @param cls closure | ||
149 | * @param pq data about the query | ||
150 | * @return -1 on error | ||
151 | */ | ||
152 | typedef int | ||
153 | (*GNUNET_MY_ResultConverter)(void *cls, | ||
154 | struct GNUNET_MY_QueryParam *qp, | ||
155 | MYSQL_BIND *results); | ||
156 | |||
157 | |||
158 | /** | ||
159 | * Information we pass to #GNUNET_MY_extract_result() to | ||
160 | * initialize the arguments of the prepared statement. | ||
161 | */ | ||
162 | struct GNUNET_MY_ResultSpec | ||
163 | { | ||
164 | |||
165 | /** | ||
166 | * Function to call for the type conversion. | ||
167 | */ | ||
168 | GNUNET_MY_ResultConverter conv; | ||
169 | |||
170 | /** | ||
171 | * Closure for @e conv. | ||
172 | */ | ||
173 | void *conv_cls; | ||
174 | |||
175 | /** | ||
176 | * Destination for the data. | ||
177 | */ | ||
178 | void *dst; | ||
179 | |||
180 | /** | ||
181 | * Allowed size for the data, 0 for variable-size | ||
182 | * (in this case, the type of @e dst is a `void **` | ||
183 | * and we need to allocate a buffer of the right size). | ||
184 | */ | ||
185 | size_t dst_size; | ||
186 | |||
187 | /** | ||
188 | * Where to store actual size of the result. | ||
189 | */ | ||
190 | size_t *result_size; | ||
191 | |||
192 | }; | ||
193 | |||
194 | |||
195 | /** | ||
196 | * End of result speceter specification. | ||
197 | * | ||
198 | * @return array last entry for the result specification to use | ||
199 | */ | ||
200 | #define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL } | ||
201 | |||
202 | |||
203 | |||
204 | /** | ||
205 | * Obtain fixed size result of @a ptr_size bytes from | ||
206 | * MySQL, store in already allocated buffer at @a ptr. | ||
207 | * | ||
208 | * @spec ptr where to write the result | ||
209 | * @oaran ptr_size number of bytes available at @a ptr | ||
210 | */ | ||
211 | struct GNUNET_MY_ResultSpec | ||
212 | GNUNET_MY_result_spec_fixed_size (void *ptr, | ||
213 | size_t ptr_size); | ||
214 | |||
215 | |||
216 | /** | ||
217 | * We expect a fixed-size result, with size determined by the type of `* dst` | ||
218 | * | ||
219 | * @spec name name of the field in the table | ||
220 | * @spec dst point to where to store the result, type fits expected result size | ||
221 | * @return array entry for the result specification to use | ||
222 | */ | ||
223 | #define GNUNET_MY_result_spec_auto_from_type(dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof (*(dst))) | ||
224 | |||
225 | |||
226 | /** | ||
227 | * FIXME. | ||
228 | */ | ||
229 | int | ||
230 | GNUNET_MY_extract_result (struct GNUNET_MYSQL_Context *mc, | ||
231 | struct GNUNET_MYSQL_StatementHandle *stmt, | ||
232 | int row, | ||
233 | struct GNUNET_MY_ResultSpec *specs); | ||
144 | 234 | ||
145 | #if 0 /* keep Emacsens' auto-indent happy */ | 235 | #if 0 /* keep Emacsens' auto-indent happy */ |
146 | { | 236 | { |