From: Christophe Genevey Metat Date: Fri, 3 Jun 2016 09:06:30 +0000 (+0000) Subject: start to written extract_result X-Git-Tag: initial-import-from-subversion-38251~821 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b114c5d82d3984e6baa216ed47dee20fae9bf4d6;p=oweals%2Fgnunet.git start to written extract_result --- 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 @@ #include #include "gnunet_my_lib.h" - +#define STRING_SIZE 50 /** * Run a prepared SELECT statement. @@ -118,19 +118,86 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, int row) { MYSQL_BIND *result; + + int num_fields; + MYSQL_FIELD *fields; + MYSQL_RES *res; + unsigned int i; + unsigned int j; int had_null = GNUNET_NO; int ret; + result = NULL; MYSQL_STMT *stmt; stmt = GNUNET_MYSQL_statement_get_stmt (NULL /* FIXME */, sh); - // result = mysql_get_result (stmt); - result = NULL; + if (NULL == stmt) + { + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", + ("`%s' failed at %s:%d with error: %s\n"), + "mysql_stmt_bind_result", __FILE__, __LINE__, + mysql_stmt_error (stmt)); + return GNUNET_SYSERR; + } - if (mysql_stmt_bind_result(stmt, result)) + + num_fields = mysql_stmt_field_count (stmt); + res = mysql_stmt_result_metadata (stmt); + fields = mysql_fetch_fields (res); + + int int_data[num_fields]; + long int long_data[num_fields]; + short short_data[num_fields]; + char str_data[STRING_SIZE]; + int error[num_fields]; + + result = (MYSQL_BIND *)malloc (sizeof (MYSQL_BIND)*num_fields); + if(!result) { + fprintf(stderr, "Error to allocate output buffers\n"); + return GNUNET_SYSERR; + } + + memset(result, 0, sizeof (MYSQL_BIND) * num_fields); +/** INITIALISER LE MYSQL_BIND ****/ + + for(i = 0 ; i< num_fields ;i++) + { + result[i].buffer_type = fields[i].type; + result[i].is_null = 0; + result[i].error = &error[i]; + + switch (fields[i].type) + { + case MYSQL_TYPE_LONG: + result[i].buffer = &(int_data[i]); + result[i].buffer_length = sizeof (int_data); + break; + + case MYSQL_TYPE_LONGLONG: + result[i].buffer = &(long_data[i]); + result[i].buffer_length = sizeof (long_data); + break; + + case MYSQL_TYPE_STRING: + result[i].buffer = (char *)str_data; + result[i].buffer_length = sizeof (str_data); + break; + + case MYSQL_TYPE_SHORT: + result[i].buffer = &(short_data[i]); + result[i].buffer_length = sizeof (short_data); + break; + + default: + fprintf(stderr, "Failed : wrong type : %d!\n", fields[i].type); + } + } + + if (mysql_stmt_bind_result(stmt, result)) + { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_bind_result", __FILE__, __LINE__, @@ -138,27 +205,50 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, return GNUNET_SYSERR; } - for (i = 0 ; NULL != rs[i].conv ; i++) + /*** FAILED HERE ***/ + if (mysql_stmt_fetch (stmt)) { - struct GNUNET_MY_ResultSpec *spec; + for(j = 0 ; j < num_fields ;j++) + { + fprintf(stderr, "Error Bind [%d] : %d\n", j, error[j]); + } + + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", + _("`%s' failed at %s:%d with error: %s\n"), + "mysql_stmt_fetch", __FILE__, __LINE__, + mysql_stmt_error (stmt)); + return GNUNET_SYSERR; + } - spec = &rs[i]; - ret = spec->conv (spec->conv_cls, - spec, - result); +/* + while (1) + { + mysql_stmt_fetch (stmt); - if (GNUNET_SYSERR == ret) + for (i = 0 ; NULL != rs[i].conv ; i++) { - return GNUNET_SYSERR; - } + struct GNUNET_MY_ResultSpec *spec; + + spec = &rs[i]; + ret = spec->conv (spec->conv_cls, + spec, + result); - if (NULL != spec->result_size) - *spec->result_size = spec->dst_size; + if (GNUNET_SYSERR == ret) + { + return GNUNET_SYSERR; + } + + if (NULL != spec->result_size) + *spec->result_size = spec->dst_size; + } } if (GNUNET_YES == had_null) return GNUNET_NO; +*/ + free (result); return GNUNET_OK; } 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 run_queries (struct GNUNET_MYSQL_Context *context) { struct GNUNET_CRYPTO_RsaPublicKey *pub; -// struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; + struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; struct GNUNET_CRYPTO_RsaSignature *sig; -// struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; + struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); -// struct GNUNET_TIME_Absolute abs_time2; + struct GNUNET_TIME_Absolute abs_time2; struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; -// struct GNUNET_TIME_Absolute forever2; + struct GNUNET_TIME_Absolute forever2; struct GNUNET_HashCode hc; -// struct GNUNET_HashCode hc2; + struct GNUNET_HashCode hc2; const char msg[] = "hello"; -// void *msg2; - size_t msg_len; -// size_t msg2_len; + void *msg2; + size_t msg2_len; uint16_t u16; -// uint16_t u162; + uint16_t u162; uint32_t u32; -// uint32_t u322; + uint32_t u322; uint64_t u64; -// uint64_t u642; + uint64_t u642; - msg_len = sizeof(msg); - -// int ret; + int ret; struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; - -// struct GNUNET_MYSQL_StatementHandle *statements_handle_select; + struct GNUNET_MYSQL_StatementHandle *statements_handle_select; struct GNUNET_CRYPTO_RsaPrivateKey *priv; struct GNUNET_HashCode hmsg; @@ -122,7 +118,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) -/* statements_handle_select = GNUNET_MYSQL_statement_prepare (context, + statements_handle_select = GNUNET_MYSQL_statement_prepare (context, "SELECT" " pub" ",sig" @@ -178,7 +174,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) fprintf(stderr, "Failed to extract result\n"); return 1; } -*/ + return 0; } @@ -245,8 +241,8 @@ main (int argc, const char * const argv[]) fprintf (stderr, "Failed to drop table test_my\n"); GNUNET_MYSQL_statements_invalidate (context); } -*/ - GNUNET_MYSQL_context_destroy (context); + GNUNET_MYSQL_context_destroy (context); +*/ return ret; }