diff options
Diffstat (limited to 'src/sq/sq_exec.c')
-rw-r--r-- | src/sq/sq_exec.c | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/src/sq/sq_exec.c b/src/sq/sq_exec.c index 325dfa014..ebc159421 100644 --- a/src/sq/sq_exec.c +++ b/src/sq/sq_exec.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2018 GNUnet e.V. | 3 | Copyright (C) 2018 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_exec.c | 21 | * @file sq/sq_exec.c |
22 | * @brief helper functions for executing SQL statements | 22 | * @brief helper functions for executing SQL statements |
@@ -33,8 +33,8 @@ | |||
33 | * @return initialized struct | 33 | * @return initialized struct |
34 | */ | 34 | */ |
35 | struct GNUNET_SQ_ExecuteStatement | 35 | struct GNUNET_SQ_ExecuteStatement |
36 | GNUNET_SQ_make_execute (const char *sql) | 36 | GNUNET_SQ_make_execute(const char *sql) |
37 | { | 37 | { |
38 | struct GNUNET_SQ_ExecuteStatement es = { | 38 | struct GNUNET_SQ_ExecuteStatement es = { |
39 | .sql = sql, | 39 | .sql = sql, |
40 | .ignore_errors = GNUNET_NO | 40 | .ignore_errors = GNUNET_NO |
@@ -53,7 +53,7 @@ GNUNET_SQ_make_execute (const char *sql) | |||
53 | * @return initialized struct | 53 | * @return initialized struct |
54 | */ | 54 | */ |
55 | struct GNUNET_SQ_ExecuteStatement | 55 | struct GNUNET_SQ_ExecuteStatement |
56 | GNUNET_SQ_make_try_execute (const char *sql) | 56 | GNUNET_SQ_make_try_execute(const char *sql) |
57 | { | 57 | { |
58 | struct GNUNET_SQ_ExecuteStatement es = { | 58 | struct GNUNET_SQ_ExecuteStatement es = { |
59 | .sql = sql, | 59 | .sql = sql, |
@@ -74,39 +74,39 @@ GNUNET_SQ_make_try_execute (const char *sql) | |||
74 | * #GNUNET_SYSERR on error | 74 | * #GNUNET_SYSERR on error |
75 | */ | 75 | */ |
76 | int | 76 | int |
77 | GNUNET_SQ_exec_statements (sqlite3 *dbh, | 77 | GNUNET_SQ_exec_statements(sqlite3 *dbh, |
78 | const struct GNUNET_SQ_ExecuteStatement *es) | 78 | const struct GNUNET_SQ_ExecuteStatement *es) |
79 | { | 79 | { |
80 | for (unsigned int i=0;NULL != es[i].sql;i++) | 80 | for (unsigned int i = 0; NULL != es[i].sql; i++) |
81 | { | ||
82 | char *emsg = NULL; | ||
83 | |||
84 | if (SQLITE_OK != | ||
85 | sqlite3_exec (dbh, | ||
86 | es[i].sql, | ||
87 | NULL, | ||
88 | NULL, | ||
89 | &emsg)) | ||
90 | { | 81 | { |
91 | if (es[i].ignore_errors) | 82 | char *emsg = NULL; |
92 | { | 83 | |
93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 84 | if (SQLITE_OK != |
94 | "Failed to run SQL `%s': %s\n", | 85 | sqlite3_exec(dbh, |
95 | es[i].sql, | 86 | es[i].sql, |
96 | emsg); | 87 | NULL, |
97 | } | 88 | NULL, |
98 | else | 89 | &emsg)) |
99 | { | 90 | { |
100 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 91 | if (es[i].ignore_errors) |
101 | "Failed to run SQL `%s': %s\n", | 92 | { |
102 | es[i].sql, | 93 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
103 | emsg); | 94 | "Failed to run SQL `%s': %s\n", |
104 | sqlite3_free (emsg); | 95 | es[i].sql, |
105 | return GNUNET_SYSERR; | 96 | emsg); |
106 | } | 97 | } |
107 | sqlite3_free (emsg); | 98 | else |
99 | { | ||
100 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
101 | "Failed to run SQL `%s': %s\n", | ||
102 | es[i].sql, | ||
103 | emsg); | ||
104 | sqlite3_free(emsg); | ||
105 | return GNUNET_SYSERR; | ||
106 | } | ||
107 | sqlite3_free(emsg); | ||
108 | } | ||
108 | } | 109 | } |
109 | } | ||
110 | return GNUNET_OK; | 110 | return GNUNET_OK; |
111 | } | 111 | } |
112 | 112 | ||