aboutsummaryrefslogtreecommitdiff
path: root/src/my
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-03 09:06:30 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-03 09:06:30 +0000
commitb114c5d82d3984e6baa216ed47dee20fae9bf4d6 (patch)
treedfc55ae83eb1302e13e72d69efb68ce096de2546 /src/my
parentb5fc1aa04d11e28eaf9f5c78abba0effd083f985 (diff)
downloadgnunet-b114c5d82d3984e6baa216ed47dee20fae9bf4d6.tar.gz
gnunet-b114c5d82d3984e6baa216ed47dee20fae9bf4d6.zip
start to written extract_result
Diffstat (limited to 'src/my')
-rw-r--r--src/my/my.c120
-rw-r--r--src/my/test_my.c36
2 files changed, 121 insertions, 35 deletions
diff --git a/src/my/my.c b/src/my/my.c
index 6c4ab6942..54b2a49b0 100644
--- a/src/my/my.c
+++ b/src/my/my.c
@@ -27,7 +27,7 @@
27#include <mysql/mysql.h> 27#include <mysql/mysql.h>
28#include "gnunet_my_lib.h" 28#include "gnunet_my_lib.h"
29 29
30 30#define STRING_SIZE 50
31 31
32/** 32/**
33 * Run a prepared SELECT statement. 33 * Run a prepared SELECT statement.
@@ -118,19 +118,86 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
118 int row) 118 int row)
119{ 119{
120 MYSQL_BIND *result; 120 MYSQL_BIND *result;
121
122 int num_fields;
123 MYSQL_FIELD *fields;
124 MYSQL_RES *res;
125
121 unsigned int i; 126 unsigned int i;
127 unsigned int j;
122 int had_null = GNUNET_NO; 128 int had_null = GNUNET_NO;
123 int ret; 129 int ret;
124 130
131 result = NULL;
125 MYSQL_STMT *stmt; 132 MYSQL_STMT *stmt;
126 133
127 stmt = GNUNET_MYSQL_statement_get_stmt (NULL /* FIXME */, sh); 134 stmt = GNUNET_MYSQL_statement_get_stmt (NULL /* FIXME */, sh);
128 // result = mysql_get_result (stmt); 135 if (NULL == stmt)
129 result = NULL; 136 {
137 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
138 ("`%s' failed at %s:%d with error: %s\n"),
139 "mysql_stmt_bind_result", __FILE__, __LINE__,
140 mysql_stmt_error (stmt));
141 return GNUNET_SYSERR;
142 }
130 143
131 if (mysql_stmt_bind_result(stmt, result)) 144
145 num_fields = mysql_stmt_field_count (stmt);
146 res = mysql_stmt_result_metadata (stmt);
147 fields = mysql_fetch_fields (res);
148
149 int int_data[num_fields];
150 long int long_data[num_fields];
151 short short_data[num_fields];
152 char str_data[STRING_SIZE];
153 int error[num_fields];
154
155 result = (MYSQL_BIND *)malloc (sizeof (MYSQL_BIND)*num_fields);
156 if(!result)
132 { 157 {
158 fprintf(stderr, "Error to allocate output buffers\n");
159 return GNUNET_SYSERR;
160 }
161
162 memset(result, 0, sizeof (MYSQL_BIND) * num_fields);
133 163
164/** INITIALISER LE MYSQL_BIND ****/
165
166 for(i = 0 ; i< num_fields ;i++)
167 {
168 result[i].buffer_type = fields[i].type;
169 result[i].is_null = 0;
170 result[i].error = &error[i];
171
172 switch (fields[i].type)
173 {
174 case MYSQL_TYPE_LONG:
175 result[i].buffer = &(int_data[i]);
176 result[i].buffer_length = sizeof (int_data);
177 break;
178
179 case MYSQL_TYPE_LONGLONG:
180 result[i].buffer = &(long_data[i]);
181 result[i].buffer_length = sizeof (long_data);
182 break;
183
184 case MYSQL_TYPE_STRING:
185 result[i].buffer = (char *)str_data;
186 result[i].buffer_length = sizeof (str_data);
187 break;
188
189 case MYSQL_TYPE_SHORT:
190 result[i].buffer = &(short_data[i]);
191 result[i].buffer_length = sizeof (short_data);
192 break;
193
194 default:
195 fprintf(stderr, "Failed : wrong type : %d!\n", fields[i].type);
196 }
197 }
198
199 if (mysql_stmt_bind_result(stmt, result))
200 {
134 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", 201 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
135 _("`%s' failed at %s:%d with error: %s\n"), 202 _("`%s' failed at %s:%d with error: %s\n"),
136 "mysql_stmt_bind_result", __FILE__, __LINE__, 203 "mysql_stmt_bind_result", __FILE__, __LINE__,
@@ -138,27 +205,50 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
138 return GNUNET_SYSERR; 205 return GNUNET_SYSERR;
139 } 206 }
140 207
141 for (i = 0 ; NULL != rs[i].conv ; i++) 208 /*** FAILED HERE ***/
209 if (mysql_stmt_fetch (stmt))
142 { 210 {
143 struct GNUNET_MY_ResultSpec *spec; 211 for(j = 0 ; j < num_fields ;j++)
212 {
213 fprintf(stderr, "Error Bind [%d] : %d\n", j, error[j]);
214 }
215
216 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
217 _("`%s' failed at %s:%d with error: %s\n"),
218 "mysql_stmt_fetch", __FILE__, __LINE__,
219 mysql_stmt_error (stmt));
220 return GNUNET_SYSERR;
221 }
144 222
145 spec = &rs[i]; 223/*
146 ret = spec->conv (spec->conv_cls, 224 while (1)
147 spec, 225 {
148 result); 226 mysql_stmt_fetch (stmt);
149 227
150 if (GNUNET_SYSERR == ret) 228 for (i = 0 ; NULL != rs[i].conv ; i++)
151 { 229 {
152 return GNUNET_SYSERR; 230 struct GNUNET_MY_ResultSpec *spec;
153 } 231
232 spec = &rs[i];
233 ret = spec->conv (spec->conv_cls,
234 spec,
235 result);
154 236
155 if (NULL != spec->result_size) 237 if (GNUNET_SYSERR == ret)
156 *spec->result_size = spec->dst_size; 238 {
239 return GNUNET_SYSERR;
240 }
241
242 if (NULL != spec->result_size)
243 *spec->result_size = spec->dst_size;
244 }
157 } 245 }
158 246
159 if (GNUNET_YES == had_null) 247 if (GNUNET_YES == had_null)
160 return GNUNET_NO; 248 return GNUNET_NO;
249*/
161 250
251 free (result);
162 return GNUNET_OK; 252 return GNUNET_OK;
163} 253}
164 254
diff --git a/src/my/test_my.c b/src/my/test_my.c
index d213bf547..c63a069bf 100644
--- a/src/my/test_my.c
+++ b/src/my/test_my.c
@@ -38,34 +38,30 @@ static int
38run_queries (struct GNUNET_MYSQL_Context *context) 38run_queries (struct GNUNET_MYSQL_Context *context)
39{ 39{
40 struct GNUNET_CRYPTO_RsaPublicKey *pub; 40 struct GNUNET_CRYPTO_RsaPublicKey *pub;
41// struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; 41 struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL;
42 struct GNUNET_CRYPTO_RsaSignature *sig; 42 struct GNUNET_CRYPTO_RsaSignature *sig;
43// struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; 43 struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL;
44 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; 45 struct GNUNET_TIME_Absolute abs_time2;
46 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; 47 struct GNUNET_TIME_Absolute forever2;
48 struct GNUNET_HashCode hc; 48 struct GNUNET_HashCode hc;
49// struct GNUNET_HashCode hc2; 49 struct GNUNET_HashCode hc2;
50 const char msg[] = "hello"; 50 const char msg[] = "hello";
51// void *msg2; 51 void *msg2;
52 size_t msg_len; 52 size_t msg2_len;
53// size_t msg2_len;
54 53
55 uint16_t u16; 54 uint16_t u16;
56// uint16_t u162; 55 uint16_t u162;
57 uint32_t u32; 56 uint32_t u32;
58// uint32_t u322; 57 uint32_t u322;
59 uint64_t u64; 58 uint64_t u64;
60// uint64_t u642; 59 uint64_t u642;
61 60
62 msg_len = sizeof(msg); 61 int ret;
63
64// int ret;
65 62
66 struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; 63 struct GNUNET_MYSQL_StatementHandle *statements_handle_insert;
67 64 struct GNUNET_MYSQL_StatementHandle *statements_handle_select;
68// struct GNUNET_MYSQL_StatementHandle *statements_handle_select;
69 65
70 struct GNUNET_CRYPTO_RsaPrivateKey *priv; 66 struct GNUNET_CRYPTO_RsaPrivateKey *priv;
71 struct GNUNET_HashCode hmsg; 67 struct GNUNET_HashCode hmsg;
@@ -122,7 +118,7 @@ run_queries (struct GNUNET_MYSQL_Context *context)
122 118
123 119
124 120
125/* statements_handle_select = GNUNET_MYSQL_statement_prepare (context, 121 statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
126 "SELECT" 122 "SELECT"
127 " pub" 123 " pub"
128 ",sig" 124 ",sig"
@@ -178,7 +174,7 @@ run_queries (struct GNUNET_MYSQL_Context *context)
178 fprintf(stderr, "Failed to extract result\n"); 174 fprintf(stderr, "Failed to extract result\n");
179 return 1; 175 return 1;
180 } 176 }
181*/ 177
182 return 0; 178 return 0;
183} 179}
184 180
@@ -245,8 +241,8 @@ main (int argc, const char * const argv[])
245 fprintf (stderr, "Failed to drop table test_my\n"); 241 fprintf (stderr, "Failed to drop table test_my\n");
246 GNUNET_MYSQL_statements_invalidate (context); 242 GNUNET_MYSQL_statements_invalidate (context);
247 } 243 }
248*/
249 GNUNET_MYSQL_context_destroy (context);
250 244
245 GNUNET_MYSQL_context_destroy (context);
246*/
251 return ret; 247 return ret;
252} 248}