add function conv param string
authorChristophe Genevey Metat <genevey.christophe@gmail.com>
Mon, 27 Jun 2016 15:34:12 +0000 (15:34 +0000)
committerChristophe Genevey Metat <genevey.christophe@gmail.com>
Mon, 27 Jun 2016 15:34:12 +0000 (15:34 +0000)
src/my/my_query_helper.c
src/regex/gnunet-regex-simulation-profiler.c

index 436860691065ba051cd4869b7758a70bcf09dd38..17ade5a9274c2949401bc7456d538d7fd1d7e5d1 100644 (file)
@@ -88,6 +88,29 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
 }
 
 
+/**
+ * Function called to convert input argument into SQL parameters.
+ *
+ * @param cls closure
+ * @param pq data about the query
+ * @param qbind array of parameters to initialize
+ * @return -1 on error
+ */
+static int
+my_conv_string (void *cls,
+                const struct GNUNET_MY_QueryParam *qp,
+                MYSQL_BIND *qbind)
+{
+  GNUNET_assert (1 == qp->num_params);
+
+  qbind->buffer = (void *) qp->data;
+  qbind->buffer_length = qp->data_len;
+  qbind->buffer_type = MYSQL_TYPE_STRING;
+
+  return 1;
+}
+
+
 /**
  * Generate query parameter for a string
  *
@@ -96,8 +119,15 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
 struct GNUNET_MY_QueryParam
 GNUNET_MY_query_param_string (const char *ptr)
 {
-  return GNUNET_MY_query_param_fixed_size (ptr,
-                                           strlen(ptr));
+  struct GNUNET_MY_QueryParam qp = {
+    .conv = &my_conv_string,
+    .cleaner = NULL,
+    .conv_cls = NULL,
+    .num_params = 1,
+    .data = ptr,
+    .data_len = strlen (ptr)
+  };
+  return qp;
 }
 
 
index e88a007498a78953962d09e32472bffe59a99513..62c768a55fde6097b7766ede5f75b9d3f26ceced 100644 (file)
@@ -316,10 +316,10 @@ do_abort (void *cls)
  */
 static void
 regex_iterator (void *cls,
-                           const struct GNUNET_HashCode *key,
-                           const char *proof,
+               const struct GNUNET_HashCode *key,
+               const char *proof,
                 int accepting,
-                           unsigned int num_edges,
+               unsigned int num_edges,
                 const struct REGEX_BLOCK_Edge *edges)
 {
   unsigned int i;
@@ -334,7 +334,7 @@ regex_iterator (void *cls,
   {
     struct GNUNET_MY_QueryParam params_select[] = {
       GNUNET_MY_query_param_auto_from_type (key),
-      GNUNET_MY_query_param_fixed_size(edges[i].label, strlen (edges[i].label)),
+      GNUNET_MY_query_param_string (edges[i].label),
       GNUNET_MY_query_param_end
     };
 
@@ -370,13 +370,14 @@ regex_iterator (void *cls,
 
     if (-1 != total && total > 0)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n", (unsigned long long)total,
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n", 
+                 (unsigned long long)total,
                   GNUNET_h2s (key), edges[i].label);
     }
 
     struct GNUNET_MY_QueryParam params_stmt[] = {
       GNUNET_MY_query_param_auto_from_type (&key),
-      GNUNET_MY_query_param_fixed_size (edges[i].label, strlen (edges[i].label)),
+      GNUNET_MY_query_param_string (edges[i].label),
       GNUNET_MY_query_param_auto_from_type (&edges[i].destination),
       GNUNET_MY_query_param_uint32 (&iaccepting),
       GNUNET_MY_query_param_end
@@ -392,8 +393,12 @@ regex_iterator (void *cls,
       char *key_str = GNUNET_strdup (GNUNET_h2s (key));
       char *to_key_str = GNUNET_strdup (GNUNET_h2s (&edges[i].destination));
 
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n", key_str,
-                  edges[i].label, to_key_str, accepting);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n", 
+                 key_str,
+                  edges[i].label, 
+                 to_key_str, 
+                 accepting);
+
       GNUNET_free (key_str);
       GNUNET_free (to_key_str);
       num_merged_transitions++;
@@ -416,7 +421,7 @@ regex_iterator (void *cls,
   {
     struct GNUNET_MY_QueryParam params_stmt[] = {
       GNUNET_MY_query_param_auto_from_type (key),
-      GNUNET_MY_query_param_fixed_size (NULL, 0),
+      GNUNET_MY_query_param_string (""),
       GNUNET_MY_query_param_auto_from_type (NULL),
       GNUNET_MY_query_param_uint32 (&iaccepting),
       GNUNET_MY_query_param_end