diff options
author | Jeffrey Burdges <burdges@gnunet.org> | 2017-06-03 23:16:28 +0200 |
---|---|---|
committer | Jeffrey Burdges <burdges@gnunet.org> | 2017-06-03 23:16:28 +0200 |
commit | 1a90e7878a8fa1f5b30421bd3045cf5d6d3e13e4 (patch) | |
tree | 37fddbce1aa94bbe209ce3308a0617ee151e2f85 /src | |
parent | c53f7586d98f5a147dd3ce102eadae2834e363d2 (diff) | |
download | gnunet-1a90e7878a8fa1f5b30421bd3045cf5d6d3e13e4.tar.gz gnunet-1a90e7878a8fa1f5b30421bd3045cf5d6d3e13e4.zip |
Do singleton select statements
Diffstat (limited to 'src')
-rw-r--r-- | src/psycstore/plugin_psycstore_postgres.c | 119 |
1 files changed, 20 insertions, 99 deletions
diff --git a/src/psycstore/plugin_psycstore_postgres.c b/src/psycstore/plugin_psycstore_postgres.c index cd933667f..f23b75a0c 100644 --- a/src/psycstore/plugin_psycstore_postgres.c +++ b/src/psycstore/plugin_psycstore_postgres.c | |||
@@ -556,13 +556,10 @@ membership_test (void *cls, | |||
556 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, | 556 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, |
557 | uint64_t message_id) | 557 | uint64_t message_id) |
558 | { | 558 | { |
559 | PGresult *res; | ||
560 | struct Plugin *plugin = cls; | 559 | struct Plugin *plugin = cls; |
561 | 560 | ||
562 | uint32_t did_join = 0; | 561 | uint32_t did_join = 0; |
563 | 562 | ||
564 | int ret = GNUNET_SYSERR; | ||
565 | |||
566 | struct GNUNET_PQ_QueryParam params_select[] = { | 563 | struct GNUNET_PQ_QueryParam params_select[] = { |
567 | GNUNET_PQ_query_param_auto_from_type (channel_key), | 564 | GNUNET_PQ_query_param_auto_from_type (channel_key), |
568 | GNUNET_PQ_query_param_auto_from_type (slave_key), | 565 | GNUNET_PQ_query_param_auto_from_type (slave_key), |
@@ -570,35 +567,17 @@ membership_test (void *cls, | |||
570 | GNUNET_PQ_query_param_end | 567 | GNUNET_PQ_query_param_end |
571 | }; | 568 | }; |
572 | 569 | ||
573 | res = GNUNET_PQ_exec_prepared (plugin->dbh, "select_membership", params_select); | ||
574 | if (GNUNET_OK != | ||
575 | GNUNET_POSTGRES_check_result (plugin->dbh, | ||
576 | res, | ||
577 | PGRES_TUPLES_OK, | ||
578 | "PQexecPrepared", "select_membership")) | ||
579 | { | ||
580 | return GNUNET_SYSERR; | ||
581 | } | ||
582 | |||
583 | struct GNUNET_PQ_ResultSpec results_select[] = { | 570 | struct GNUNET_PQ_ResultSpec results_select[] = { |
584 | GNUNET_PQ_result_spec_uint32 ("did_join", &did_join), | 571 | GNUNET_PQ_result_spec_uint32 ("did_join", &did_join), |
585 | GNUNET_PQ_result_spec_end | 572 | GNUNET_PQ_result_spec_end |
586 | }; | 573 | }; |
587 | 574 | ||
588 | switch (GNUNET_PQ_extract_result (res, results_select, 0)) | 575 | if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT != |
589 | { | 576 | GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, "select_membership", |
590 | case GNUNET_OK: | 577 | params_select, results_select)) |
591 | ret = GNUNET_YES; | 578 | return GNUNET_SYSERR; |
592 | break; | ||
593 | 579 | ||
594 | default: | 580 | return GNUNET_OK; |
595 | ret = GNUNET_NO; | ||
596 | break; | ||
597 | } | ||
598 | |||
599 | PQclear (res); | ||
600 | |||
601 | return ret; | ||
602 | } | 581 | } |
603 | 582 | ||
604 | /** | 583 | /** |
@@ -1002,7 +981,6 @@ counters_message_get (void *cls, | |||
1002 | uint64_t *max_message_id, | 981 | uint64_t *max_message_id, |
1003 | uint64_t *max_group_generation) | 982 | uint64_t *max_group_generation) |
1004 | { | 983 | { |
1005 | PGresult *res; | ||
1006 | struct Plugin *plugin = cls; | 984 | struct Plugin *plugin = cls; |
1007 | 985 | ||
1008 | const char *stmt = "select_counters_message"; | 986 | const char *stmt = "select_counters_message"; |
@@ -1012,15 +990,6 @@ counters_message_get (void *cls, | |||
1012 | GNUNET_PQ_query_param_end | 990 | GNUNET_PQ_query_param_end |
1013 | }; | 991 | }; |
1014 | 992 | ||
1015 | res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select); | ||
1016 | if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh, | ||
1017 | res, | ||
1018 | PGRES_TUPLES_OK, | ||
1019 | "PQexecPrepared", stmt)) | ||
1020 | { | ||
1021 | return GNUNET_SYSERR; | ||
1022 | } | ||
1023 | |||
1024 | struct GNUNET_PQ_ResultSpec results_select[] = { | 993 | struct GNUNET_PQ_ResultSpec results_select[] = { |
1025 | GNUNET_PQ_result_spec_uint64 ("fragment_id", max_fragment_id), | 994 | GNUNET_PQ_result_spec_uint64 ("fragment_id", max_fragment_id), |
1026 | GNUNET_PQ_result_spec_uint64 ("message_id", max_message_id), | 995 | GNUNET_PQ_result_spec_uint64 ("message_id", max_message_id), |
@@ -1028,14 +997,10 @@ counters_message_get (void *cls, | |||
1028 | GNUNET_PQ_result_spec_end | 997 | GNUNET_PQ_result_spec_end |
1029 | }; | 998 | }; |
1030 | 999 | ||
1031 | if (GNUNET_OK != GNUNET_PQ_extract_result (res, results_select, 0)) | 1000 | if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT != |
1032 | { | 1001 | GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt, |
1033 | PQclear (res); | 1002 | params_select, results_select)) |
1034 | return GNUNET_SYSERR; | 1003 | return GNUNET_SYSERR; |
1035 | } | ||
1036 | |||
1037 | GNUNET_PQ_cleanup_result(results_select); | ||
1038 | PQclear (res); | ||
1039 | 1004 | ||
1040 | return GNUNET_OK; | 1005 | return GNUNET_OK; |
1041 | } | 1006 | } |
@@ -1052,44 +1017,26 @@ counters_state_get (void *cls, | |||
1052 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 1017 | const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
1053 | uint64_t *max_state_message_id) | 1018 | uint64_t *max_state_message_id) |
1054 | { | 1019 | { |
1055 | PGresult *res; | ||
1056 | struct Plugin *plugin = cls; | 1020 | struct Plugin *plugin = cls; |
1057 | 1021 | ||
1058 | const char *stmt = "select_counters_state"; | 1022 | const char *stmt = "select_counters_state"; |
1059 | 1023 | ||
1060 | int ret = GNUNET_SYSERR; | ||
1061 | |||
1062 | struct GNUNET_PQ_QueryParam params_select[] = { | 1024 | struct GNUNET_PQ_QueryParam params_select[] = { |
1063 | GNUNET_PQ_query_param_auto_from_type (channel_key), | 1025 | GNUNET_PQ_query_param_auto_from_type (channel_key), |
1064 | GNUNET_PQ_query_param_end | 1026 | GNUNET_PQ_query_param_end |
1065 | }; | 1027 | }; |
1066 | 1028 | ||
1067 | res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select); | ||
1068 | if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh, | ||
1069 | res, | ||
1070 | PGRES_TUPLES_OK, | ||
1071 | "PQexecPrepared", stmt)) | ||
1072 | { | ||
1073 | return GNUNET_SYSERR; | ||
1074 | } | ||
1075 | |||
1076 | struct GNUNET_PQ_ResultSpec results_select[] = { | 1029 | struct GNUNET_PQ_ResultSpec results_select[] = { |
1077 | GNUNET_PQ_result_spec_uint64 ("max_state_message_id", max_state_message_id), | 1030 | GNUNET_PQ_result_spec_uint64 ("max_state_message_id", max_state_message_id), |
1078 | GNUNET_PQ_result_spec_end | 1031 | GNUNET_PQ_result_spec_end |
1079 | }; | 1032 | }; |
1080 | 1033 | ||
1081 | ret = GNUNET_PQ_extract_result (res, results_select, 0); | 1034 | if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT != |
1082 | 1035 | GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt, | |
1083 | if (GNUNET_OK != ret) | 1036 | params_select, results_select)) |
1084 | { | 1037 | return GNUNET_SYSERR; |
1085 | PQclear (res); | ||
1086 | return GNUNET_SYSERR; | ||
1087 | } | ||
1088 | |||
1089 | GNUNET_PQ_cleanup_result(results_select); | ||
1090 | PQclear (res); | ||
1091 | 1038 | ||
1092 | return ret; | 1039 | return GNUNET_OK; |
1093 | } | 1040 | } |
1094 | 1041 | ||
1095 | 1042 | ||
@@ -1343,10 +1290,7 @@ static int | |||
1343 | state_get (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | 1290 | state_get (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, |
1344 | const char *name, GNUNET_PSYCSTORE_StateCallback cb, void *cb_cls) | 1291 | const char *name, GNUNET_PSYCSTORE_StateCallback cb, void *cb_cls) |
1345 | { | 1292 | { |
1346 | PGresult *res; | ||
1347 | |||
1348 | struct Plugin *plugin = cls; | 1293 | struct Plugin *plugin = cls; |
1349 | int ret = GNUNET_SYSERR; | ||
1350 | 1294 | ||
1351 | const char *stmt = "select_state_one"; | 1295 | const char *stmt = "select_state_one"; |
1352 | 1296 | ||
@@ -1359,41 +1303,18 @@ state_get (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, | |||
1359 | void *value_current = NULL; | 1303 | void *value_current = NULL; |
1360 | size_t value_size = 0; | 1304 | size_t value_size = 0; |
1361 | 1305 | ||
1362 | struct GNUNET_PQ_ResultSpec results[] = { | 1306 | struct GNUNET_PQ_ResultSpec results_select[] = { |
1363 | GNUNET_PQ_result_spec_variable_size ("value_current", &value_current, &value_size), | 1307 | GNUNET_PQ_result_spec_variable_size ("value_current", &value_current, &value_size), |
1364 | GNUNET_PQ_result_spec_end | 1308 | GNUNET_PQ_result_spec_end |
1365 | }; | 1309 | }; |
1366 | 1310 | ||
1367 | res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select); | 1311 | if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT != |
1368 | if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh, | 1312 | GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt, |
1369 | res, | 1313 | params_select, results_select)) |
1370 | PGRES_TUPLES_OK, | 1314 | return GNUNET_SYSERR; |
1371 | "PQexecPrepared", stmt)) | ||
1372 | { | ||
1373 | return GNUNET_SYSERR; | ||
1374 | } | ||
1375 | |||
1376 | if (PQntuples (res) == 0) | ||
1377 | { | ||
1378 | PQclear (res); | ||
1379 | ret = GNUNET_NO; | ||
1380 | } | ||
1381 | 1315 | ||
1382 | ret = GNUNET_PQ_extract_result (res, results, 0); | 1316 | return cb (cb_cls, name, value_current, |
1383 | |||
1384 | if (GNUNET_OK != ret) | ||
1385 | { | ||
1386 | PQclear (res); | ||
1387 | return GNUNET_SYSERR; | ||
1388 | } | ||
1389 | |||
1390 | ret = cb (cb_cls, name, value_current, | ||
1391 | value_size); | 1317 | value_size); |
1392 | |||
1393 | GNUNET_PQ_cleanup_result(results); | ||
1394 | PQclear (res); | ||
1395 | |||
1396 | return ret; | ||
1397 | } | 1318 | } |
1398 | 1319 | ||
1399 | 1320 | ||