diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-01 12:44:39 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-01 12:44:39 +0200 |
commit | a5e3e870f27c8ef3a3cd5d59a686a3050f9c64fb (patch) | |
tree | 6eec8a07a9a932d3c7b36f196ad01428e4f0ed63 /src/namestore/plugin_namestore_postgres.c | |
parent | 8f2f5bc2ee8ebf9b059b7b7e3104f25c5c363458 (diff) | |
download | gnunet-a5e3e870f27c8ef3a3cd5d59a686a3050f9c64fb.tar.gz gnunet-a5e3e870f27c8ef3a3cd5d59a686a3050f9c64fb.zip |
more extensive namestore tests for the non-sqlite plugins, with bugfixes
Diffstat (limited to 'src/namestore/plugin_namestore_postgres.c')
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index 69e28b0d0..4e4ca1f43 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -212,7 +212,9 @@ namestore_postgres_store_records (void *cls, | |||
212 | uint32_t rd_count32 = (uint32_t) rd_count; | 212 | uint32_t rd_count32 = (uint32_t) rd_count; |
213 | size_t data_size; | 213 | size_t data_size; |
214 | 214 | ||
215 | memset (&pkey, 0, sizeof (pkey)); | 215 | memset (&pkey, |
216 | 0, | ||
217 | sizeof (pkey)); | ||
216 | for (unsigned int i=0;i<rd_count;i++) | 218 | for (unsigned int i=0;i<rd_count;i++) |
217 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) | 219 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) |
218 | { | 220 | { |
@@ -231,6 +233,32 @@ namestore_postgres_store_records (void *cls, | |||
231 | GNUNET_break (0); | 233 | GNUNET_break (0); |
232 | return GNUNET_SYSERR; | 234 | return GNUNET_SYSERR; |
233 | } | 235 | } |
236 | /* first, delete existing records */ | ||
237 | { | ||
238 | struct GNUNET_PQ_QueryParam params[] = { | ||
239 | GNUNET_PQ_query_param_auto_from_type (zone_key), | ||
240 | GNUNET_PQ_query_param_string (label), | ||
241 | GNUNET_PQ_query_param_end | ||
242 | }; | ||
243 | enum GNUNET_DB_QueryStatus res; | ||
244 | |||
245 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | ||
246 | "delete_records", | ||
247 | params); | ||
248 | if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) && | ||
249 | (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != res) ) | ||
250 | { | ||
251 | GNUNET_break (0); | ||
252 | return GNUNET_SYSERR; | ||
253 | } | ||
254 | } | ||
255 | if (0 == rd_count) | ||
256 | { | ||
257 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
258 | "postgres", | ||
259 | "Record deleted\n"); | ||
260 | return GNUNET_OK; | ||
261 | } | ||
234 | { | 262 | { |
235 | char data[data_size]; | 263 | char data[data_size]; |
236 | struct GNUNET_PQ_QueryParam params[] = { | 264 | struct GNUNET_PQ_QueryParam params[] = { |
@@ -389,7 +417,7 @@ parse_result_call_iterator (void *cls, | |||
389 | * @param label name of the record in the zone | 417 | * @param label name of the record in the zone |
390 | * @param iter function to call with the result | 418 | * @param iter function to call with the result |
391 | * @param iter_cls closure for @a iter | 419 | * @param iter_cls closure for @a iter |
392 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 420 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR |
393 | */ | 421 | */ |
394 | static int | 422 | static int |
395 | namestore_postgres_lookup_records (void *cls, | 423 | namestore_postgres_lookup_records (void *cls, |
@@ -407,6 +435,11 @@ namestore_postgres_lookup_records (void *cls, | |||
407 | struct ParserContext pc; | 435 | struct ParserContext pc; |
408 | enum GNUNET_DB_QueryStatus res; | 436 | enum GNUNET_DB_QueryStatus res; |
409 | 437 | ||
438 | if (NULL == zone) | ||
439 | { | ||
440 | GNUNET_break (0); | ||
441 | return GNUNET_SYSERR; | ||
442 | } | ||
410 | pc.iter = iter; | 443 | pc.iter = iter; |
411 | pc.iter_cls = iter_cls; | 444 | pc.iter_cls = iter_cls; |
412 | pc.zone_key = zone; | 445 | pc.zone_key = zone; |
@@ -415,8 +448,10 @@ namestore_postgres_lookup_records (void *cls, | |||
415 | params, | 448 | params, |
416 | &parse_result_call_iterator, | 449 | &parse_result_call_iterator, |
417 | &pc); | 450 | &pc); |
418 | if (res <= 0) | 451 | if (res < 0) |
419 | return GNUNET_SYSERR; | 452 | return GNUNET_SYSERR; |
453 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) | ||
454 | return GNUNET_NO; | ||
420 | return GNUNET_OK; | 455 | return GNUNET_OK; |
421 | } | 456 | } |
422 | 457 | ||