diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/pq/pq_eval.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/pq/pq_eval.c')
-rw-r--r-- | src/pq/pq_eval.c | 267 |
1 files changed, 134 insertions, 133 deletions
diff --git a/src/pq/pq_eval.c b/src/pq/pq_eval.c index 0df71e672..1d041f226 100644 --- a/src/pq/pq_eval.c +++ b/src/pq/pq_eval.c | |||
@@ -57,76 +57,76 @@ | |||
57 | * @deprecated (low level, let's see if we can do with just the high-level functions) | 57 | * @deprecated (low level, let's see if we can do with just the high-level functions) |
58 | */ | 58 | */ |
59 | enum GNUNET_DB_QueryStatus | 59 | enum GNUNET_DB_QueryStatus |
60 | GNUNET_PQ_eval_result(PGconn *connection, | 60 | GNUNET_PQ_eval_result (PGconn *connection, |
61 | const char *statement_name, | 61 | const char *statement_name, |
62 | PGresult *result) | 62 | PGresult *result) |
63 | { | 63 | { |
64 | ExecStatusType est; | 64 | ExecStatusType est; |
65 | 65 | ||
66 | est = PQresultStatus(result); | 66 | est = PQresultStatus (result); |
67 | if ((PGRES_COMMAND_OK != est) && | 67 | if ((PGRES_COMMAND_OK != est) && |
68 | (PGRES_TUPLES_OK != est)) | 68 | (PGRES_TUPLES_OK != est)) |
69 | { | 69 | { |
70 | const char *sqlstate; | 70 | const char *sqlstate; |
71 | 71 | ||
72 | sqlstate = PQresultErrorField(result, | 72 | sqlstate = PQresultErrorField (result, |
73 | PG_DIAG_SQLSTATE); | 73 | PG_DIAG_SQLSTATE); |
74 | if (NULL == sqlstate) | 74 | if (NULL == sqlstate) |
75 | { | 75 | { |
76 | /* very unexpected... */ | 76 | /* very unexpected... */ |
77 | GNUNET_break(0); | 77 | GNUNET_break (0); |
78 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
79 | } | ||
80 | if ((0 == strcmp(sqlstate, | ||
81 | PQ_DIAG_SQLSTATE_DEADLOCK)) || | ||
82 | (0 == strcmp(sqlstate, | ||
83 | PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE))) | ||
84 | { | ||
85 | /* These two can be retried and have a fair chance of working | ||
86 | the next time */ | ||
87 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, | ||
88 | "pq", | ||
89 | "Query `%s' failed with result: %s/%s/%s/%s/%s\n", | ||
90 | statement_name, | ||
91 | PQresultErrorField(result, | ||
92 | PG_DIAG_MESSAGE_PRIMARY), | ||
93 | PQresultErrorField(result, | ||
94 | PG_DIAG_MESSAGE_DETAIL), | ||
95 | PQresultErrorMessage(result), | ||
96 | PQresStatus(PQresultStatus(result)), | ||
97 | PQerrorMessage(connection)); | ||
98 | return GNUNET_DB_STATUS_SOFT_ERROR; | ||
99 | } | ||
100 | if (0 == strcmp(sqlstate, | ||
101 | PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION)) | ||
102 | { | ||
103 | /* Likely no need to retry, INSERT of "same" data. */ | ||
104 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, | ||
105 | "pq", | ||
106 | "Query `%s' failed with unique violation: %s/%s/%s/%s/%s\n", | ||
107 | statement_name, | ||
108 | PQresultErrorField(result, | ||
109 | PG_DIAG_MESSAGE_PRIMARY), | ||
110 | PQresultErrorField(result, | ||
111 | PG_DIAG_MESSAGE_DETAIL), | ||
112 | PQresultErrorMessage(result), | ||
113 | PQresStatus(PQresultStatus(result)), | ||
114 | PQerrorMessage(connection)); | ||
115 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | ||
116 | } | ||
117 | GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, | ||
118 | "pq", | ||
119 | "Query `%s' failed with result: %s/%s/%s/%s/%s\n", | ||
120 | statement_name, | ||
121 | PQresultErrorField(result, | ||
122 | PG_DIAG_MESSAGE_PRIMARY), | ||
123 | PQresultErrorField(result, | ||
124 | PG_DIAG_MESSAGE_DETAIL), | ||
125 | PQresultErrorMessage(result), | ||
126 | PQresStatus(PQresultStatus(result)), | ||
127 | PQerrorMessage(connection)); | ||
128 | return GNUNET_DB_STATUS_HARD_ERROR; | 78 | return GNUNET_DB_STATUS_HARD_ERROR; |
129 | } | 79 | } |
80 | if ((0 == strcmp (sqlstate, | ||
81 | PQ_DIAG_SQLSTATE_DEADLOCK)) || | ||
82 | (0 == strcmp (sqlstate, | ||
83 | PQ_DIAG_SQLSTATE_SERIALIZATION_FAILURE))) | ||
84 | { | ||
85 | /* These two can be retried and have a fair chance of working | ||
86 | the next time */ | ||
87 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | ||
88 | "pq", | ||
89 | "Query `%s' failed with result: %s/%s/%s/%s/%s\n", | ||
90 | statement_name, | ||
91 | PQresultErrorField (result, | ||
92 | PG_DIAG_MESSAGE_PRIMARY), | ||
93 | PQresultErrorField (result, | ||
94 | PG_DIAG_MESSAGE_DETAIL), | ||
95 | PQresultErrorMessage (result), | ||
96 | PQresStatus (PQresultStatus (result)), | ||
97 | PQerrorMessage (connection)); | ||
98 | return GNUNET_DB_STATUS_SOFT_ERROR; | ||
99 | } | ||
100 | if (0 == strcmp (sqlstate, | ||
101 | PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION)) | ||
102 | { | ||
103 | /* Likely no need to retry, INSERT of "same" data. */ | ||
104 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
105 | "pq", | ||
106 | "Query `%s' failed with unique violation: %s/%s/%s/%s/%s\n", | ||
107 | statement_name, | ||
108 | PQresultErrorField (result, | ||
109 | PG_DIAG_MESSAGE_PRIMARY), | ||
110 | PQresultErrorField (result, | ||
111 | PG_DIAG_MESSAGE_DETAIL), | ||
112 | PQresultErrorMessage (result), | ||
113 | PQresStatus (PQresultStatus (result)), | ||
114 | PQerrorMessage (connection)); | ||
115 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | ||
116 | } | ||
117 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
118 | "pq", | ||
119 | "Query `%s' failed with result: %s/%s/%s/%s/%s\n", | ||
120 | statement_name, | ||
121 | PQresultErrorField (result, | ||
122 | PG_DIAG_MESSAGE_PRIMARY), | ||
123 | PQresultErrorField (result, | ||
124 | PG_DIAG_MESSAGE_DETAIL), | ||
125 | PQresultErrorMessage (result), | ||
126 | PQresStatus (PQresultStatus (result)), | ||
127 | PQerrorMessage (connection)); | ||
128 | return GNUNET_DB_STATUS_HARD_ERROR; | ||
129 | } | ||
130 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | 130 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; |
131 | } | 131 | } |
132 | 132 | ||
@@ -148,29 +148,29 @@ GNUNET_PQ_eval_result(PGconn *connection, | |||
148 | * zero; if INSERT was successful, we return one. | 148 | * zero; if INSERT was successful, we return one. |
149 | */ | 149 | */ |
150 | enum GNUNET_DB_QueryStatus | 150 | enum GNUNET_DB_QueryStatus |
151 | GNUNET_PQ_eval_prepared_non_select(PGconn *connection, | 151 | GNUNET_PQ_eval_prepared_non_select (PGconn *connection, |
152 | const char *statement_name, | 152 | const char *statement_name, |
153 | const struct GNUNET_PQ_QueryParam *params) | 153 | const struct GNUNET_PQ_QueryParam *params) |
154 | { | 154 | { |
155 | PGresult *result; | 155 | PGresult *result; |
156 | enum GNUNET_DB_QueryStatus qs; | 156 | enum GNUNET_DB_QueryStatus qs; |
157 | 157 | ||
158 | result = GNUNET_PQ_exec_prepared(connection, | 158 | result = GNUNET_PQ_exec_prepared (connection, |
159 | statement_name, | 159 | statement_name, |
160 | params); | 160 | params); |
161 | qs = GNUNET_PQ_eval_result(connection, | 161 | qs = GNUNET_PQ_eval_result (connection, |
162 | statement_name, | 162 | statement_name, |
163 | result); | 163 | result); |
164 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) | 164 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) |
165 | { | 165 | { |
166 | const char *tuples; | 166 | const char *tuples; |
167 | 167 | ||
168 | /* What an awful API, this function really does return a string */ | 168 | /* What an awful API, this function really does return a string */ |
169 | tuples = PQcmdTuples(result); | 169 | tuples = PQcmdTuples (result); |
170 | if (NULL != tuples) | 170 | if (NULL != tuples) |
171 | qs = strtol(tuples, NULL, 10); | 171 | qs = strtol (tuples, NULL, 10); |
172 | } | 172 | } |
173 | PQclear(result); | 173 | PQclear (result); |
174 | return qs; | 174 | return qs; |
175 | } | 175 | } |
176 | 176 | ||
@@ -191,33 +191,33 @@ GNUNET_PQ_eval_prepared_non_select(PGconn *connection, | |||
191 | * codes to `enum GNUNET_DB_QueryStatus`. | 191 | * codes to `enum GNUNET_DB_QueryStatus`. |
192 | */ | 192 | */ |
193 | enum GNUNET_DB_QueryStatus | 193 | enum GNUNET_DB_QueryStatus |
194 | GNUNET_PQ_eval_prepared_multi_select(PGconn *connection, | 194 | GNUNET_PQ_eval_prepared_multi_select (PGconn *connection, |
195 | const char *statement_name, | 195 | const char *statement_name, |
196 | const struct GNUNET_PQ_QueryParam *params, | 196 | const struct GNUNET_PQ_QueryParam *params, |
197 | GNUNET_PQ_PostgresResultHandler rh, | 197 | GNUNET_PQ_PostgresResultHandler rh, |
198 | void *rh_cls) | 198 | void *rh_cls) |
199 | { | 199 | { |
200 | PGresult *result; | 200 | PGresult *result; |
201 | enum GNUNET_DB_QueryStatus qs; | 201 | enum GNUNET_DB_QueryStatus qs; |
202 | unsigned int ret; | 202 | unsigned int ret; |
203 | 203 | ||
204 | result = GNUNET_PQ_exec_prepared(connection, | 204 | result = GNUNET_PQ_exec_prepared (connection, |
205 | statement_name, | 205 | statement_name, |
206 | params); | 206 | params); |
207 | qs = GNUNET_PQ_eval_result(connection, | 207 | qs = GNUNET_PQ_eval_result (connection, |
208 | statement_name, | 208 | statement_name, |
209 | result); | 209 | result); |
210 | if (qs < 0) | 210 | if (qs < 0) |
211 | { | 211 | { |
212 | PQclear(result); | 212 | PQclear (result); |
213 | return qs; | 213 | return qs; |
214 | } | 214 | } |
215 | ret = PQntuples(result); | 215 | ret = PQntuples (result); |
216 | if (NULL != rh) | 216 | if (NULL != rh) |
217 | rh(rh_cls, | 217 | rh (rh_cls, |
218 | result, | 218 | result, |
219 | ret); | 219 | ret); |
220 | PQclear(result); | 220 | PQclear (result); |
221 | return ret; | 221 | return ret; |
222 | } | 222 | } |
223 | 223 | ||
@@ -238,46 +238,47 @@ GNUNET_PQ_eval_prepared_multi_select(PGconn *connection, | |||
238 | * codes to `enum GNUNET_DB_QueryStatus`. | 238 | * codes to `enum GNUNET_DB_QueryStatus`. |
239 | */ | 239 | */ |
240 | enum GNUNET_DB_QueryStatus | 240 | enum GNUNET_DB_QueryStatus |
241 | GNUNET_PQ_eval_prepared_singleton_select(PGconn *connection, | 241 | GNUNET_PQ_eval_prepared_singleton_select (PGconn *connection, |
242 | const char *statement_name, | 242 | const char *statement_name, |
243 | const struct GNUNET_PQ_QueryParam *params, | 243 | const struct |
244 | struct GNUNET_PQ_ResultSpec *rs) | 244 | GNUNET_PQ_QueryParam *params, |
245 | struct GNUNET_PQ_ResultSpec *rs) | ||
245 | { | 246 | { |
246 | PGresult *result; | 247 | PGresult *result; |
247 | enum GNUNET_DB_QueryStatus qs; | 248 | enum GNUNET_DB_QueryStatus qs; |
248 | 249 | ||
249 | result = GNUNET_PQ_exec_prepared(connection, | 250 | result = GNUNET_PQ_exec_prepared (connection, |
250 | statement_name, | 251 | statement_name, |
251 | params); | 252 | params); |
252 | qs = GNUNET_PQ_eval_result(connection, | 253 | qs = GNUNET_PQ_eval_result (connection, |
253 | statement_name, | 254 | statement_name, |
254 | result); | 255 | result); |
255 | if (qs < 0) | 256 | if (qs < 0) |
256 | { | 257 | { |
257 | PQclear(result); | 258 | PQclear (result); |
258 | return qs; | 259 | return qs; |
259 | } | 260 | } |
260 | if (0 == PQntuples(result)) | 261 | if (0 == PQntuples (result)) |
261 | { | 262 | { |
262 | PQclear(result); | 263 | PQclear (result); |
263 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | 264 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; |
264 | } | 265 | } |
265 | if (1 != PQntuples(result)) | 266 | if (1 != PQntuples (result)) |
266 | { | 267 | { |
267 | /* more than one result, but there must be at most one */ | 268 | /* more than one result, but there must be at most one */ |
268 | GNUNET_break(0); | 269 | GNUNET_break (0); |
269 | PQclear(result); | 270 | PQclear (result); |
270 | return GNUNET_DB_STATUS_HARD_ERROR; | 271 | return GNUNET_DB_STATUS_HARD_ERROR; |
271 | } | 272 | } |
272 | if (GNUNET_OK != | 273 | if (GNUNET_OK != |
273 | GNUNET_PQ_extract_result(result, | 274 | GNUNET_PQ_extract_result (result, |
274 | rs, | 275 | rs, |
275 | 0)) | 276 | 0)) |
276 | { | 277 | { |
277 | PQclear(result); | 278 | PQclear (result); |
278 | return GNUNET_DB_STATUS_HARD_ERROR; | 279 | return GNUNET_DB_STATUS_HARD_ERROR; |
279 | } | 280 | } |
280 | PQclear(result); | 281 | PQclear (result); |
281 | return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; | 282 | return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; |
282 | } | 283 | } |
283 | 284 | ||