gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37238 - gnunet/src/my


From: gnunet
Subject: [GNUnet-SVN] r37238 - gnunet/src/my
Date: Fri, 3 Jun 2016 11:06:30 +0200

Author: christophe.genevey
Date: 2016-06-03 11:06:30 +0200 (Fri, 03 Jun 2016)
New Revision: 37238

Modified:
   gnunet/src/my/my.c
   gnunet/src/my/test_my.c
Log:
start to written extract_result

Modified: gnunet/src/my/my.c
===================================================================
--- gnunet/src/my/my.c  2016-06-02 17:35:00 UTC (rev 37237)
+++ gnunet/src/my/my.c  2016-06-03 09:06:30 UTC (rev 37238)
@@ -27,8 +27,8 @@
 #include <mysql/mysql.h>
 #include "gnunet_my_lib.h"
 
+#define STRING_SIZE 50
 
-
 /**
  * Run a prepared SELECT statement.
  *
@@ -118,19 +118,86 @@
                           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;
+  }
 
+
+  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 @@
       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]);
+    }
 
-    spec = &rs[i];
-    ret = spec->conv (spec->conv_cls,
-                      spec,
-                      result);
+    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;
+  }
 
-    if (GNUNET_SYSERR == ret)
+/*
+  while (1)
+  {
+    mysql_stmt_fetch (stmt);
+
+    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 (GNUNET_SYSERR == ret)
+      {
+        return GNUNET_SYSERR;
+      }
+
+      if (NULL != spec->result_size)
+        *spec->result_size = spec->dst_size;
     }
-
-    if (NULL != spec->result_size)
-      *spec->result_size = spec->dst_size;
   }
 
   if (GNUNET_YES == had_null)
     return GNUNET_NO;
+*/
 
+  free (result);
   return GNUNET_OK;
 }
 

Modified: gnunet/src/my/test_my.c
===================================================================
--- gnunet/src/my/test_my.c     2016-06-02 17:35:00 UTC (rev 37237)
+++ gnunet/src/my/test_my.c     2016-06-03 09:06:30 UTC (rev 37238)
@@ -38,35 +38,31 @@
 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 @@
 
 
 
-/*   statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
+   statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
                                                                  "SELECT"
                                                                  " pub"
                                                                  ",sig"
@@ -178,7 +174,7 @@
           fprintf(stderr, "Failed to extract result\n");
           return 1;
      }
-*/
+
      return 0;
 }
 
@@ -245,8 +241,8 @@
           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;
 }




reply via email to

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