From f5fbee84de11776b796b57d80e5daf47d5543da6 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 28 Jul 2008 14:41:09 -0400 Subject: Fix crash when trying to get a row count from a query with no results. --- src/mysqlerl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mysqlerl.c b/src/mysqlerl.c index 4932700..4b1fac6 100644 --- a/src/mysqlerl.c +++ b/src/mysqlerl.c @@ -27,13 +27,14 @@ MYSQL_RES *results = NULL; my_ulonglong resultoffset = 0, numrows = 0; void -set_mysql_results(MYSQL_RES *res) +set_mysql_results() { if (results) mysql_free_result(results); - results = res; + results = mysql_store_result(&dbh); + resultoffset = 0; - numrows = mysql_num_rows(results); + numrows = results ? mysql_num_rows(results) : 0; } ETERM * @@ -208,7 +209,7 @@ handle_query(ETERM *cmd) resp = erl_format("{error, {mysql_error, ~i, ~s}}", mysql_errno(&dbh), mysql_error(&dbh)); } else { - set_mysql_results(mysql_store_result(&dbh)); + set_mysql_results(); if (results) { resp = handle_mysql_result(results); set_mysql_results(NULL); @@ -275,7 +276,7 @@ handle_select_count(ETERM *msg) resp = erl_format("{error, {mysql_error, ~i, ~s}}", mysql_errno(&dbh), mysql_error(&dbh)); } else { - set_mysql_results(mysql_store_result(&dbh)); + set_mysql_results(); if (results) { resp = erl_format("{ok, ~i}", numrows); } else { -- cgit v1.2.3