#include <mysql/mysql.h>
#include "gnunet_my_lib.h"
-
+#define STRING_SIZE 50
/**
* Run a prepared SELECT statement.
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__,
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;
}
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;
-/* statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
+ statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
"SELECT"
" pub"
",sig"
fprintf(stderr, "Failed to extract result\n");
return 1;
}
-*/
+
return 0;
}
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;
}