aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2012-02-07 18:42:57 -0500
committerBrian Cully <github.20.shmit@spamgourmet.com>2012-02-07 18:42:57 -0500
commit29df8ec1113f91bf54d5d26840911c2643e27c6b (patch)
tree971b46d10929e8ee2f19c786940bcf2a32a6e933 /src
parent672fb633ebba099929277c79cb4c5b162c69fc0a (diff)
downloadmysqlerl-29df8ec1113f91bf54d5d26840911c2643e27c6b.tar.gz
mysqlerl-29df8ec1113f91bf54d5d26840911c2643e27c6b.zip
Fix cursor traversing bugs in the port driver.
Diffstat (limited to 'src')
-rw-r--r--src/mysqlerl.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c
index 0ee04ed..80d7303 100644
--- a/src/mysqlerl.c
+++ b/src/mysqlerl.c
@@ -36,7 +36,8 @@ my_bool FALSY = 0;
MYSQL dbh;
MYSQL_RES *results = NULL;
-my_ulonglong resultoffset = 0, numrows = 0;
+my_ulonglong numrows = 0;
+my_ulonglong resultoffset = 0; // The index of the next row to read.
void
set_mysql_results()
@@ -126,7 +127,6 @@ make_rows(unsigned int num_rows, unsigned int num_fields)
MYSQL_ROW row;
row = mysql_fetch_row(results);
- resultoffset++;
lengths = mysql_fetch_lengths(results);
rt = make_row(row, lengths, num_fields);
@@ -155,6 +155,7 @@ handle_mysql_result()
ecols = make_cols(fields, num_fields);
erows = make_rows(numrows, num_fields);
+ resultoffset = numrows;
resp = erl_format("{selected, ~w, ~w}", ecols, erows);
@@ -553,6 +554,7 @@ handle_select(ETERM *msg)
ecols = make_cols(fields, num_fields);
erows = make_rows(num_items, num_fields);
+ resultoffset += num_items;
resp = erl_format("{selected, ~w, ~w}", ecols, erows);
erl_free_term(erows);
@@ -574,10 +576,10 @@ handle_first(ETERM *msg)
exit(2);
}
- num_fields = mysql_num_fields(results);
- fields = mysql_fetch_fields(results);
- resultoffset = 0;
+ num_fields = mysql_num_fields(results);
+ fields = mysql_fetch_fields(results);
mysql_data_seek(results, resultoffset);
+ resultoffset = 1;
ecols = make_cols(fields, num_fields);
erows = make_rows(1, num_fields);
@@ -602,10 +604,10 @@ handle_last(ETERM *msg)
exit(2);
}
- num_fields = mysql_num_fields(results);
- fields = mysql_fetch_fields(results);
- resultoffset = numrows - 1;
- mysql_data_seek(results, resultoffset);
+ num_fields = mysql_num_fields(results);
+ fields = mysql_fetch_fields(results);
+ mysql_data_seek(results, numrows - 1);
+ resultoffset = numrows;
ecols = make_cols(fields, num_fields);
erows = make_rows(1, num_fields);
@@ -638,6 +640,8 @@ handle_next(ETERM *msg)
if (resultoffset == numrows) {
resp = erl_format("{selected, ~w, []}", ecols);
} else {
+ mysql_data_seek(results, resultoffset);
+ resultoffset++;
erows = make_rows(1, num_fields);
resp = erl_format("{selected, ~w, ~w}", ecols, erows);
erl_free_term(erows);
@@ -669,13 +673,9 @@ handle_prev(ETERM *msg)
if (resultoffset <= 1) {
resp = erl_format("{selected, ~w, []}", ecols);
} else {
- resultoffset = resultoffset - 1;
- mysql_data_seek(results, resultoffset);
+ resultoffset--;
+ mysql_data_seek(results, resultoffset - 1);
erows = make_rows(1, num_fields);
-
- /* Rewind to position at the point we returned. */
- resultoffset = resultoffset - 1;
- mysql_data_seek(results, resultoffset);
resp = erl_format("{selected, ~w, ~w}", ecols, erows);
erl_free_term(erows);
}