gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r37241 - in gnunet/src: include my


From: gnunet
Subject: [GNUnet-SVN] r37241 - in gnunet/src: include my
Date: Fri, 3 Jun 2016 18:08:23 +0200

Author: christophe.genevey
Date: 2016-06-03 18:08:23 +0200 (Fri, 03 Jun 2016)
New Revision: 37241

Modified:
   gnunet/src/include/gnunet_my_lib.h
   gnunet/src/my/my.c
   gnunet/src/my/my_query_helper.c
   gnunet/src/my/my_result_helper.c
   gnunet/src/my/test_my.c
Log:
start to fix extract result

Modified: gnunet/src/include/gnunet_my_lib.h
===================================================================
--- gnunet/src/include/gnunet_my_lib.h  2016-06-03 10:32:17 UTC (rev 37240)
+++ gnunet/src/include/gnunet_my_lib.h  2016-06-03 16:08:23 UTC (rev 37241)
@@ -455,7 +455,7 @@
  * @param rs reult specification to clean up
  */
 void
-GNUNET_MY_cleanup_result (struct GNUNET_PQ_ResultSpec *rs);
+GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */

Modified: gnunet/src/my/my.c
===================================================================
--- gnunet/src/my/my.c  2016-06-03 10:32:17 UTC (rev 37240)
+++ gnunet/src/my/my.c  2016-06-03 16:08:23 UTC (rev 37241)
@@ -129,7 +129,7 @@
   }
 
   num_fields = 0;
-  for (i=0;NULL != rs[i].conv;i++)
+  for (i=0;NULL != rs[i].pre_conv;i++)
     num_fields += rs[i].num_fields;
 
   if (mysql_stmt_field_count (stmt) != num_fields)
@@ -145,12 +145,12 @@
 
     memset (result, 0, sizeof (MYSQL_BIND) * num_fields);
     field_off = 0;
