diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-03 09:06:30 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-03 09:06:30 +0000 |
commit | b114c5d82d3984e6baa216ed47dee20fae9bf4d6 (patch) | |
tree | dfc55ae83eb1302e13e72d69efb68ce096de2546 /src/my/my.c | |
parent | b5fc1aa04d11e28eaf9f5c78abba0effd083f985 (diff) | |
download | gnunet-b114c5d82d3984e6baa216ed47dee20fae9bf4d6.tar.gz gnunet-b114c5d82d3984e6baa216ed47dee20fae9bf4d6.zip |
start to written extract_result
Diffstat (limited to 'src/my/my.c')
-rw-r--r-- | src/my/my.c | 120 |
1 files changed, 105 insertions, 15 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 | ||