aboutsummaryrefslogtreecommitdiff
path: root/src/my/test_my.c
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-01 17:13:39 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-01 17:13:39 +0000
commit88dd25332f857f13724442b7d60980a44fae6350 (patch)
tree2fc025e95553244b13ca9ca291bc3c1ab2b72907 /src/my/test_my.c
parent1ac9ef013b0e9c737d6909ab41a38b45a3d36e43 (diff)
downloadgnunet-88dd25332f857f13724442b7d60980a44fae6350.tar.gz
gnunet-88dd25332f857f13724442b7d60980a44fae6350.zip
fixing insert query
Diffstat (limited to 'src/my/test_my.c')
-rw-r--r--src/my/test_my.c74
1 files changed, 54 insertions, 20 deletions
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 @@
37static int 37static int
38run_queries (struct GNUNET_MYSQL_Context *context) 38run_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;