diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-24 20:12:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-24 20:12:53 +0000 |
commit | d5fd881c2a044474b54ddf03b6ab8be8d2b75927 (patch) | |
tree | b3565f8038b761a2a2117476dc7d493fc8e0cde2 /src/my/my.c | |
parent | 63b2e5ce20544b22da822848d6e3f3c495f381c3 (diff) | |
download | gnunet-d5fd881c2a044474b54ddf03b6ab8be8d2b75927.tar.gz gnunet-d5fd881c2a044474b54ddf03b6ab8be8d2b75927.zip |
-handle NULL results
Diffstat (limited to 'src/my/my.c')
-rw-r--r-- | src/my/my.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/my/my.c b/src/my/my.c index ae46a2888..5ca80b63c 100644 --- a/src/my/my.c +++ b/src/my/my.c | |||
@@ -75,9 +75,11 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
75 | if (mysql_stmt_bind_param (stmt, | 75 | if (mysql_stmt_bind_param (stmt, |
76 | qbind)) | 76 | qbind)) |
77 | { | 77 | { |
78 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 78 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
79 | "my", | ||
79 | _("`%s' failed at %s:%d with error: %s\n"), | 80 | _("`%s' failed at %s:%d with error: %s\n"), |
80 | "mysql_stmt_bind_param", __FILE__, __LINE__, | 81 | "mysql_stmt_bind_param", |
82 | __FILE__, __LINE__, | ||
81 | mysql_stmt_error (stmt)); | 83 | mysql_stmt_error (stmt)); |
82 | GNUNET_MYSQL_statements_invalidate (mc); | 84 | GNUNET_MYSQL_statements_invalidate (mc); |
83 | return GNUNET_SYSERR; | 85 | return GNUNET_SYSERR; |
@@ -85,18 +87,17 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
85 | 87 | ||
86 | if (mysql_stmt_execute (stmt)) | 88 | if (mysql_stmt_execute (stmt)) |
87 | { | 89 | { |
88 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 90 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
91 | "my", | ||
89 | _("`%s' failed at %s:%d with error: %s\n"), | 92 | _("`%s' failed at %s:%d with error: %s\n"), |
90 | "mysql_stmt_execute", __FILE__, __LINE__, | 93 | "mysql_stmt_execute", __FILE__, __LINE__, |
91 | mysql_stmt_error (stmt)); | 94 | mysql_stmt_error (stmt)); |
92 | GNUNET_MYSQL_statements_invalidate (mc); | 95 | GNUNET_MYSQL_statements_invalidate (mc); |
93 | return GNUNET_SYSERR; | 96 | return GNUNET_SYSERR; |
94 | } | 97 | } |
95 | |||
96 | GNUNET_MY_cleanup_query (params, | 98 | GNUNET_MY_cleanup_query (params, |
97 | qbind); | 99 | qbind); |
98 | } | 100 | } |
99 | |||
100 | return GNUNET_OK; | 101 | return GNUNET_OK; |
101 | } | 102 | } |
102 | 103 | ||
@@ -125,7 +126,6 @@ GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp, | |||
125 | * Extract results from a query result according to the given | 126 | * Extract results from a query result according to the given |
126 | * specification. Always fetches the next row. | 127 | * specification. Always fetches the next row. |
127 | * | 128 | * |
128 | * | ||
129 | * @param sh statement that returned results | 129 | * @param sh statement that returned results |
130 | * @param rs specification to extract for | 130 | * @param rs specification to extract for |
131 | * @return | 131 | * @return |
@@ -145,12 +145,14 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
145 | stmt = GNUNET_MYSQL_statement_get_stmt (sh); | 145 | stmt = GNUNET_MYSQL_statement_get_stmt (sh); |
146 | if (NULL == stmt) | 146 | if (NULL == stmt) |
147 | { | 147 | { |
148 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 148 | GNUNET_break (0); |
149 | ("`%s' failed at %s:%d with error: %s\n"), | ||
150 | "mysql_stmt_bind_result", __FILE__, __LINE__, | ||
151 | mysql_stmt_error (stmt)); | ||
152 | return GNUNET_SYSERR; | 149 | return GNUNET_SYSERR; |
153 | } | 150 | } |
151 | if (NULL == rs) | ||
152 | { | ||
153 | mysql_stmt_free_result (stmt); | ||
154 | return GNUNET_NO; | ||
155 | } | ||
154 | 156 | ||
155 | num_fields = 0; | 157 | num_fields = 0; |
156 | for (i=0;NULL != rs[i].pre_conv;i++) | 158 | for (i=0;NULL != rs[i].pre_conv;i++) |
@@ -187,25 +189,32 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
187 | } | 189 | } |
188 | field_off += rp->num_fields; | 190 | field_off += rp->num_fields; |
189 | } | 191 | } |
192 | |||
190 | if (mysql_stmt_bind_result (stmt, result)) | 193 | if (mysql_stmt_bind_result (stmt, result)) |
191 | { | 194 | { |
192 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 195 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
193 | "my", | 196 | "my", |
194 | _("`%s' failed at %s:%d with error: %s\n"), | 197 | _("%s failed at %s:%d with error: %s\n"), |
195 | "mysql_stmt_bind_result", __FILE__, __LINE__, | 198 | "mysql_stmt_bind_result", |
199 | __FILE__, __LINE__, | ||
196 | mysql_stmt_error (stmt)); | 200 | mysql_stmt_error (stmt)); |
197 | return GNUNET_SYSERR; | 201 | return GNUNET_SYSERR; |
198 | } | 202 | } |
199 | 203 | #if TEST_OPTIMIZATION | |
204 | (void) mysql_stmt_store_result (stmt); | ||
205 | #endif | ||
200 | ret = mysql_stmt_fetch (stmt); | 206 | ret = mysql_stmt_fetch (stmt); |
201 | |||
202 | if (MYSQL_NO_DATA == ret) | 207 | if (MYSQL_NO_DATA == ret) |
208 | { | ||
209 | mysql_stmt_free_result (stmt); | ||
203 | return GNUNET_NO; | 210 | return GNUNET_NO; |
204 | if ((0 != ret ) && (MYSQL_DATA_TRUNCATED != ret)) | 211 | } |
212 | if (1 == ret) | ||
205 | { | 213 | { |
206 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 214 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
207 | "my", | 215 | "my", |
208 | _("mysql_stmt_fetch failed at %s:%d with error: %s\n"), | 216 | _("%s failed at %s:%d with error: %s\n"), |
217 | "mysql_stmt_fetch", | ||
209 | __FILE__, __LINE__, | 218 | __FILE__, __LINE__, |
210 | mysql_stmt_error (stmt)); | 219 | mysql_stmt_error (stmt)); |
211 | GNUNET_MY_cleanup_result (rs); | 220 | GNUNET_MY_cleanup_result (rs); |
@@ -235,7 +244,6 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
235 | field_off += rp->num_fields; | 244 | field_off += rp->num_fields; |
236 | } | 245 | } |
237 | } | 246 | } |
238 | mysql_stmt_free_result (stmt); | ||
239 | return GNUNET_OK; | 247 | return GNUNET_OK; |
240 | } | 248 | } |
241 | 249 | ||