aboutsummaryrefslogtreecommitdiff
path: root/src/my/my.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-24 20:12:53 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-24 20:12:53 +0000
commitd5fd881c2a044474b54ddf03b6ab8be8d2b75927 (patch)
treeb3565f8038b761a2a2117476dc7d493fc8e0cde2 /src/my/my.c
parent63b2e5ce20544b22da822848d6e3f3c495f381c3 (diff)
-handle NULL results
Diffstat (limited to 'src/my/my.c')
-rw-r--r--src/my/my.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/my/my.c b/src/my/my.c
index ae46a2888d..5ca80b63c9 100644
--- a/src/my/my.c
+++ b/src/my/my.c
@@ -75,9 +75,11 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
if (mysql_stmt_bind_param (stmt,
qbind))
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "my",
_("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_param", __FILE__, __LINE__,
+ "mysql_stmt_bind_param",
+ __FILE__, __LINE__,
mysql_stmt_error (stmt));
GNUNET_MYSQL_statements_invalidate (mc);
return GNUNET_SYSERR;
@@ -85,18 +87,17 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
if (mysql_stmt_execute (stmt))
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "my",
_("`%s' failed at %s:%d with error: %s\n"),
"mysql_stmt_execute", __FILE__, __LINE__,
mysql_stmt_error (stmt));
GNUNET_MYSQL_statements_invalidate (mc);
return GNUNET_SYSERR;
}
-
GNUNET_MY_cleanup_query (params,
qbind);
}
-
return GNUNET_OK;
}
@@ -125,7 +126,6 @@ GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp,
* Extract results from a query result according to the given
* specification. Always fetches the next row.
*
- *
* @param sh statement that returned results
* @param rs specification to extract for
* @return
@@ -145,12 +145,14 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
stmt = GNUNET_MYSQL_statement_get_stmt (sh);
if (NULL == stmt)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
- ("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_result", __FILE__, __LINE__,
- mysql_stmt_error (stmt));
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
+ if (NULL == rs)
+ {
+ mysql_stmt_free_result (stmt);
+ return GNUNET_NO;
+ }
num_fields = 0;
for (i=0;NULL != rs[i].pre_conv;i++)
@@ -187,25 +189,32 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
}
field_off += rp->num_fields;
}
+
if (mysql_stmt_bind_result (stmt, result))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"my",
- _("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_result", __FILE__, __LINE__,
+ _("%s failed at %s:%d with error: %s\n"),
+ "mysql_stmt_bind_result",
+ __FILE__, __LINE__,
mysql_stmt_error (stmt));
return GNUNET_SYSERR;
}
-
+#if TEST_OPTIMIZATION
+ (void) mysql_stmt_store_result (stmt);
+#endif
ret = mysql_stmt_fetch (stmt);
-
if (MYSQL_NO_DATA == ret)
+ {
+ mysql_stmt_free_result (stmt);
return GNUNET_NO;
- if ((0 != ret ) && (MYSQL_DATA_TRUNCATED != ret))
+ }
+ if (1 == ret)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"my",
- _("mysql_stmt_fetch failed at %s:%d with error: %s\n"),
+ _("%s failed at %s:%d with error: %s\n"),
+ "mysql_stmt_fetch",
__FILE__, __LINE__,
mysql_stmt_error (stmt));
GNUNET_MY_cleanup_result (rs);
@@ -235,7 +244,6 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
field_off += rp->num_fields;
}
}
- mysql_stmt_free_result (stmt);
return GNUNET_OK;
}