From 5f164d71d10dcaad7200dfabcbfd7fdc4f030622 Mon Sep 17 00:00:00 2001 From: Christophe Genevey Metat Date: Tue, 31 May 2016 13:44:31 +0000 Subject: fixing query insert --- src/include/gnunet_my_lib.h | 2 +- src/my/my_query_helper.c | 12 +++++++++--- src/my/test_my.c | 21 +++++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index 0f10104b8..ffba2a66c 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h @@ -251,7 +251,7 @@ GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x struct GNUNET_MY_QueryParam GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x); -/** +/**q * Generate query parameter for an absolute time value. * The database must store a 64-bit integer. * diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index ee266ddc1..a8a9ce7b6 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c @@ -26,7 +26,6 @@ #include #include "gnunet_my_lib.h" - /** * Function called to convert input argument into SQL parameters. * @@ -41,11 +40,13 @@ my_conv_fixed_size (void *cls, MYSQL_BIND *qbind) { GNUNET_assert (1 == qp->num_params); + qbind->buffer = (void *) qp->data; qbind->buffer_length = qp->data_len; - qbind->length = (unsigned long *) &qp->data_len; qbind->buffer_type = 1; - return 0; + + //return 0; + return 1; } @@ -99,10 +100,15 @@ my_conv_uint16 (void *cls, const uint16_t *u_hbo = qp->data; uint16_t *u_nbo; + fprintf(stderr, "input data : %u\n", (unsigned)u_hbo); + GNUNET_assert (1 == qp->num_params); + u_nbo = GNUNET_new (uint16_t); *u_nbo = htons (*u_hbo); + + fprintf(stderr, "output data : %u\n", (unsigned)u_nbo); qbind->buffer = (void *) u_nbo; qbind->buffer_length = sizeof(uint16_t); qbind->buffer_type = 1; diff --git a/src/my/test_my.c b/src/my/test_my.c index 3cd6881c1..067d70a6e 100644 --- a/src/my/test_my.c +++ b/src/my/test_my.c @@ -47,8 +47,8 @@ run_queries (struct GNUNET_MYSQL_Context *context) uint32_t u32; uint64_t u64; -// struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; - struct GNUNET_MYSQL_StatementHandle *statements_handle_select; + struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; +// struct GNUNET_MYSQL_StatementHandle *statements_handle_select; struct GNUNET_CRYPTO_RsaPrivateKey *priv; struct GNUNET_HashCode hmsg; @@ -62,7 +62,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) u32 = 32; u64 = 64; -/* FIXE THE INSERT QUERY +// FIXE THE INSERT QUERY statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, "INSERT INTO test_my (" " pub" @@ -75,15 +75,16 @@ run_queries (struct GNUNET_MYSQL_Context *context) ",u32" ",u64" ") VALUES " - "(@1, @2, @3, @4, @5, @6," - "@7, @8, @9);"); + "(?, ?, ?, ?, ?, ?," + "?, ?, ?)"); if (NULL == statements_handle_insert) { - fprintf(stderr, "Failed to prepared statement INSERT\n"); + fprintf (stderr, "Failed to prepared statement INSERT\n"); return 1; } + //ERROR WITH MSG struct GNUNET_MY_QueryParam params_insert[] = { GNUNET_MY_query_param_rsa_public_key (pub), GNUNET_MY_query_param_rsa_signature (sig), @@ -97,6 +98,9 @@ run_queries (struct GNUNET_MYSQL_Context *context) GNUNET_MY_query_param_end }; + fprintf(stderr, " u16 : %u\n", (unsigned)params_insert[6].data); + fprintf(stderr, " &u16 : %u\n", (unsigned)&u16); + //FAIL HERE if (GNUNET_OK != GNUNET_MY_exec_prepared (context, statements_handle_insert, @@ -106,7 +110,8 @@ run_queries (struct GNUNET_MYSQL_Context *context) "Failed to execute prepared statement\n"); return 22; } -*/ + +/* NOT THE GOOD FUNCTION -> TO FIXE statements_handle_select = GNUNET_MYSQL_statement_prepare (context, "SELECT" " pub" @@ -139,7 +144,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) fprintf (stderr, "Failed to execute prepared statement\n"); return 22; } - +*/ return 0; } -- cgit v1.2.3