aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-07-28 14:41:09 -0400
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-07-28 14:45:29 -0400
commitf5fbee84de11776b796b57d80e5daf47d5543da6 (patch)
tree4ccc1dbbcb77c75185b82a624a191169044973b2 /src
parent313eacd26062ce24452c569a68925fa4a317c9b4 (diff)
downloadmysqlerl-f5fbee84de11776b796b57d80e5daf47d5543da6.tar.gz
mysqlerl-f5fbee84de11776b796b57d80e5daf47d5543da6.zip
Fix crash when trying to get a row count from a query with no results.
Diffstat (limited to 'src')
-rw-r--r--src/mysqlerl.c11
1 files 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 {