aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-03-02 18:51:03 -0500
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-03-02 18:51:03 -0500
commit9b172108c0facc0e480d5e4e534e3d600d11df12 (patch)
treecbd65652b161f353c09fbc9e3737566b16379792 /src
parent2c799d15e608d3139bc94e4bf1156767b5e9e5a3 (diff)
downloadmysqlerl-9b172108c0facc0e480d5e4e534e3d600d11df12.tar.gz
mysqlerl-9b172108c0facc0e480d5e4e534e3d600d11df12.zip
Return empty Rows on last next.
Diffstat (limited to 'src')
-rw-r--r--src/mysqlerl.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c
index ffac9fb..5c2063f 100644
--- a/src/mysqlerl.c
+++ b/src/mysqlerl.c
@@ -18,6 +18,7 @@ const char *SELECT_COUNT_MSG = "sql_select_count";
const char *NEXT_MSG = "sql_next";
MYSQL_RES *results = NULL;
+my_ulonglong resultoffset = 0;
void
usage()
@@ -32,6 +33,7 @@ set_mysql_results(MYSQL_RES *res)
if (results)
mysql_free_result(results);
results = res;
+ resultoffset = 0;
}
ETERM *
@@ -248,13 +250,16 @@ handle_next(MYSQL *dbh, ETERM *msg)
fields = mysql_fetch_fields(results);
ecols = make_cols(fields, num_fields);
- erows = make_rows(1, num_fields);
-
- resp = erl_format("{selected, ~w, ~w}", ecols, erows);
+ if (resultoffset == mysql_num_rows(results)) {
+ resp = erl_format("{selected, ~w, []}", ecols);
+ } else {
+ erows = make_rows(1, num_fields);
+ resp = erl_format("{selected, ~w, ~w}", ecols, erows);
+ erl_free_term(erows);
+ resultoffset++;
+ }
erl_free_term(ecols);
- erl_free_term(erows);
-
write_msg(resp);
erl_free_term(resp);
}