allow empty/NULL context message
[oweals/gnunet.git] / src / my / my_query_helper.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;
 }