fixing query insert
authorChristophe Genevey Metat <genevey.christophe@gmail.com>
Tue, 31 May 2016 13:44:31 +0000 (13:44 +0000)
committerChristophe Genevey Metat <genevey.christophe@gmail.com>
Tue, 31 May 2016 13:44:31 +0000 (13:44 +0000)
src/include/gnunet_my_lib.h
src/my/my_query_helper.c
src/my/test_my.c

index 0f10104b809af680ff19c6e70271cb3fa09441c2..ffba2a66cb5a6236b98c5306f6158f8705e085bc 100644 (file)
@@ -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.
   *
index ee266ddc1a5ec3604cc2dcb1c5fb12fb09301f3f..a8a9ce7b6659d18a4880403dd3157eca9d4cb3e8 100644 (file)
@@ -26,7 +26,6 @@
 #include <mysql/mysql.h>
 #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;
index 3cd6881c1fa2014c84e917b142115256567a846a..067d70a6e7fdf5396518f5053775580d05ac6ebc 100644 (file)
@@ -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;
 }