diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-06 16:11:56 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-06 16:11:56 +0000 |
commit | 3b680a20ab2cbb98cfa658d85be7a44baaf95d2c (patch) | |
tree | 6217c36e0ace8a7892a0a1567f13e9985903c7d6 /src/my | |
parent | 67dc0efd426a379b818155ed87f3c1a76d9e352f (diff) | |
download | gnunet-3b680a20ab2cbb98cfa658d85be7a44baaf95d2c.tar.gz gnunet-3b680a20ab2cbb98cfa658d85be7a44baaf95d2c.zip |
continue to fix extract result
Diffstat (limited to 'src/my')
-rw-r--r-- | src/my/my.c | 9 | ||||
-rw-r--r-- | src/my/my_query_helper.c | 68 | ||||
-rw-r--r-- | src/my/my_result_helper.c | 19 | ||||
-rw-r--r-- | src/my/test_my.c | 50 |
4 files changed, 85 insertions, 61 deletions
diff --git a/src/my/my.c b/src/my/my.c index d4e72ae7c..ef11fbe74 100644 --- a/src/my/my.c +++ b/src/my/my.c | |||
@@ -173,7 +173,16 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
173 | mysql_stmt_error (stmt)); | 173 | mysql_stmt_error (stmt)); |
174 | return GNUNET_SYSERR; | 174 | return GNUNET_SYSERR; |
175 | } | 175 | } |
176 | |||
176 | ret = mysql_stmt_fetch (stmt); | 177 | ret = mysql_stmt_fetch (stmt); |
178 | |||
179 | if (MYSQL_DATA_TRUNCATED == ret) | ||
180 | { | ||
181 | fprintf(stderr, "Data truncated with error %d \n", ret); | ||
182 | fprintf(stderr, "nontruncated length of the parameter values : %d\n", rs[0].mysql_bind_output_length); | ||
183 | return GNUNET_SYSERR; | ||
184 | } | ||
185 | |||
177 | if (MYSQL_NO_DATA == ret) | 186 | if (MYSQL_NO_DATA == ret) |
178 | return GNUNET_NO; | 187 | return GNUNET_NO; |
179 | if (0 != ret) | 188 | if (0 != ret) |
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index 6bbbf0b51..07eb2481d 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c | |||
@@ -61,11 +61,11 @@ GNUNET_MY_query_param_fixed_size (const void *ptr, | |||
61 | size_t ptr_size) | 61 | size_t ptr_size) |
62 | { | 62 | { |
63 | struct GNUNET_MY_QueryParam qp = { | 63 | struct GNUNET_MY_QueryParam qp = { |
64 | &my_conv_fixed_size, | 64 | .conv = &my_conv_fixed_size, |
65 | NULL, | 65 | .conv_cls = NULL, |
66 | 1, | 66 | .num_params = 1, |
67 | ptr, | 67 | .data = ptr, |
68 | (unsigned long) ptr_size | 68 | .data_len = (unsigned long) ptr_size |
69 | }; | 69 | }; |
70 | return qp; | 70 | return qp; |
71 | } | 71 | } |
@@ -125,11 +125,11 @@ struct GNUNET_MY_QueryParam | |||
125 | GNUNET_MY_query_param_uint16 (const uint16_t *x) | 125 | GNUNET_MY_query_param_uint16 (const uint16_t *x) |
126 | { | 126 | { |
127 | struct GNUNET_MY_QueryParam res = { | 127 | struct GNUNET_MY_QueryParam res = { |
128 | &my_conv_uint16, | 128 | .conv = &my_conv_uint16, |
129 | NULL, | 129 | .conv_cls = NULL, |
130 | 1, | 130 | .num_params = 1, |
131 | x, | 131 | .data = x, |
132 | sizeof (*x) | 132 | .data_len = sizeof (*x) |
133 | }; | 133 | }; |
134 | 134 | ||
135 | return res; | 135 | return res; |
@@ -173,11 +173,11 @@ struct GNUNET_MY_QueryParam | |||
173 | GNUNET_MY_query_param_uint32 (const uint32_t *x) | 173 | GNUNET_MY_query_param_uint32 (const uint32_t *x) |
174 | { | 174 | { |
175 | struct GNUNET_MY_QueryParam res = { | 175 | struct GNUNET_MY_QueryParam res = { |
176 | &my_conv_uint32, | 176 | .conv = &my_conv_uint32, |
177 | NULL, | 177 | .conv_cls = NULL, |
178 | 1, | 178 | .num_params = 1, |
179 | x, | 179 | .data = x, |
180 | sizeof (*x) | 180 | .data_len = sizeof (*x) |
181 | }; | 181 | }; |
182 | 182 | ||
183 | return res; | 183 | return res; |
@@ -221,11 +221,11 @@ struct GNUNET_MY_QueryParam | |||
221 | GNUNET_MY_query_param_uint64 (const uint64_t *x) | 221 | GNUNET_MY_query_param_uint64 (const uint64_t *x) |
222 | { | 222 | { |
223 | struct GNUNET_MY_QueryParam res = { | 223 | struct GNUNET_MY_QueryParam res = { |
224 | &my_conv_uint64, | 224 | .conv = &my_conv_uint64, |
225 | NULL, | 225 | .conv_cls = NULL, |
226 | 1, | 226 | .num_params = 1, |
227 | x, | 227 | .data = x, |
228 | sizeof(*x) | 228 | .data_len = sizeof(*x) |
229 | }; | 229 | }; |
230 | 230 | ||
231 | return res; | 231 | return res; |
@@ -253,8 +253,8 @@ my_conv_rsa_public_key (void *cls, | |||
253 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf); | 253 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf); |
254 | 254 | ||
255 | qbind->buffer = (void *)buf; | 255 | qbind->buffer = (void *)buf; |
256 | qbind->buffer_length = buf_size - 1; | 256 | qbind->buffer_length = buf_size-1; |
257 | qbind->buffer_type = MYSQL_TYPE_LONG; | 257 | qbind->buffer_type = MYSQL_TYPE_BLOB; |
258 | 258 | ||
259 | return 1; | 259 | return 1; |
260 | } | 260 | } |
@@ -270,11 +270,11 @@ struct GNUNET_MY_QueryParam | |||
270 | GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) | 270 | GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) |
271 | { | 271 | { |
272 | struct GNUNET_MY_QueryParam res = { | 272 | struct GNUNET_MY_QueryParam res = { |
273 | &my_conv_rsa_public_key, | 273 | .conv = &my_conv_rsa_public_key, |
274 | NULL, | 274 | .conv_cls = NULL, |
275 | 1, | 275 | .num_params = 1, |
276 | x, | 276 | .data = x, |
277 | 0 | 277 | .data_len = 0 |
278 | }; | 278 | }; |
279 | 279 | ||
280 | return res; | 280 | return res; |
@@ -303,8 +303,8 @@ my_conv_rsa_signature (void *cls, | |||
303 | &buf); | 303 | &buf); |
304 | 304 | ||
305 | qbind->buffer = (void *)buf; | 305 | qbind->buffer = (void *)buf; |
306 | qbind->buffer_length = buf_size - 1; | 306 | qbind->buffer_length = buf_size-1; |
307 | qbind->buffer_type = MYSQL_TYPE_LONG; | 307 | qbind->buffer_type = MYSQL_TYPE_BLOB; |
308 | 308 | ||
309 | return 1; | 309 | return 1; |
310 | } | 310 | } |
@@ -320,11 +320,11 @@ struct GNUNET_MY_QueryParam | |||
320 | GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | 320 | GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) |
321 | { | 321 | { |
322 | struct GNUNET_MY_QueryParam res = { | 322 | struct GNUNET_MY_QueryParam res = { |
323 | &my_conv_rsa_signature, | 323 | .conv = &my_conv_rsa_signature, |
324 | NULL, | 324 | .conv_cls = NULL, |
325 | 1, | 325 | .num_params = 1, |
326 | (x), | 326 | .data = (x), |
327 | 0 | 327 | .data_len = 0 |
328 | }; | 328 | }; |
329 | return res; | 329 | return res; |
330 | } | 330 | } |
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c index eafe434f8..97cc1f1bf 100644 --- a/src/my/my_result_helper.c +++ b/src/my/my_result_helper.c | |||
@@ -37,9 +37,10 @@ pre_extract_varsize_blob (void *cls, | |||
37 | unsigned int column, | 37 | unsigned int column, |
38 | MYSQL_BIND *results) | 38 | MYSQL_BIND *results) |
39 | { | 39 | { |
40 | results[0].buffer = 0; | 40 | results[0].buffer = NULL; |
41 | results[0].buffer_length = 0; | 41 | results[0].buffer_length = 0; |
42 | results[0].length = &rs->mysql_bind_output_length; | 42 | results[0].length = &rs->mysql_bind_output_length; |
43 | results[0].buffer_type = MYSQL_TYPE_BLOB; | ||
43 | 44 | ||
44 | return GNUNET_OK; | 45 | return GNUNET_OK; |
45 | } | 46 | } |
@@ -73,6 +74,7 @@ post_extract_varsize_blob (void *cls, | |||
73 | buf = GNUNET_malloc (size); | 74 | buf = GNUNET_malloc (size); |
74 | results[0].buffer = buf; | 75 | results[0].buffer = buf; |
75 | results[0].buffer_length = size; | 76 | results[0].buffer_length = size; |
77 | |||
76 | if (0 != | 78 | if (0 != |
77 | mysql_stmt_fetch_column (stmt, | 79 | mysql_stmt_fetch_column (stmt, |
78 | results, | 80 | results, |
@@ -235,10 +237,10 @@ pre_extract_rsa_public_key (void *cls, | |||
235 | MYSQL_BIND *results) | 237 | MYSQL_BIND *results) |
236 | 238 | ||
237 | { | 239 | { |
238 | results[0].buffer = 0; | 240 | results[0].buffer = NULL; |
239 | results[0].buffer_length = 0; | 241 | results[0].buffer_length = 0; |
240 | results[0].length = rs->mysql_bind_output_length; | 242 | results[0].length = &rs->mysql_bind_output_length; |
241 | results[0].buffer_type = MYSQL_TYPE_LONG; | 243 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
242 | 244 | ||
243 | return GNUNET_OK; | 245 | return GNUNET_OK; |
244 | } | 246 | } |
@@ -292,9 +294,6 @@ post_extract_rsa_public_key (void *cls, | |||
292 | return GNUNET_SYSERR; | 294 | return GNUNET_SYSERR; |
293 | } | 295 | } |
294 | 296 | ||
295 | if (rs->dst_size != rs->mysql_bind_output_length) | ||
296 | return GNUNET_SYSERR; | ||
297 | |||
298 | return GNUNET_OK; | 297 | return GNUNET_OK; |
299 | } | 298 | } |
300 | 299 | ||
@@ -366,7 +365,7 @@ pre_extract_rsa_signature (void *cls, | |||
366 | results[0].buffer = 0; | 365 | results[0].buffer = 0; |
367 | results[0].buffer_length = 0; | 366 | results[0].buffer_length = 0; |
368 | results[0].length = &rs->mysql_bind_output_length; | 367 | results[0].length = &rs->mysql_bind_output_length; |
369 | results[0].buffer_type = MYSQL_TYPE_LONG; | 368 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
370 | 369 | ||
371 | return GNUNET_OK; | 370 | return GNUNET_OK; |
372 | } | 371 | } |
@@ -391,8 +390,8 @@ post_extract_rsa_signature (void *cls, | |||
391 | MYSQL_BIND *results) | 390 | MYSQL_BIND *results) |
392 | { | 391 | { |
393 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; | 392 | struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; |
394 | size_t size; | 393 | size_t size = 0 ; |
395 | const char *res; | 394 | char *res = NULL; |
396 | 395 | ||
397 | results[0].buffer = res; | 396 | results[0].buffer = res; |
398 | results[0].buffer_length = size; | 397 | results[0].buffer_length = size; |
diff --git a/src/my/test_my.c b/src/my/test_my.c index c9529cbaf..af15b6ab2 100644 --- a/src/my/test_my.c +++ b/src/my/test_my.c | |||
@@ -75,8 +75,8 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
75 | u32 = 32; | 75 | u32 = 32; |
76 | u64 = 64; | 76 | u64 = 64; |
77 | 77 | ||
78 | /* statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, | 78 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, |
79 | "INSERT INTO test_my (" | 79 | "INSERT INTO test_my2 (" |
80 | " pub" | 80 | " pub" |
81 | ",sig" | 81 | ",sig" |
82 | ",abs_time" | 82 | ",abs_time" |
@@ -107,26 +107,28 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
107 | GNUNET_MY_query_param_uint64 (&u64), | 107 | GNUNET_MY_query_param_uint64 (&u64), |
108 | GNUNET_MY_query_param_end | 108 | GNUNET_MY_query_param_end |
109 | }; | 109 | }; |
110 | */ | 110 | |
111 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, | 111 | /* statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, |
112 | "INSERT INTO test_my2 (" | 112 | "INSERT INTO test_my2 (" |
113 | " abs_time" | 113 | " abs_time" |
114 | ",forever" | 114 | ",forever" |
115 | ",hash" | ||
115 | ",u16" | 116 | ",u16" |
116 | ",u32" | 117 | ",u32" |
117 | ",u64" | 118 | ",u64" |
118 | ") VALUES " | 119 | ") VALUES " |
119 | "( ?, ?, ?, ?, ?)"); | 120 | "( ?, ?, ?, ?, ?, ?)"); |
120 | 121 | ||
121 | struct GNUNET_MY_QueryParam params_insert[] = { | 122 | struct GNUNET_MY_QueryParam params_insert[] = { |
122 | GNUNET_MY_query_param_absolute_time (&abs_time), | 123 | GNUNET_MY_query_param_absolute_time (&abs_time), |
123 | GNUNET_MY_query_param_absolute_time (&forever), | 124 | GNUNET_MY_query_param_absolute_time (&forever), |
125 | GNUNET_MY_query_param_auto_from_type (&hc), | ||
124 | GNUNET_MY_query_param_uint16 (&u16), | 126 | GNUNET_MY_query_param_uint16 (&u16), |
125 | GNUNET_MY_query_param_uint32 (&u32), | 127 | GNUNET_MY_query_param_uint32 (&u32), |
126 | GNUNET_MY_query_param_uint64 (&u64), | 128 | GNUNET_MY_query_param_uint64 (&u64), |
127 | GNUNET_MY_query_param_end | 129 | GNUNET_MY_query_param_end |
128 | }; | 130 | }; |
129 | 131 | */ | |
130 | if (GNUNET_OK != GNUNET_MY_exec_prepared(context, | 132 | if (GNUNET_OK != GNUNET_MY_exec_prepared(context, |
131 | statements_handle_insert, | 133 | statements_handle_insert, |
132 | params_insert)) | 134 | params_insert)) |
@@ -155,8 +157,12 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
155 | */ | 157 | */ |
156 | statements_handle_select = GNUNET_MYSQL_statement_prepare (context, | 158 | statements_handle_select = GNUNET_MYSQL_statement_prepare (context, |
157 | "SELECT" | 159 | "SELECT" |
160 | //" pub" | ||
161 | //" sig" | ||
158 | " abs_time" | 162 | " abs_time" |
159 | ",forever" | 163 | ",forever" |
164 | ",hash" | ||
165 | //" vsize" | ||
160 | ",u16" | 166 | ",u16" |
161 | ",u32" | 167 | ",u32" |
162 | ",u64" | 168 | ",u64" |
@@ -195,8 +201,12 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
195 | }; | 201 | }; |
196 | */ | 202 | */ |
197 | struct GNUNET_MY_ResultSpec results_select[] = { | 203 | struct GNUNET_MY_ResultSpec results_select[] = { |
204 | //GNUNET_MY_result_spec_rsa_public_key (&pub2), | ||
205 | //GNUNET_MY_result_spec_rsa_signature (&sig2), | ||
198 | GNUNET_MY_result_spec_absolute_time (&abs_time2), | 206 | GNUNET_MY_result_spec_absolute_time (&abs_time2), |
199 | GNUNET_MY_result_spec_absolute_time (&forever2), | 207 | GNUNET_MY_result_spec_absolute_time (&forever2), |
208 | GNUNET_MY_result_spec_auto_from_type (&hc2), | ||
209 | //GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), | ||
200 | GNUNET_MY_result_spec_uint16 (&u162), | 210 | GNUNET_MY_result_spec_uint16 (&u162), |
201 | GNUNET_MY_result_spec_uint32 (&u322), | 211 | GNUNET_MY_result_spec_uint32 (&u322), |
202 | GNUNET_MY_result_spec_uint64 (&u642), | 212 | GNUNET_MY_result_spec_uint64 (&u642), |
@@ -206,8 +216,13 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
206 | ret = GNUNET_MY_extract_result (statements_handle_select, | 216 | ret = GNUNET_MY_extract_result (statements_handle_select, |
207 | results_select); | 217 | results_select); |
208 | 218 | ||
219 | GNUNET_break (GNUNET_YES == ret); | ||
209 | GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); | 220 | GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); |
210 | GNUNET_break (forever.abs_value_us == forever2.abs_value_us); | 221 | GNUNET_break (forever.abs_value_us == forever2.abs_value_us); |
222 | GNUNET_break (0 == | ||
223 | memcmp (&hc, | ||
224 | &hc2, | ||
225 | sizeof (struct GNUNET_HashCode))); | ||
211 | 226 | ||
212 | GNUNET_break (16 == u162); | 227 | GNUNET_break (16 == u162); |
213 | GNUNET_break (32 == u322); | 228 | GNUNET_break (32 == u322); |
@@ -256,14 +271,14 @@ main (int argc, const char * const argv[]) | |||
256 | return 77; | 271 | return 77; |
257 | } | 272 | } |
258 | 273 | ||
259 | /* if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, | 274 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, |
260 | "CREATE TABLE test_my(" | 275 | "CREATE TABLE test_my2(" |
261 | "pub INT NOT NULL" | 276 | "pub BLOB NOT NULL" |
262 | ", sig INT NOT NULL" | 277 | ", sig BLOB NOT NULL" |
263 | ", abs_time BIGINT NOT NULL" | 278 | ", abs_time BIGINT NOT NULL" |
264 | ", forever BIGINT NOT NULL" | 279 | ", forever BIGINT NOT NULL" |
265 | ", hash VARCHAR(32) NOT NULL CHECK(LENGTH(hash)=64)" | 280 | ", hash BLOB NOT NULL CHECK(LENGTH(hash)=64)" |
266 | ", vsize VARCHAR(32) NOT NULL" | 281 | ", vsize BLOB NOT NULL" |
267 | ", u16 SMALLINT NOT NULL" | 282 | ", u16 SMALLINT NOT NULL" |
268 | ", u32 INT NOT NULL" | 283 | ", u32 INT NOT NULL" |
269 | ", u64 BIGINT NOT NULL" | 284 | ", u64 BIGINT NOT NULL" |
@@ -276,11 +291,12 @@ main (int argc, const char * const argv[]) | |||
276 | 291 | ||
277 | return 1; | 292 | return 1; |
278 | } | 293 | } |
279 | */ | 294 | |
280 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, | 295 | /* if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, |
281 | "CREATE TABLE test_my2(" | 296 | "CREATE TABLE test_my2(" |
282 | " abs_time BIGINT NOT NULL" | 297 | " abs_time BIGINT NOT NULL" |
283 | ", forever BIGINT NOT NULL" | 298 | ", forever BIGINT NOT NULL" |
299 | ", hash VARCHAR(32) NOT NULL CHECK(LENGTH(hash)=64)" | ||
284 | ", u16 SMALLINT NOT NULL" | 300 | ", u16 SMALLINT NOT NULL" |
285 | ", u32 INT NOT NULL" | 301 | ", u32 INT NOT NULL" |
286 | ", u64 BIGINT NOT NULL" | 302 | ", u64 BIGINT NOT NULL" |
@@ -293,10 +309,10 @@ main (int argc, const char * const argv[]) | |||
293 | 309 | ||
294 | return 1; | 310 | return 1; |
295 | } | 311 | } |
296 | 312 | */ | |
297 | ret = run_queries (context); | 313 | ret = run_queries (context); |
298 | /* | 314 | |
299 | if(GNUNET_OK != GNUNET_MYSQL_statement_run (context, | 315 | /* if(GNUNET_OK != GNUNET_MYSQL_statement_run (context, |
300 | "DROP TABLE test_my2")) | 316 | "DROP TABLE test_my2")) |
301 | { | 317 | { |
302 | fprintf (stderr, "Failed to drop table test_my\n"); | 318 | fprintf (stderr, "Failed to drop table test_my\n"); |