diff options
Diffstat (limited to 'src/sq/sq.c')
-rw-r--r-- | src/sq/sq.c | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/src/sq/sq.c b/src/sq/sq.c index e74071b81..6fce01322 100644 --- a/src/sq/sq.c +++ b/src/sq/sq.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2017 GNUnet e.V. | 3 | Copyright (C) 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file sq/sq.c | 21 | * @file sq/sq.c |
22 | * @brief helper functions for Sqlite3 DB interactions | 22 | * @brief helper functions for Sqlite3 DB interactions |
@@ -34,37 +34,37 @@ | |||
34 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 34 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
35 | */ | 35 | */ |
36 | int | 36 | int |
37 | GNUNET_SQ_bind (sqlite3_stmt *stmt, | 37 | GNUNET_SQ_bind(sqlite3_stmt *stmt, |
38 | const struct GNUNET_SQ_QueryParam *params) | 38 | const struct GNUNET_SQ_QueryParam *params) |
39 | { | 39 | { |
40 | unsigned int j; | 40 | unsigned int j; |
41 | 41 | ||
42 | j = 1; | 42 | j = 1; |
43 | for (unsigned int i=0;NULL != params[i].conv; i++) | 43 | for (unsigned int i = 0; NULL != params[i].conv; i++) |
44 | { | ||
45 | if (GNUNET_OK != | ||
46 | params[i].conv (params[i].conv_cls, | ||
47 | params[i].data, | ||
48 | params[i].size, | ||
49 | stmt, | ||
50 | j)) | ||
51 | { | 44 | { |
52 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 45 | if (GNUNET_OK != |
53 | "sq", | 46 | params[i].conv(params[i].conv_cls, |
54 | _("Failure to bind %u-th SQL parameter\n"), | 47 | params[i].data, |
55 | i); | 48 | params[i].size, |
56 | if (SQLITE_OK != | 49 | stmt, |
57 | sqlite3_reset (stmt)) | 50 | j)) |
58 | { | 51 | { |
59 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 52 | GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, |
60 | "sq", | 53 | "sq", |
61 | _("Failure in sqlite3_reset (!)\n")); | 54 | _("Failure to bind %u-th SQL parameter\n"), |
62 | return GNUNET_SYSERR; | 55 | i); |
63 | } | 56 | if (SQLITE_OK != |
57 | sqlite3_reset(stmt)) | ||
58 | { | ||
59 | GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, | ||
60 | "sq", | ||
61 | _("Failure in sqlite3_reset (!)\n")); | ||
62 | return GNUNET_SYSERR; | ||
63 | } | ||
64 | } | ||
65 | GNUNET_assert(0 != params[i].num_params); | ||
66 | j += params[i].num_params; | ||
64 | } | 67 | } |
65 | GNUNET_assert (0 != params[i].num_params); | ||
66 | j += params[i].num_params; | ||
67 | } | ||
68 | return GNUNET_OK; | 68 | return GNUNET_OK; |
69 | } | 69 | } |
70 | 70 | ||
@@ -79,30 +79,30 @@ GNUNET_SQ_bind (sqlite3_stmt *stmt, | |||
79 | * #GNUNET_SYSERR if a result was invalid (non-existing field) | 79 | * #GNUNET_SYSERR if a result was invalid (non-existing field) |
80 | */ | 80 | */ |
81 | int | 81 | int |
82 | GNUNET_SQ_extract_result (sqlite3_stmt *result, | 82 | GNUNET_SQ_extract_result(sqlite3_stmt *result, |
83 | struct GNUNET_SQ_ResultSpec *rs) | 83 | struct GNUNET_SQ_ResultSpec *rs) |
84 | { | 84 | { |
85 | unsigned int j = 0; | 85 | unsigned int j = 0; |
86 | 86 | ||
87 | for (unsigned int i=0;NULL != rs[i].conv; i++) | 87 | for (unsigned int i = 0; NULL != rs[i].conv; i++) |
88 | { | ||
89 | if (NULL == rs[i].result_size) | ||
90 | rs[i].result_size = &rs[i].dst_size; | ||
91 | if (GNUNET_OK != | ||
92 | rs[i].conv (rs[i].cls, | ||
93 | result, | ||
94 | j, | ||
95 | rs[i].result_size, | ||
96 | rs[i].dst)) | ||
97 | { | 88 | { |
98 | for (unsigned int k=0;k<i;k++) | 89 | if (NULL == rs[i].result_size) |
99 | if (NULL != rs[k].cleaner) | 90 | rs[i].result_size = &rs[i].dst_size; |
100 | rs[k].cleaner (rs[k].cls); | 91 | if (GNUNET_OK != |
101 | return GNUNET_SYSERR; | 92 | rs[i].conv(rs[i].cls, |
93 | result, | ||
94 | j, | ||
95 | rs[i].result_size, | ||
96 | rs[i].dst)) | ||
97 | { | ||
98 | for (unsigned int k = 0; k < i; k++) | ||
99 | if (NULL != rs[k].cleaner) | ||
100 | rs[k].cleaner(rs[k].cls); | ||
101 | return GNUNET_SYSERR; | ||
102 | } | ||
103 | GNUNET_assert(0 != rs[i].num_params); | ||
104 | j += rs[i].num_params; | ||
102 | } | 105 | } |
103 | GNUNET_assert (0 != rs[i].num_params); | ||
104 | j += rs[i].num_params; | ||
105 | } | ||
106 | return GNUNET_OK; | 106 | return GNUNET_OK; |
107 | } | 107 | } |
108 | 108 | ||
@@ -114,11 +114,11 @@ GNUNET_SQ_extract_result (sqlite3_stmt *result, | |||
114 | * @param rs reult specification to clean up | 114 | * @param rs reult specification to clean up |
115 | */ | 115 | */ |
116 | void | 116 | void |
117 | GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs) | 117 | GNUNET_SQ_cleanup_result(struct GNUNET_SQ_ResultSpec *rs) |
118 | { | 118 | { |
119 | for (unsigned int i=0;NULL != rs[i].conv; i++) | 119 | for (unsigned int i = 0; NULL != rs[i].conv; i++) |
120 | if (NULL != rs[i].cleaner) | 120 | if (NULL != rs[i].cleaner) |
121 | rs[i].cleaner (rs[i].cls); | 121 | rs[i].cleaner(rs[i].cls); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
@@ -129,15 +129,15 @@ GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs) | |||
129 | * @param stmt statement to reset | 129 | * @param stmt statement to reset |
130 | */ | 130 | */ |
131 | void | 131 | void |
132 | GNUNET_SQ_reset (sqlite3 *dbh, | 132 | GNUNET_SQ_reset(sqlite3 *dbh, |
133 | sqlite3_stmt *stmt) | 133 | sqlite3_stmt *stmt) |
134 | { | 134 | { |
135 | if (SQLITE_OK != | 135 | if (SQLITE_OK != |
136 | sqlite3_reset (stmt)) | 136 | sqlite3_reset(stmt)) |
137 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 137 | GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
138 | "sqlite", | 138 | "sqlite", |
139 | _("Failed to reset sqlite statement with error: %s\n"), | 139 | _("Failed to reset sqlite statement with error: %s\n"), |
140 | sqlite3_errmsg (dbh)); | 140 | sqlite3_errmsg(dbh)); |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||