aboutsummaryrefslogtreecommitdiff
path: root/src/my
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-06 16:11:56 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-06 16:11:56 +0000
commit3b680a20ab2cbb98cfa658d85be7a44baaf95d2c (patch)
tree6217c36e0ace8a7892a0a1567f13e9985903c7d6 /src/my
parent67dc0efd426a379b818155ed87f3c1a76d9e352f (diff)
continue to fix extract result
Diffstat (limited to 'src/my')
-rw-r--r--src/my/my.c9
-rw-r--r--src/my/my_query_helper.c68
-rw-r--r--src/my/my_result_helper.c19
-rw-r--r--src/my/test_my.c50
4 files changed, 85 insertions, 61 deletions
diff --git a/src/my/my.c b/src/my/my.c
index d4e72ae7c3..ef11fbe74d 100644
--- a/src/my/my.c
+++ b/src/my/my.c
@@ -173,7 +173,16 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
mysql_stmt_error (stmt));
return GNUNET_SYSERR;
}
+
ret = mysql_stmt_fetch (stmt);
+
+ if (MYSQL_DATA_TRUNCATED == ret)
+ {
+ fprintf(stderr, "Data truncated with error %d \n", ret);
+ fprintf(stderr, "nontruncated length of the parameter values : %d\n", rs[0].mysql_bind_output_length);
+ return GNUNET_SYSERR;
+ }
+
if (MYSQL_NO_DATA == ret)
return GNUNET_NO;
if (0 != ret)
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c
index 6bbbf0b51a..07eb2481d5 100644
--- a/src/my/my_query_helper.c
+++ b/src/my/my_query_helper.c
@@ -61,11 +61,11 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
size_t ptr_size)
{
struct GNUNET_MY_QueryParam qp = {
- &my_conv_fixed_size,
- NULL,
- 1,
- ptr,
- (unsigned long) ptr_size
+ .conv = &my_conv_fixed_size,
+ .conv_cls = NULL,
+ .num_params = 1,
+ .data = ptr,
+ .data_len = (unsigned long) ptr_size
};
return qp;
}
@@ -125,11 +125,11 @@ struct GNUNET_MY_QueryParam
GNUNET_MY_query_param_uint16 (const uint16_t *x)
{
struct GNUNET_MY_QueryParam res = {
- &my_conv_uint16,
- NULL,
- 1,
- x,
- sizeof (*x)
+ .conv = &my_conv_uint16,
+ .conv_cls = NULL,
+ .num_params = 1,
+ .data = x,
+ .data_len = sizeof (*x)
};
return res;
@@ -173,11 +173,11 @@ struct GNUNET_MY_QueryParam
GNUNET_MY_query_param_uint32 (const uint32_t *x)
{
struct GNUNET_MY_QueryParam res = {
- &my_conv_uint32,
- NULL,
- 1,
- x,
- sizeof (*x)
+ .conv = &my_conv_uint32,
+ .conv_cls = NULL,
+ .num_params = 1,
+ .data = x,
+ .data_len = sizeof (*x)
};
return res;
@@ -221,11 +221,11 @@ struct GNUNET_MY_QueryParam
GNUNET_MY_query_param_uint64 (const uint64_t *x)
{
struct GNUNET_MY_QueryParam res = {
- &my_conv_uint64,
- NULL,
- 1,
- x,
- sizeof(*x)
+ .conv = &my_conv_uint64,
+ .conv_cls = NULL,
+ .num_params = 1,
+ .data = x,
+ .data_len = sizeof(*x)
};
return res;
@@ -253,8 +253,8 @@ my_conv_rsa_public_key (void *cls,
buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf);
qbind->buffer = (void *)buf;
- qbind->buffer_length = buf_size - 1;
- qbind->buffer_type = MYSQL_TYPE_LONG;
+ qbind->buffer_length = buf_size-1;
+ qbind->buffer_type = MYSQL_TYPE_BLOB;
return 1;
}
@@ -270,11 +270,11 @@ struct GNUNET_MY_QueryParam
GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x)
{
struct GNUNET_MY_QueryParam res = {
- &my_conv_rsa_public_key,
- NULL,
- 1,
- x,
- 0
+ .conv = &my_conv_rsa_public_key,
+ .conv_cls = NULL,
+ .num_params = 1,
+ .data = x,
+ .data_len = 0
};
return res;
@@ -303,8 +303,8 @@ my_conv_rsa_signature (void *cls,
&buf);
qbind->buffer = (void *)buf;
- qbind->buffer_length = buf_size - 1;
- qbind->buffer_type = MYSQL_TYPE_LONG;
+ qbind->buffer_length = buf_size-1;
+ qbind->buffer_type = MYSQL_TYPE_BLOB;
return 1;
}
@@ -320,11 +320,11 @@ struct GNUNET_MY_QueryParam
GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
{
struct GNUNET_MY_QueryParam res = {
- &my_conv_rsa_signature,
- NULL,
- 1,
- (x),
- 0
+ .conv = &my_conv_rsa_signature,
+ .conv_cls = NULL,
+ .num_params = 1,
+ .data = (x),
+ .data_len = 0
};
return res;
}
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c
index eafe434f81..97cc1f1bf3 100644
--- a/src/my/my_result_helper.c
+++ b/src/my/my_result_helper.c
@@ -37,9 +37,10 @@ pre_extract_varsize_blob (void *cls,
unsigned int column,
MYSQL_BIND *results)
{
- results[0].buffer = 0;
+ results[0].buffer = NULL;
results[0].buffer_length = 0;
results[0].length = &rs->mysql_bind_output_length;
+ results[0].buffer_type = MYSQL_TYPE_BLOB;
return GNUNET_OK;
}
@@ -73,6 +74,7 @@ post_extract_varsize_blob (void *cls,
buf = GNUNET_malloc (size);
results[0].buffer = buf;
results[0].buffer_length = size;
+
if (0 !=
mysql_stmt_fetch_column (stmt,
results,
@@ -235,10 +237,10 @@ pre_extract_rsa_public_key (void *cls,
MYSQL_BIND *results)
{
- results[0].buffer = 0;
+ results[0].buffer = NULL;
results[0].buffer_length = 0;
- results[0].length = rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_LONG;
+ results[0].length = &rs->mysql_bind_output_length;
+ results[0].buffer_type = MYSQL_TYPE_BLOB;
return GNUNET_OK;
}
@@ -292,9 +294,6 @@ post_extract_rsa_public_key (void *cls,
return GNUNET_SYSERR;
}
- if (rs->dst_size != rs->mysql_bind_output_length)
- return GNUNET_SYSERR;
-
return GNUNET_OK;
}
@@ -366,7 +365,7 @@ pre_extract_rsa_signature (void *cls,
results[0].buffer = 0;
results[0].buffer_length = 0;
results[0].length = &rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_LONG;
+ results[0].buffer_type = MYSQL_TYPE_BLOB;
return GNUNET_OK;
}
@@ -391,8 +390,8 @@ post_extract_rsa_signature (void *cls,
MYSQL_BIND *results)
{
struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
- size_t size;
- const char *res;
+ size_t size = 0 ;
+ char *res = NULL;
results[0].buffer = res;
results[0].buffer_length = size;
diff --git a/src/my/test_my.c b/src/my/test_my.c
index c9529cbaf6..af15b6ab2d 100644
--- a/src/my/test_my.c
+++ b/src/my/test_my.c
@@ -75,8 +75,8 @@ run_queries (struct GNUNET_MYSQL_Context *context)
u32 = 32;
u64 = 64;
-/* statements_handle_insert = GNUNET_MYSQL_statement_prepare (context,
- "INSERT INTO test_my ("
+ statements_handle_insert = GNUNET_MYSQL_statement_prepare (context,
+ "INSERT INTO test_my2 ("
" pub"
",sig"
",abs_time"
@@ -107,26 +107,28 @@ run_queries (struct GNUNET_MYSQL_Context *context)
GNUNET_MY_query_param_uint64 (&u64),
GNUNET_MY_query_param_end
};
-*/
- statements_handle_insert = GNUNET_MYSQL_statement_prepare (context,
+
+ /* statements_handle_insert = GNUNET_MYSQL_statement_prepare (context,
"INSERT INTO test_my2 ("
" abs_time"
",forever"
+ ",hash"
",u16"
",u32"
",u64"
") VALUES "
- "( ?, ?, ?, ?, ?)");
+ "( ?, ?, ?, ?, ?, ?)");
struct GNUNET_MY_QueryParam params_insert[] = {
GNUNET_MY_query_param_absolute_time (&abs_time),
GNUNET_MY_query_param_absolute_time (&forever),
+ GNUNET_MY_query_param_auto_from_type (&hc),
GNUNET_MY_query_param_uint16 (&u16),
GNUNET_MY_query_param_uint32 (&u32),
GNUNET_MY_query_param_uint64 (&u64),
GNUNET_MY_query_param_end
};
-
+*/
if (GNUNET_OK != GNUNET_MY_exec_prepared(context,
statements_handle_insert,
params_insert))
@@ -155,8 +157,12 @@ run_queries (struct GNUNET_MYSQL_Context *context)
*/
statements_handle_select = GNUNET_MYSQL_statement_prepare (context,
"SELECT"
+ //" pub"
+ //" sig"
" abs_time"
",forever"
+ ",hash"
+ //" vsize"
",u16"
",u32"
",u64"
@@ -195,8 +201,12 @@ run_queries (struct GNUNET_MYSQL_Context *context)
};
*/
struct GNUNET_MY_ResultSpec results_select[] = {
+ //GNUNET_MY_result_spec_rsa_public_key (&pub2),
+ //GNUNET_MY_result_spec_rsa_signature (&sig2),
GNUNET_MY_result_spec_absolute_time (&abs_time2),
GNUNET_MY_result_spec_absolute_time (&forever2),
+ GNUNET_MY_result_spec_auto_from_type (&hc2),
+ //GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len),
GNUNET_MY_result_spec_uint16 (&u162),
GNUNET_MY_result_spec_uint32 (&u322),
GNUNET_MY_result_spec_uint64 (&u642),
@@ -206,8 +216,13 @@ run_queries (struct GNUNET_MYSQL_Context *context)
ret = GNUNET_MY_extract_result (statements_handle_select,
results_select);
+ GNUNET_break (GNUNET_YES == ret);
GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us);
GNUNET_break (forever.abs_value_us == forever2.abs_value_us);
+ GNUNET_break (0 ==
+ memcmp (&hc,
+ &hc2,
+ sizeof (struct GNUNET_HashCode)));
GNUNET_break (16 == u162);
GNUNET_break (32 == u322);
@@ -256,14 +271,14 @@ main (int argc, const char * const argv[])
return 77;
}
-/* if (GNUNET_OK != GNUNET_MYSQL_statement_run (context,
- "CREATE TABLE test_my("
- "pub INT NOT NULL"
- ", sig INT NOT NULL"
+ if (GNUNET_OK != GNUNET_MYSQL_statement_run (context,
+ "CREATE TABLE test_my2("
+ "pub BLOB NOT NULL"
+ ", sig BLOB NOT NULL"
", abs_time BIGINT NOT NULL"
", forever BIGINT NOT NULL"
- ", hash VARCHAR(32) NOT NULL CHECK(LENGTH(hash)=64)"
- ", vsize VARCHAR(32) NOT NULL"
+ ", hash BLOB NOT NULL CHECK(LENGTH(hash)=64)"
+ ", vsize BLOB NOT NULL"
", u16 SMALLINT NOT NULL"
", u32 INT NOT NULL"
", u64 BIGINT NOT NULL"
@@ -276,11 +291,12 @@ main (int argc, const char * const argv[])
return 1;
}
-*/
- if (GNUNET_OK != GNUNET_MYSQL_statement_run (context,
+
+/* if (GNUNET_OK != GNUNET_MYSQL_statement_run (context,
"CREATE TABLE test_my2("
" abs_time BIGINT NOT NULL"
", forever BIGINT NOT NULL"
+ ", hash VARCHAR(32) NOT NULL CHECK(LENGTH(hash)=64)"
", u16 SMALLINT NOT NULL"
", u32 INT NOT NULL"
", u64 BIGINT NOT NULL"
@@ -293,10 +309,10 @@ main (int argc, const char * const argv[])
return 1;
}
-
+*/
ret = run_queries (context);
-/*
- if(GNUNET_OK != GNUNET_MYSQL_statement_run (context,
+
+/* if(GNUNET_OK != GNUNET_MYSQL_statement_run (context,
"DROP TABLE test_my2"))
{
fprintf (stderr, "Failed to drop table test_my\n");