diff options
Diffstat (limited to 'src/my/my_query_helper.c')
-rw-r--r-- | src/my/my_query_helper.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c new file mode 100644 index 000000000..057c32d9f --- /dev/null +++ b/src/my/my_query_helper.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file my/my_query_helper.c | ||
22 | * @brief library to help with access to a MySQL database | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include <mysql/mysql.h> | ||
27 | #include "gnunet_my_lib.h" | ||
28 | |||
29 | |||
30 | /** | ||
31 | * Function called to convert input argument into SQL parameters. | ||
32 | * | ||
33 | * @param cls closure | ||
34 | * @param pq data about the query | ||
35 | * @param qbind array of parameters to initialize | ||
36 | * @return -1 on error | ||
37 | */ | ||
38 | static int | ||
39 | pq_conv_fixed_size (void *cls, | ||
40 | const struct GNUNET_MY_QueryParam *qp, | ||
41 | MYSQL_BIND *qbind) | ||
42 | { | ||
43 | GNUNET_assert (1 == qp->num_params); | ||
44 | qbind->buffer = (void *) qp->data; | ||
45 | qbind->buffer_length = qp->data_len; | ||
46 | qbind->length = (unsigned long *) &qp->data_len; | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | |||
51 | /** | ||
52 | * Generate query parameter for a buffer @a ptr of | ||
53 | * @a ptr_size bytes. | ||
54 | * | ||
55 | * @param ptr pointer to the query parameter to pass | ||
56 | * @oaran ptr_size number of bytes in @a ptr | ||
57 | */ | ||
58 | struct GNUNET_MY_QueryParam | ||
59 | GNUNET_MY_query_param_fixed_size (const void *ptr, | ||
60 | size_t ptr_size) | ||
61 | { | ||
62 | struct GNUNET_MY_QueryParam qp = { | ||
63 | &pq_conv_fixed_size, | ||
64 | NULL, | ||
65 | 1, | ||
66 | ptr, | ||
67 | (unsigned long) ptr_size | ||
68 | }; | ||
69 | return qp; | ||
70 | } | ||
71 | |||
72 | |||
73 | /* end of my_query_helper.c */ | ||