[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: handle UNIQUE violation nic
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: handle UNIQUE violation nicely |
Date: |
Sat, 10 Jun 2017 21:53:20 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new d71e2f3b3 handle UNIQUE violation nicely
d71e2f3b3 is described below
commit d71e2f3b35de7fcce36806bdad44ecf4114f6740
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Jun 10 21:53:08 2017 +0200
handle UNIQUE violation nicely
---
src/include/gnunet_pq_lib.h | 5 ++++-
src/pq/pq_eval.c | 22 +++++++++++++++++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index ff4df563d..0f6b88b78 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -525,7 +525,10 @@ GNUNET_PQ_eval_result (PGconn *connection,
* @return status code from the result, mapping PQ status
* codes to `enum GNUNET_PQ_QueryStatus`. If the
* statement was a DELETE or UPDATE statement, the
- * number of affected rows is returned.
+ * number of affected rows is returned; if the
+ * statment was an INSERT statement, and no row
+ * was added due to a UNIQUE violation, we return
+ * zero; if INSERT was successful, we return one.
*/
enum GNUNET_PQ_QueryStatus
GNUNET_PQ_eval_prepared_non_select (PGconn *connection,
diff --git a/src/pq/pq_eval.c b/src/pq/pq_eval.c
index 9296dce2e..b19742bba 100644
--- a/src/pq/pq_eval.c
+++ b/src/pq/pq_eval.c
@@ -93,6 +93,23 @@ GNUNET_PQ_eval_result (PGconn *connection,
PQerrorMessage (connection));
return GNUNET_PQ_STATUS_SOFT_ERROR;
}
+ if (0 == strcmp (sqlstate,
+ PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION))
+ {
+ /* Likely no need to retry, INSERT of "same" data. */
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "pq",
+ "Query `%s' failed with unique violation:
%s/%s/%s/%s/%s\n",
+ statement_name,
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_PRIMARY),
+ PQresultErrorField (result,
+ PG_DIAG_MESSAGE_DETAIL),
+ PQresultErrorMessage (result),
+ PQresStatus (PQresultStatus (result)),
+ PQerrorMessage (connection));
+ return GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS;
+ }
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"pq",
"Query `%s' failed with result: %s/%s/%s/%s/%s\n",
@@ -121,7 +138,10 @@ GNUNET_PQ_eval_result (PGconn *connection,
* @return status code from the result, mapping PQ status
* codes to `enum GNUNET_PQ_QueryStatus`. If the
* statement was a DELETE or UPDATE statement, the
- * number of affected rows is returned.
+ * number of affected rows is returned.; if the
+ * statment was an INSERT statement, and no row
+ * was added due to a UNIQUE violation, we return
+ * zero; if INSERT was successful, we return one.
*/
enum GNUNET_PQ_QueryStatus
GNUNET_PQ_eval_prepared_non_select (PGconn *connection,
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet] branch master updated: handle UNIQUE violation nicely,
gnunet <=