-    for (i=0;NULL != rs[i].conv;i++)
+    for (i=0;NULL != rs[i].pre_conv;i++)
     {
       struct GNUNET_MY_ResultSpec *rp = &rs[i];
 
       if (GNUNET_OK !=
-          rp->pre_conv (rp->cls,
+          rp->pre_conv (rp->conv_cls,
                         rp,
                         stmt,
                         field_off,
@@ -186,13 +186,13 @@
       return GNUNET_SYSERR;
     }
     field_off = 0;
-    for (i=0;NULL != rs[i].conv;i++)
+    for (i=0;NULL != rs[i].post_conv;i++)
     {
       struct GNUNET_MY_ResultSpec *rp = &rs[i];
 
       if (NULL != rp->post_conv)
         if (GNUNET_OK !=
-            rp->post_conv (rp->cls,
+            rp->post_conv (rp->conv_cls,
                            rp,
                            stmt,
                            field_off,
@@ -218,12 +218,12 @@
  * @param rs reult specification to clean up
  */
 void
-GNUNET_MY_cleanup_result (struct GNUNET_PQ_ResultSpec *rs)
+GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs)
 {
   unsigned int i;
 
-  for (i=0;NULL != rs[i].conv;i++)
-    rs[i].cleaner (rs[i].cls,
+  for (i=0;NULL != rs[i].cleaner;i++)
+    rs[i].cleaner (rs[i].conv_cls,
                    &rs[i]);
 }
 

Modified: gnunet/src/my/my_query_helper.c
===================================================================
--- gnunet/src/my/my_query_helper.c     2016-06-03 10:32:17 UTC (rev 37240)
+++ gnunet/src/my/my_query_helper.c     2016-06-03 16:08:23 UTC (rev 37241)
@@ -106,8 +106,9 @@
   if (NULL == u_nbo)
     return -1;
 
-  *u_nbo = htons (*u_hbo);
-  
+//  *u_nbo = htons (*u_hbo);
+    *u_nbo = *u_hbo;
+
   qbind->buffer = (void *) u_nbo;
   qbind->buffer_length = sizeof(uint16_t);
   qbind->buffer_type = MYSQL_TYPE_SHORT;
@@ -153,7 +154,8 @@
   GNUNET_assert (1 == qp->num_params);
 
   u_nbo = GNUNET_new (uint32_t);
-  *u_nbo = htonl (*u_hbo);
+//  *u_nbo = htonl (*u_hbo);
+    *u_nbo = *u_hbo;
 
   qbind->buffer = (void *) u_nbo;
   qbind->buffer_length = sizeof(uint32_t);
@@ -200,7 +202,8 @@
   GNUNET_assert (1 == qp->num_params);
 
   u_nbo = GNUNET_new(uint64_t);
-  *u_nbo = GNUNET_htonll (*u_hbo);
+  //*u_nbo = GNUNET_htonll (*u_hbo);
+    *u_nbo = *u_hbo;
 
   qbind->buffer = (void *) u_nbo;
   qbind->buffer_length = sizeof (uint64_t);

Modified: gnunet/src/my/my_result_helper.c
===================================================================
--- gnunet/src/my/my_result_helper.c    2016-06-03 10:32:17 UTC (rev 37240)
+++ gnunet/src/my/my_result_helper.c    2016-06-03 16:08:23 UTC (rev 37241)
@@ -33,11 +33,14 @@
 static int
 pre_extract_varsize_blob (void *cls,
                           struct GNUNET_MY_ResultSpec *rs,
+                          MYSQL_STMT *stmt,
+                          unsigned int column,
                           MYSQL_BIND *results)
 {
-  results[0].buffer = NULL;
+  results[0].buffer = 0;
   results[0].buffer_length = 0;
   results[0].length = &rs->mysql_bind_output_length;
+
   return GNUNET_OK;
 }
 
@@ -147,11 +150,15 @@
 static int
 pre_extract_fixed_blob (void *cls,
                         struct GNUNET_MY_ResultSpec *rs,
+                        MYSQL_STMT *stmt,
+                        unsigned int column,
                         MYSQL_BIND *results)
 {
   results[0].buffer = rs->dst;
   results[0].buffer_length = rs->dst_size;
   results[0].length = &rs->mysql_bind_output_length;
+  results[0].buffer_type = MYSQL_TYPE_BLOB;
+
   return GNUNET_OK;
 }
 
@@ -173,6 +180,8 @@
 static int
 post_extract_fixed_blob (void *cls,
                          struct GNUNET_MY_ResultSpec *rs,
+                         MYSQL_STMT *stmt,
+                         unsigned int column,
                          MYSQL_BIND *results)
 {
   if (rs->dst_size != rs->mysql_bind_output_length)
@@ -219,27 +228,63 @@
   *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
   */
 static int
-extract_rsa_public_key (void *cls,
-                       struct GNUNET_MY_ResultSpec *rs,
+pre_extract_rsa_public_key  (void *cls,
+                        struct GNUNET_MY_ResultSpec *rs,
+                        MYSQL_STMT *stmt,
+                        unsigned int column,
                         MYSQL_BIND *results)
 
 {
+  results[0].buffer = 0;
+  results[0].buffer_length = 0;
+  results[0].length = rs->mysql_bind_output_length;
+  results[0].buffer_type = MYSQL_TYPE_LONG;
+
+  return GNUNET_OK;
+}
+
+
+/**
+  * Check size of extracted fixed size data from a Mysql database @a
+  * result at row @a row
+  *
+  * @param cls closure
+  * @param result where to extract data from
+  * @param int row to extract data from
+  * @param fname name (or prefix) of the fields to extract from
+  * @param[in, out] dst_size where to store size of result, may be NULL
+  * @param[out] dst where to store the result
+  * @return
+  *   #GNUNET_OK if all results could be extracted
+  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+  */
+static int
+post_extract_rsa_public_key  (void *cls,
+                        struct GNUNET_MY_ResultSpec *rs,
+                        MYSQL_STMT *stmt,
+                        unsigned int column,
+                        MYSQL_BIND *results)
+
+{
   struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
 
-  size_t len;
-  const char *res;
+  size_t size;
+  char *res;
 
-  if (results->is_null)
+  results[0].buffer = res;
+  results[0].buffer_length = size;
+
+  if (0 != 
+        mysql_stmt_fetch_column (stmt,
+                                results,
+                                column,
+                                0))
   {
-    return GNUNET_SYSERR;
+    return GNUNET_SYSERR; 
   }
 
-  len = results->buffer_length;
-  res = results->buffer;
-
   *pk = GNUNET_CRYPTO_rsa_public_key_decode (res,
-                                            len);
-
+                                            size);
   if (NULL == *pk)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -247,10 +292,36 @@
     return GNUNET_SYSERR;
   }
 
+  if (rs->dst_size != rs->mysql_bind_output_length)
+    return GNUNET_SYSERR;
+
   return GNUNET_OK;
 }
 
+
 /**
+ * Function called to clean up memory allocated
+ * by a #GNUNET_MY_ResultConverter.
+ *
+ * @param cls closure
+ * @param rd result data to clean up
+ */
+static void
+clean_rsa_public_key (void *cls,
+                      struct GNUNET_MY_ResultSpec *rs)
+{
+  struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
+
+  if (NULL != *pk)
+  {
+    GNUNET_CRYPTO_rsa_public_key_free (*pk);
+    *pk = NULL;
+    *rs->result_size = 0;
+  }
+}
+
+
+/**
   * RSA public key expected
   *
   * @param name name of the field in the table
@@ -261,12 +332,12 @@
 GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
 {
   struct GNUNET_MY_ResultSpec res = {
-    &extract_rsa_public_key,
-    NULL,
-    (void *) rsa,
-    0,
-    NULL,
-    1
+    .pre_conv = &pre_extract_rsa_public_key,
+    .post_conv = &post_extract_rsa_public_key,
+    .cleaner = &clean_rsa_public_key,
+    .dst = (void *) rsa,
+    .dst_size = 0,
+    .num_fields = 1
   };
 
   return res;
@@ -286,24 +357,57 @@
   *    #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
   */
 static int
-extract_rsa_signature (void *cls,
+pre_extract_rsa_signature (void *cls,
                       struct GNUNET_MY_ResultSpec *rs,
+                      MYSQL_STMT *stmt,
+                      unsigned int column,
                       MYSQL_BIND *results)
 {
+  results[0].buffer = 0;
+  results[0].buffer_length = 0;
+  results[0].length = &rs->mysql_bind_output_length;
+  results[0].buffer_type = MYSQL_TYPE_LONG;
+
+  return GNUNET_OK;
+}
+/**
+  * Extract data from a Mysql database @a result at row @a row.
+  *
+  * @param cls closure
+  * @param result where to extract data from
+  * @param int row to extract data from
+  * @param fname name (or prefix) of the fields to extract from
+  * @param[in,out] dst_size where to store size of result, may be NULL
+  * @param[out] dst where to store the result
+  * @return
+  *    #GNUNET_OK if all results could be extracted
+  *    #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+  */
+static int
+post_extract_rsa_signature (void *cls,
+                      struct GNUNET_MY_ResultSpec *rs,
+                      MYSQL_STMT *stmt,
+                      unsigned int column,
+                      MYSQL_BIND *results)
+{
   struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
-  size_t len;
+  size_t size;
   const char *res;
 
-  if (results->is_null)
+  results[0].buffer = res;
+  results[0].buffer_length = size;
+
+  if (0 != 
+      mysql_stmt_fetch_column (stmt,
+                              results,
+                              column,
+                              0))
   {
     return GNUNET_SYSERR;
   }
 
-  len = results->buffer_length;
-  res = results->buffer;
-
   *sig = GNUNET_CRYPTO_rsa_signature_decode (res,
-                                            len);
+                                            size);
 
   if (NULL != *sig)
   {
@@ -315,7 +419,30 @@
   return GNUNET_OK;
 }
 
+
 /**
+ * Function called to clean up memory allocated
+ * by a #GNUNET_MY_ResultConverter.
+ *
+ * @param cls closure
+ * @param rd result data to clean up
+ */
+static void
+clean_rsa_signature (void *cls,
+          struct GNUNET_MY_ResultSpec *rs)
+{
+  struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
+
+  if (NULL != *sig)
+  {
+    GNUNET_CRYPTO_rsa_signature_free (*sig);
+    *sig = NULL;
+    rs->result_size = 0;
+  }
+}
+
+
+/**
   * RSA signature expected.
   *
   * @param[out] sig where to store the result;
@@ -326,12 +453,12 @@
 {
   struct GNUNET_MY_ResultSpec res =
   {
-    &extract_rsa_signature,
-    NULL,
-    (void *)sig,
-    0,
-    NULL,
-    1
+    .pre_conv = &pre_extract_rsa_signature,
+    .post_conv = &post_extract_rsa_signature,
+    .cleaner = &clean_rsa_signature,
+    .dst = (void *)sig,
+    .dst_size = 0,
+    .num_fields = 1
   };
   return res;
 }
@@ -350,10 +477,16 @@
   *    #GNUNET_SYSERR if a result was invalid (non existing field or NULL)
   */
 static int
-extract_string (void * cls,
+pre_extract_string (void * cls,
                 struct GNUNET_MY_ResultSpec *rs,
+                MYSQL_STMT *stmt,
+                unsigned int column,
                 MYSQL_BIND *results)
 {
+  results[0].buffer = (char *)rs->dst;
+  results[0].buffer_length = rs->dst_size;
+  results[0].length = &rs->mysql_bind_output_length;
+/*
   char **str = rs->dst;
   size_t len;
   const char *res;
@@ -377,7 +510,59 @@
                 "Results contains bogus value (fail to decode)\n");
     return GNUNET_SYSERR;
   }
+*/  return GNUNET_OK;
+}
+
+
+/**
+  * Check size of extracted fixed size data from a Mysql database @a 
+  *
+  * @param cls closure
+  * @param result where to extract data from
+  * @param int row to extract data from
+  * @param fname name (or prefix) of the fields to extract from
+  * @param[in, out] dst_size where to store size of result, may be NULL
+  * @param[out] dst where to store the result
+  * @return
+  *    #GNUNET_OK if all results could be extracted
+  *    #GNUNET_SYSERR if a result was invalid (non existing field or NULL)
+  */
+static int
+post_extract_string (void * cls,
+                struct GNUNET_MY_ResultSpec *rs,
+                MYSQL_STMT *stmt,
+                unsigned int column,
+                MYSQL_BIND *results)
+{
+  if (rs->dst_size != rs->mysql_bind_output_length)
+    return GNUNET_SYSERR;
   return GNUNET_OK;
+/*  
+  char **str = rs->dst;
+  size_t len;
+  const char *res;
+
+  *str = NULL;
+
+  if (results->is_null)
+  {
+    return GNUNET_SYSERR;
+  }
+
+  len = results->buffer_length;
+  res = results->buffer;
+
+  *str = GNUNET_strndup (res,
+                        len);
+
+  if (NULL == *str)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Results contains bogus value (fail to decode)\n");
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+*/
 }
 
 
@@ -391,12 +576,11 @@
 GNUNET_MY_result_spec_string (char **dst)
 {
   struct GNUNET_MY_ResultSpec res = {
-    &extract_string,
-    NULL,
-    (void *) dst,
-    0,
-    NULL,
-    1
+    .pre_conv = &pre_extract_string,
+    .post_conv = &post_extract_string,
+    .dst = (void *) dst,
+    .dst_size = 0,
+    .num_fields = 1
   };
   return res;
 }
@@ -445,28 +629,43 @@
  *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
 static int
-extract_uint16 (void *cls,
+pre_extract_uint16 (void *cls,
                 struct GNUNET_MY_ResultSpec *rs,
+                MYSQL_STMT *stmt,
+                unsigned int column,
                 MYSQL_BIND *results)
 {
-  uint16_t *udst = rs->dst;
-  const uint16_t *res;
+  results[0].buffer = (char *)rs->dst;
+  results[0].buffer_length = rs->dst_size;
+  results[0].length = &rs->mysql_bind_output_length;
+  results[0].buffer_type = MYSQL_TYPE_SHORT;
 
-  if(results->is_null)
-  {
-    return GNUNET_SYSERR;
-  }
+  return GNUNET_OK;
+}
 
-  GNUNET_assert (NULL != rs->dst);
-  if (sizeof (uint16_t) != rs->dst_size)
-  {
-    GNUNET_break (0);
+
+/**
+ * Check size of extracted fixed size data from a Mysql datbase.
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param int row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ *   #GNUNET_YES if all results could be extracted
+ *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static int
+post_extract_uint16 (void *cls,
+                struct GNUNET_MY_ResultSpec *rs,
+                MYSQL_STMT *stmt,
+                unsigned int column,
+                MYSQL_BIND *results)
+{
+  if (rs->dst_size != rs->mysql_bind_output_length)
     return GNUNET_SYSERR;
-  }
-
-  res = (uint16_t *)results->buffer;
-  *udst = ntohs (*res);
-
   return GNUNET_OK;
 }
 
@@ -481,12 +680,11 @@
 GNUNET_MY_result_spec_uint16 (uint16_t *u16)
 {
   struct GNUNET_MY_ResultSpec res = {
-    &extract_uint16,
-    NULL,
-    (void *) u16,
-    sizeof (*u16),
-    NULL,
-    1
+    .pre_conv = &pre_extract_uint16,
+    .post_conv = &post_extract_uint16,
+    .dst = (void *) u16,
+    .dst_size = sizeof (*u16),
+    .num_fields = 1
   };
   return res;
 }
@@ -505,32 +703,47 @@
   *      #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
   */
 static int
-extract_uint32 (void *cls,
+pre_extract_uint32 (void *cls,
                 struct GNUNET_MY_ResultSpec *rs,
+                MYSQL_STMT *stmt,
+                unsigned int column,
                 MYSQL_BIND *results)
 {
-  uint32_t *udst = rs->dst;
-  const uint32_t *res;
+  results[0].buffer = (int *)rs->dst;
+  results[0].buffer_length = rs->dst_size;
+  results[0].length = &rs->mysql_bind_output_length;
+  results[0].buffer_type = MYSQL_TYPE_LONG;
 
-  if(results->is_null)
-  {
-    return GNUNET_SYSERR;
-  }
+  return GNUNET_OK;
+}
 
-  GNUNET_assert (NULL != rs->dst);
-  if (sizeof (uint32_t) != rs->dst_size)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
 
-  res = (uint32_t *)results->buffer;
-
-  *udst = ntohl (*res);
-
+/**
+  * Extrac data from a  MYSQL database @a result at row @a row
+  *
+  * @param cls closure
+  * @param result where to extract data from
+  * @param int row to extract data from
+  * @param fname name (or prefix) of the fields to extract from
+  * @param[in, out] dst_size where to store size of result, may be NULL
+  * @param[out] dst where to store the result
+  * @return
+  *      #GNUNET_OK if all results could be extracted
+  *      #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+  */
+static int
+post_extract_uint32 (void *cls,
+                struct GNUNET_MY_ResultSpec *rs,
+                MYSQL_STMT * stmt,
+                unsigned int column,
+                MYSQL_BIND *results)
+{
+  if (rs->dst_size != rs->mysql_bind_output_length)
+      return GNUNET_SYSERR;
   return GNUNET_OK;
 }
 
+
 /**
   * uint32_t expected
   *
@@ -541,16 +754,16 @@
 GNUNET_MY_result_spec_uint32 (uint32_t *u32)
 {
   struct GNUNET_MY_ResultSpec res = {
-    &extract_uint32,
-    NULL,
-    (void *) u32,
-    sizeof (*u32),
-    NULL,
-    1
+    .pre_conv = &pre_extract_uint32,
+    .post_conv = &post_extract_uint32,
+    .dst = (void *) u32,
+    .dst_size = sizeof (*u32),
+    .num_fields = 1
   };
   return res;
 }
 
+
 /**
   * Extract data from a MYSQL database @a result at row @a row
   *
@@ -565,26 +778,44 @@
   *    #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
   */
 static int
-extract_uint64 (void *cls,
+pre_extract_uint64 (void *cls,
                 struct GNUNET_MY_ResultSpec *rs,
+                MYSQL_STMT *stmt,
+                unsigned int column,
                 MYSQL_BIND *results)
 {
-  uint64_t *udst = rs->dst;
-  const uint64_t *res;
+  results[0].buffer = rs->dst;
+  results[0].buffer_length = rs->dst_size;
+  results[0].length = &rs->mysql_bind_output_length;
+  results[0].buffer_type = MYSQL_TYPE_LONGLONG;
 
-  results[0].buffer = &rs->dst;
-  results[0].buffer_length = 42;
+  return GNUNET_OK;
+}
 
-  GNUNET_assert (NULL != rs->dst);
-  if (sizeof (uint64_t) != rs->dst_size)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
 
-  res = (uint64_t *)results->buffer;
-  *udst = GNUNET_ntohll (*res);
 
+/**
+  * Check size of extracted fixe size data from a Mysql database
+  *
+  * @param cls closure
+  * @param result where to extract data from
+  * @param int row to extract data from
+  * @param fname name (or prefix) of the fields to extract from
+  * @param[in, out] dst_size where to store size of result, may be null
+  * @param[out] dst where to store the result
+  * @return
+  *    #GNUNET_OK if all results could be extracted
+  *    #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+  */
+static int
+post_extract_uint64 (void *cls,
+                struct GNUNET_MY_ResultSpec *rs,
+                MYSQL_STMT *stmt,
+                unsigned int column,
+                MYSQL_BIND *results)
+{
+  if (rs->dst_size != rs->mysql_bind_output_length)
+    return GNUNET_SYSERR;
   return GNUNET_OK;
 }
 
@@ -599,7 +830,8 @@
 GNUNET_MY_result_spec_uint64 (uint64_t *u64)
 {
   struct GNUNET_MY_ResultSpec res = {
-    .pre_conv = &extract_uint64,
+    .pre_conv = &pre_extract_uint64,
+    .post_conv = &post_extract_uint64,
     .dst = (void *) u64,
     .dst_size = sizeof (*u64),
     .num_fields = 1

Modified: gnunet/src/my/test_my.c
===================================================================
--- gnunet/src/my/test_my.c     2016-06-03 10:32:17 UTC (rev 37240)
+++ gnunet/src/my/test_my.c     2016-06-03 16:08:23 UTC (rev 37241)
@@ -75,7 +75,7 @@
      u32 = 32;
      u64 = 64;
 
-     statements_handle_insert = GNUNET_MYSQL_statement_prepare (context,
+/*     statements_handle_insert = GNUNET_MYSQL_statement_prepare (context,
                                         "INSERT INTO test_my ("
                                         " pub"
                                         ",sig"
@@ -107,7 +107,26 @@
           GNUNET_MY_query_param_uint64 (&u64),
           GNUNET_MY_query_param_end
      };
+*/
+     statements_handle_insert = GNUNET_MYSQL_statement_prepare (context,
+                                        "INSERT INTO test_my2 ("
+                                        " abs_time"
+                                        ",forever"
+                                        ",u16"
+                                        ",u32"
+                                        ",u64"
+                                        ") VALUES "
+                                        "( ?, ?, ?, ?, ?)");
 
+      struct GNUNET_MY_QueryParam params_insert[] = {
+          GNUNET_MY_query_param_absolute_time (&abs_time),
+          GNUNET_MY_query_param_absolute_time (&forever),
+          GNUNET_MY_query_param_uint16 (&u16),
+          GNUNET_MY_query_param_uint32 (&u32),
+          GNUNET_MY_query_param_uint64 (&u64),
+          GNUNET_MY_query_param_end
+     };
+
      if (GNUNET_OK != GNUNET_MY_exec_prepared(context,
                                              statements_handle_insert,
                                              params_insert))
@@ -118,7 +137,7 @@
 
 
 
-   statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
+/*   statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
                                                                  "SELECT"
                                                                  " pub"
                                                                  ",sig"
@@ -133,6 +152,16 @@
                                                                  " ORDER BY 
abs_time DESC "
                                                                  " LIMIT 1;");
 
+*/ 
+     statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
+                                                                 "SELECT"
+                                                                 " abs_time"
+                                                                 ",forever"
+                                                                 ",u16"
+                                                                 ",u32"
+                                                                 ",u64"
+                                                                 " FROM 
test_my2");
+
      if (NULL == statements_handle_select)
      {
           fprintf(stderr, "Failed to prepared statement SELECT\n");
@@ -151,7 +180,7 @@
           return 1;
      }
 
-
+/*
      struct GNUNET_MY_ResultSpec results_select[] = {
           GNUNET_MY_result_spec_rsa_public_key (&pub2),
           GNUNET_MY_result_spec_rsa_signature (&sig2),
@@ -164,11 +193,26 @@
           GNUNET_MY_result_spec_uint64 (&u642),
           GNUNET_MY_result_spec_end
      };
+*/
+     struct GNUNET_MY_ResultSpec results_select[] = {
+          GNUNET_MY_result_spec_absolute_time (&abs_time2),
+          GNUNET_MY_result_spec_absolute_time (&forever2),
+          GNUNET_MY_result_spec_uint16 (&u162),
+          GNUNET_MY_result_spec_uint32 (&u322),
+          GNUNET_MY_result_spec_uint64 (&u642),
+          GNUNET_MY_result_spec_end
+     };
 
      ret = GNUNET_MY_extract_result (statements_handle_select,
-                                        NULL,
-                                        results_select,
-                                        0);
+                                     results_select);
+
+     GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us);
+     GNUNET_break (forever.abs_value_us == forever2.abs_value_us);
+
+     GNUNET_break (16 == u162);
+     GNUNET_break (32 == u322);
+     GNUNET_break (64 == u642);
+
      if (GNUNET_OK != ret)
      {
           fprintf(stderr, "Failed to extract result\n");
@@ -212,7 +256,7 @@
           return 77;
      }
 
-     if (GNUNET_OK != GNUNET_MYSQL_statement_run (context,
+/*     if (GNUNET_OK != GNUNET_MYSQL_statement_run (context,
                                                   "CREATE TABLE test_my("
                                                   "pub INT NOT NULL"
                                                   ", sig INT NOT NULL"
@@ -232,11 +276,28 @@
           
           return 1;
      }
+*/
+     if (GNUNET_OK != GNUNET_MYSQL_statement_run (context,
+                                                  "CREATE TABLE test_my2("
+                                                  " abs_time BIGINT NOT NULL"
+                                                  ", forever BIGINT NOT NULL"
+                                                  ", u16 SMALLINT NOT NULL"
+                                                  ", u32 INT NOT NULL"
+                                                  ", u64 BIGINT NOT NULL"
+                                                  ")"))
+     {
+          fprintf (stderr, 
+                    "Failed to create table \n"); 
+          GNUNET_MYSQL_statements_invalidate (context);    
+          GNUNET_MYSQL_context_destroy (context);
+          
+          return 1;
+     }
 
      ret = run_queries (context);
-
-/*     if(GNUNET_OK != GNUNET_MYSQL_statement_run (context,
-                                                  "DROP TABLE test_my"))
+/*
+     if(GNUNET_OK != GNUNET_MYSQL_statement_run (context,
+                                                  "DROP TABLE test_my2"))
      {
           fprintf (stderr, "Failed to drop table test_my\n");
           GNUNET_MYSQL_statements_invalidate (context);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]