diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-01 17:13:39 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-01 17:13:39 +0000 |
commit | 88dd25332f857f13724442b7d60980a44fae6350 (patch) | |
tree | 2fc025e95553244b13ca9ca291bc3c1ab2b72907 | |
parent | 1ac9ef013b0e9c737d6909ab41a38b45a3d36e43 (diff) | |
download | gnunet-88dd25332f857f13724442b7d60980a44fae6350.tar.gz gnunet-88dd25332f857f13724442b7d60980a44fae6350.zip |
fixing insert query
-rw-r--r-- | src/include/gnunet_my_lib.h | 1 | ||||
-rw-r--r-- | src/my/my.c | 2 | ||||
-rw-r--r-- | src/my/my_query_helper.c | 19 | ||||
-rw-r--r-- | src/my/test_my.c | 74 |
4 files changed, 65 insertions, 31 deletions
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index ffba2a66c..c0a6f4b90 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h | |||
@@ -99,7 +99,6 @@ struct GNUNET_MY_QueryParam | |||
99 | 99 | ||
100 | }; | 100 | }; |
101 | 101 | ||
102 | |||
103 | /** | 102 | /** |
104 | * End of query parameter specification. | 103 | * End of query parameter specification. |
105 | * | 104 | * |
diff --git a/src/my/my.c b/src/my/my.c index 7f01d7f63..6c4ab6942 100644 --- a/src/my/my.c +++ b/src/my/my.c | |||
@@ -81,6 +81,7 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
81 | GNUNET_MYSQL_statements_invalidate (mc); | 81 | GNUNET_MYSQL_statements_invalidate (mc); |
82 | return GNUNET_SYSERR; | 82 | return GNUNET_SYSERR; |
83 | } | 83 | } |
84 | |||
84 | } | 85 | } |
85 | if (mysql_stmt_execute (stmt)) | 86 | if (mysql_stmt_execute (stmt)) |
86 | { | 87 | { |
@@ -91,6 +92,7 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
91 | GNUNET_MYSQL_statements_invalidate (mc); | 92 | GNUNET_MYSQL_statements_invalidate (mc); |
92 | return GNUNET_SYSERR; | 93 | return GNUNET_SYSERR; |
93 | } | 94 | } |
95 | |||
94 | return GNUNET_OK; | 96 | return GNUNET_OK; |
95 | } | 97 | } |
96 | 98 | ||
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index a8a9ce7b6..4ea1b4ffe 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c | |||
@@ -43,9 +43,8 @@ my_conv_fixed_size (void *cls, | |||
43 | 43 | ||
44 | qbind->buffer = (void *) qp->data; | 44 | qbind->buffer = (void *) qp->data; |
45 | qbind->buffer_length = qp->data_len; | 45 | qbind->buffer_length = qp->data_len; |
46 | qbind->buffer_type = 1; | 46 | qbind->buffer_type = MYSQL_TYPE_BLOB; |
47 | 47 | ||
48 | //return 0; | ||
49 | return 1; | 48 | return 1; |
50 | } | 49 | } |
51 | 50 | ||
@@ -100,18 +99,18 @@ my_conv_uint16 (void *cls, | |||
100 | const uint16_t *u_hbo = qp->data; | 99 | const uint16_t *u_hbo = qp->data; |
101 | uint16_t *u_nbo; | 100 | uint16_t *u_nbo; |
102 | 101 | ||
103 | fprintf(stderr, "input data : %u\n", (unsigned)u_hbo); | ||
104 | |||
105 | GNUNET_assert (1 == qp->num_params); | 102 | GNUNET_assert (1 == qp->num_params); |
106 | 103 | ||
107 | 104 | ||
108 | u_nbo = GNUNET_new (uint16_t); | 105 | u_nbo = GNUNET_new (uint16_t); |
106 | if (NULL == u_nbo) | ||
107 | return -1; | ||
108 | |||
109 | *u_nbo = htons (*u_hbo); | 109 | *u_nbo = htons (*u_hbo); |
110 | 110 | ||
111 | fprintf(stderr, "output data : %u\n", (unsigned)u_nbo); | ||
112 | qbind->buffer = (void *) u_nbo; | 111 | qbind->buffer = (void *) u_nbo; |
113 | qbind->buffer_length = sizeof(uint16_t); | 112 | qbind->buffer_length = sizeof(uint16_t); |
114 | qbind->buffer_type = 1; | 113 | qbind->buffer_type = MYSQL_TYPE_SHORT; |
115 | 114 | ||
116 | return 1; | 115 | return 1; |
117 | } | 116 | } |
@@ -158,7 +157,7 @@ my_conv_uint32 (void *cls, | |||
158 | 157 | ||
159 | qbind->buffer = (void *) u_nbo; | 158 | qbind->buffer = (void *) u_nbo; |
160 | qbind->buffer_length = sizeof(uint32_t); | 159 | qbind->buffer_length = sizeof(uint32_t); |
161 | qbind->buffer_type = 1; | 160 | qbind->buffer_type = MYSQL_TYPE_LONG; |
162 | 161 | ||
163 | return 1; | 162 | return 1; |
164 | } | 163 | } |
@@ -205,7 +204,7 @@ my_conv_uint64 (void *cls, | |||
205 | 204 | ||
206 | qbind->buffer = (void *) u_nbo; | 205 | qbind->buffer = (void *) u_nbo; |
207 | qbind->buffer_length = sizeof (uint64_t); | 206 | qbind->buffer_length = sizeof (uint64_t); |
208 | qbind->buffer_type = 1; | 207 | qbind->buffer_type = MYSQL_TYPE_LONGLONG; |
209 | 208 | ||
210 | return 1; | 209 | return 1; |
211 | } | 210 | } |
@@ -252,7 +251,7 @@ my_conv_rsa_public_key (void *cls, | |||
252 | 251 | ||
253 | qbind->buffer = (void *)buf; | 252 | qbind->buffer = (void *)buf; |
254 | qbind->buffer_length = buf_size - 1; | 253 | qbind->buffer_length = buf_size - 1; |
255 | qbind->buffer_type = 1; | 254 | qbind->buffer_type = MYSQL_TYPE_LONG; |
256 | 255 | ||
257 | return 1; | 256 | return 1; |
258 | } | 257 | } |
@@ -302,7 +301,7 @@ my_conv_rsa_signature (void *cls, | |||
302 | 301 | ||
303 | qbind->buffer = (void *)buf; | 302 | qbind->buffer = (void *)buf; |
304 | qbind->buffer_length = buf_size - 1; | 303 | qbind->buffer_length = buf_size - 1; |
305 | qbind->buffer_type = 1; | 304 | qbind->buffer_type = MYSQL_TYPE_LONG; |
306 | 305 | ||
307 | return 1; | 306 | return 1; |
308 | } | 307 | } |
diff --git a/src/my/test_my.c b/src/my/test_my.c index 067d70a6e..d213bf547 100644 --- a/src/my/test_my.c +++ b/src/my/test_my.c | |||
@@ -37,17 +37,34 @@ | |||
37 | static int | 37 | static int |
38 | run_queries (struct GNUNET_MYSQL_Context *context) | 38 | run_queries (struct GNUNET_MYSQL_Context *context) |
39 | { | 39 | { |
40 | const struct GNUNET_CRYPTO_RsaPublicKey *pub; | 40 | struct GNUNET_CRYPTO_RsaPublicKey *pub; |
41 | // struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; | ||
41 | struct GNUNET_CRYPTO_RsaSignature *sig; | 42 | struct GNUNET_CRYPTO_RsaSignature *sig; |
43 | // struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; | ||
42 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); | 44 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); |
45 | // struct GNUNET_TIME_Absolute abs_time2; | ||
43 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; | 46 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; |
47 | // struct GNUNET_TIME_Absolute forever2; | ||
44 | struct GNUNET_HashCode hc; | 48 | struct GNUNET_HashCode hc; |
49 | // struct GNUNET_HashCode hc2; | ||
45 | const char msg[] = "hello"; | 50 | const char msg[] = "hello"; |
51 | // void *msg2; | ||
52 | size_t msg_len; | ||
53 | // size_t msg2_len; | ||
54 | |||
46 | uint16_t u16; | 55 | uint16_t u16; |
56 | // uint16_t u162; | ||
47 | uint32_t u32; | 57 | uint32_t u32; |
58 | // uint32_t u322; | ||
48 | uint64_t u64; | 59 | uint64_t u64; |
60 | // uint64_t u642; | ||
61 | |||
62 | msg_len = sizeof(msg); | ||
63 | |||
64 | // int ret; | ||
49 | 65 | ||
50 | struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; | 66 | struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; |
67 | |||
51 | // struct GNUNET_MYSQL_StatementHandle *statements_handle_select; | 68 | // struct GNUNET_MYSQL_StatementHandle *statements_handle_select; |
52 | 69 | ||
53 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; | 70 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; |
@@ -62,7 +79,6 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
62 | u32 = 32; | 79 | u32 = 32; |
63 | u64 = 64; | 80 | u64 = 64; |
64 | 81 | ||
65 | // FIXE THE INSERT QUERY | ||
66 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, | 82 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, |
67 | "INSERT INTO test_my (" | 83 | "INSERT INTO test_my (" |
68 | " pub" | 84 | " pub" |
@@ -75,8 +91,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
75 | ",u32" | 91 | ",u32" |
76 | ",u64" | 92 | ",u64" |
77 | ") VALUES " | 93 | ") VALUES " |
78 | "(?, ?, ?, ?, ?, ?," | 94 | "( ?, ?, ?, ?, ?, ?, ?, ?, ?)"); |
79 | "?, ?, ?)"); | ||
80 | 95 | ||
81 | if (NULL == statements_handle_insert) | 96 | if (NULL == statements_handle_insert) |
82 | { | 97 | { |
@@ -84,7 +99,6 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
84 | return 1; | 99 | return 1; |
85 | } | 100 | } |
86 | 101 | ||
87 | //ERROR WITH MSG | ||
88 | struct GNUNET_MY_QueryParam params_insert[] = { | 102 | struct GNUNET_MY_QueryParam params_insert[] = { |
89 | GNUNET_MY_query_param_rsa_public_key (pub), | 103 | GNUNET_MY_query_param_rsa_public_key (pub), |
90 | GNUNET_MY_query_param_rsa_signature (sig), | 104 | GNUNET_MY_query_param_rsa_signature (sig), |
@@ -98,21 +112,17 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
98 | GNUNET_MY_query_param_end | 112 | GNUNET_MY_query_param_end |
99 | }; | 113 | }; |
100 | 114 | ||
101 | fprintf(stderr, " u16 : %u\n", (unsigned)params_insert[6].data); | 115 | if (GNUNET_OK != GNUNET_MY_exec_prepared(context, |
102 | fprintf(stderr, " &u16 : %u\n", (unsigned)&u16); | ||
103 | |||
104 | //FAIL HERE | ||
105 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, | ||
106 | statements_handle_insert, | 116 | statements_handle_insert, |
107 | params_insert)) | 117 | params_insert)) |
108 | { | 118 | { |
109 | fprintf (stderr, | 119 | fprintf (stderr, "Failed to execute prepared statement INSERT\n"); |
110 | "Failed to execute prepared statement\n"); | 120 | return 1; |
111 | return 22; | ||
112 | } | 121 | } |
113 | 122 | ||
114 | /* NOT THE GOOD FUNCTION -> TO FIXE | 123 | |
115 | statements_handle_select = GNUNET_MYSQL_statement_prepare (context, | 124 | |
125 | /* statements_handle_select = GNUNET_MYSQL_statement_prepare (context, | ||
116 | "SELECT" | 126 | "SELECT" |
117 | " pub" | 127 | " pub" |
118 | ",sig" | 128 | ",sig" |
@@ -141,8 +151,32 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
141 | statements_handle_select, | 151 | statements_handle_select, |
142 | params_select)) | 152 | params_select)) |
143 | { | 153 | { |
144 | fprintf (stderr, "Failed to execute prepared statement\n"); | 154 | fprintf (stderr, "Failed to execute prepared statement SELECT\n"); |
145 | return 22; | 155 | return 1; |
156 | } | ||
157 | |||
158 | |||
159 | struct GNUNET_MY_ResultSpec results_select[] = { | ||
160 | GNUNET_MY_result_spec_rsa_public_key (&pub2), | ||
161 | GNUNET_MY_result_spec_rsa_signature (&sig2), | ||
162 | GNUNET_MY_result_spec_absolute_time (&abs_time2), | ||
163 | GNUNET_MY_result_spec_absolute_time (&forever2), | ||
164 | GNUNET_MY_result_spec_auto_from_type (&hc2), | ||
165 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), | ||
166 | GNUNET_MY_result_spec_uint16 (&u162), | ||
167 | GNUNET_MY_result_spec_uint32 (&u322), | ||
168 | GNUNET_MY_result_spec_uint64 (&u642), | ||
169 | GNUNET_MY_result_spec_end | ||
170 | }; | ||
171 | |||
172 | ret = GNUNET_MY_extract_result (statements_handle_select, | ||
173 | NULL, | ||
174 | results_select, | ||
175 | 0); | ||
176 | if (GNUNET_OK != ret) | ||
177 | { | ||
178 | fprintf(stderr, "Failed to extract result\n"); | ||
179 | return 1; | ||
146 | } | 180 | } |
147 | */ | 181 | */ |
148 | return 0; | 182 | return 0; |
@@ -188,7 +222,7 @@ main (int argc, const char * const argv[]) | |||
188 | ", sig INT NOT NULL" | 222 | ", sig INT NOT NULL" |
189 | ", abs_time BIGINT NOT NULL" | 223 | ", abs_time BIGINT NOT NULL" |
190 | ", forever BIGINT NOT NULL" | 224 | ", forever BIGINT NOT NULL" |
191 | ", hash INT NOT NULL CHECK(LENGTH(hash)=64)" | 225 | ", hash VARCHAR(32) NOT NULL CHECK(LENGTH(hash)=64)" |
192 | ", vsize VARCHAR(32) NOT NULL" | 226 | ", vsize VARCHAR(32) NOT NULL" |
193 | ", u16 SMALLINT NOT NULL" | 227 | ", u16 SMALLINT NOT NULL" |
194 | ", u32 INT NOT NULL" | 228 | ", u32 INT NOT NULL" |
@@ -205,13 +239,13 @@ main (int argc, const char * const argv[]) | |||
205 | 239 | ||
206 | ret = run_queries (context); | 240 | ret = run_queries (context); |
207 | 241 | ||
208 | if(GNUNET_OK != GNUNET_MYSQL_statement_run (context, | 242 | /* if(GNUNET_OK != GNUNET_MYSQL_statement_run (context, |
209 | "DROP TABLE test_my")) | 243 | "DROP TABLE test_my")) |
210 | { | 244 | { |
211 | fprintf (stderr, "Failed to drop table test_my\n"); | 245 | fprintf (stderr, "Failed to drop table test_my\n"); |
212 | GNUNET_MYSQL_statements_invalidate (context); | 246 | GNUNET_MYSQL_statements_invalidate (context); |
213 | } | 247 | } |
214 | 248 | */ | |
215 | GNUNET_MYSQL_context_destroy (context); | 249 | GNUNET_MYSQL_context_destroy (context); |
216 | 250 | ||
217 | return ret; | 251 | return ret; |