diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-05-31 13:44:31 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-05-31 13:44:31 +0000 |
commit | 5f164d71d10dcaad7200dfabcbfd7fdc4f030622 (patch) | |
tree | d4d615a7a4c8a9f69f898f1a2226acbc0e8a3d3f | |
parent | 993f58bc44663821311792bc46f025f2ac3a9695 (diff) | |
download | gnunet-5f164d71d10dcaad7200dfabcbfd7fdc4f030622.tar.gz gnunet-5f164d71d10dcaad7200dfabcbfd7fdc4f030622.zip |
fixing query insert
-rw-r--r-- | src/include/gnunet_my_lib.h | 2 | ||||
-rw-r--r-- | src/my/my_query_helper.c | 12 | ||||
-rw-r--r-- | src/my/test_my.c | 21 |
3 files changed, 23 insertions, 12 deletions
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index 0f10104b8..ffba2a66c 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h | |||
@@ -251,7 +251,7 @@ GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x | |||
251 | struct GNUNET_MY_QueryParam | 251 | struct GNUNET_MY_QueryParam |
252 | GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x); | 252 | GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x); |
253 | 253 | ||
254 | /** | 254 | /**q |
255 | * Generate query parameter for an absolute time value. | 255 | * Generate query parameter for an absolute time value. |
256 | * The database must store a 64-bit integer. | 256 | * The database must store a 64-bit integer. |
257 | * | 257 | * |
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index ee266ddc1..a8a9ce7b6 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <mysql/mysql.h> | 26 | #include <mysql/mysql.h> |
27 | #include "gnunet_my_lib.h" | 27 | #include "gnunet_my_lib.h" |
28 | 28 | ||
29 | |||
30 | /** | 29 | /** |
31 | * Function called to convert input argument into SQL parameters. | 30 | * Function called to convert input argument into SQL parameters. |
32 | * | 31 | * |
@@ -41,11 +40,13 @@ my_conv_fixed_size (void *cls, | |||
41 | MYSQL_BIND *qbind) | 40 | MYSQL_BIND *qbind) |
42 | { | 41 | { |
43 | GNUNET_assert (1 == qp->num_params); | 42 | GNUNET_assert (1 == qp->num_params); |
43 | |||
44 | qbind->buffer = (void *) qp->data; | 44 | qbind->buffer = (void *) qp->data; |
45 | qbind->buffer_length = qp->data_len; | 45 | qbind->buffer_length = qp->data_len; |
46 | qbind->length = (unsigned long *) &qp->data_len; | ||
47 | qbind->buffer_type = 1; | 46 | qbind->buffer_type = 1; |
48 | return 0; | 47 | |
48 | //return 0; | ||
49 | return 1; | ||
49 | } | 50 | } |
50 | 51 | ||
51 | 52 | ||
@@ -99,10 +100,15 @@ my_conv_uint16 (void *cls, | |||
99 | const uint16_t *u_hbo = qp->data; | 100 | const uint16_t *u_hbo = qp->data; |
100 | uint16_t *u_nbo; | 101 | uint16_t *u_nbo; |
101 | 102 | ||
103 | fprintf(stderr, "input data : %u\n", (unsigned)u_hbo); | ||
104 | |||
102 | GNUNET_assert (1 == qp->num_params); | 105 | GNUNET_assert (1 == qp->num_params); |
103 | 106 | ||
107 | |||
104 | u_nbo = GNUNET_new (uint16_t); | 108 | u_nbo = GNUNET_new (uint16_t); |
105 | *u_nbo = htons (*u_hbo); | 109 | *u_nbo = htons (*u_hbo); |
110 | |||
111 | fprintf(stderr, "output data : %u\n", (unsigned)u_nbo); | ||
106 | qbind->buffer = (void *) u_nbo; | 112 | qbind->buffer = (void *) u_nbo; |
107 | qbind->buffer_length = sizeof(uint16_t); | 113 | qbind->buffer_length = sizeof(uint16_t); |
108 | qbind->buffer_type = 1; | 114 | qbind->buffer_type = 1; |
diff --git a/src/my/test_my.c b/src/my/test_my.c index 3cd6881c1..067d70a6e 100644 --- a/src/my/test_my.c +++ b/src/my/test_my.c | |||
@@ -47,8 +47,8 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
47 | uint32_t u32; | 47 | uint32_t u32; |
48 | uint64_t u64; | 48 | uint64_t u64; |
49 | 49 | ||
50 | // struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; | 50 | struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; |
51 | struct GNUNET_MYSQL_StatementHandle *statements_handle_select; | 51 | // struct GNUNET_MYSQL_StatementHandle *statements_handle_select; |
52 | 52 | ||
53 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; | 53 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; |
54 | struct GNUNET_HashCode hmsg; | 54 | struct GNUNET_HashCode hmsg; |
@@ -62,7 +62,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
62 | u32 = 32; | 62 | u32 = 32; |
63 | u64 = 64; | 63 | u64 = 64; |
64 | 64 | ||
65 | /* FIXE THE INSERT QUERY | 65 | // FIXE THE INSERT QUERY |
66 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, | 66 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, |
67 | "INSERT INTO test_my (" | 67 | "INSERT INTO test_my (" |
68 | " pub" | 68 | " pub" |
@@ -75,15 +75,16 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
75 | ",u32" | 75 | ",u32" |
76 | ",u64" | 76 | ",u64" |
77 | ") VALUES " | 77 | ") VALUES " |
78 | "(@1, @2, @3, @4, @5, @6," | 78 | "(?, ?, ?, ?, ?, ?," |
79 | "@7, @8, @9);"); | 79 | "?, ?, ?)"); |
80 | 80 | ||
81 | if (NULL == statements_handle_insert) | 81 | if (NULL == statements_handle_insert) |
82 | { | 82 | { |
83 | fprintf(stderr, "Failed to prepared statement INSERT\n"); | 83 | fprintf (stderr, "Failed to prepared statement INSERT\n"); |
84 | return 1; | 84 | return 1; |
85 | } | 85 | } |
86 | 86 | ||
87 | //ERROR WITH MSG | ||
87 | struct GNUNET_MY_QueryParam params_insert[] = { | 88 | struct GNUNET_MY_QueryParam params_insert[] = { |
88 | GNUNET_MY_query_param_rsa_public_key (pub), | 89 | GNUNET_MY_query_param_rsa_public_key (pub), |
89 | GNUNET_MY_query_param_rsa_signature (sig), | 90 | GNUNET_MY_query_param_rsa_signature (sig), |
@@ -97,6 +98,9 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
97 | GNUNET_MY_query_param_end | 98 | GNUNET_MY_query_param_end |
98 | }; | 99 | }; |
99 | 100 | ||
101 | fprintf(stderr, " u16 : %u\n", (unsigned)params_insert[6].data); | ||
102 | fprintf(stderr, " &u16 : %u\n", (unsigned)&u16); | ||
103 | |||
100 | //FAIL HERE | 104 | //FAIL HERE |
101 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, | 105 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, |
102 | statements_handle_insert, | 106 | statements_handle_insert, |
@@ -106,7 +110,8 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
106 | "Failed to execute prepared statement\n"); | 110 | "Failed to execute prepared statement\n"); |
107 | return 22; | 111 | return 22; |
108 | } | 112 | } |
109 | */ | 113 | |
114 | /* NOT THE GOOD FUNCTION -> TO FIXE | ||
110 | statements_handle_select = GNUNET_MYSQL_statement_prepare (context, | 115 | statements_handle_select = GNUNET_MYSQL_statement_prepare (context, |
111 | "SELECT" | 116 | "SELECT" |
112 | " pub" | 117 | " pub" |
@@ -139,7 +144,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
139 | fprintf (stderr, "Failed to execute prepared statement\n"); | 144 | fprintf (stderr, "Failed to execute prepared statement\n"); |
140 | return 22; | 145 | return 22; |
141 | } | 146 | } |
142 | 147 | */ | |
143 | return 0; | 148 | return 0; |
144 | } | 149 | } |
145 | 150 | ||