aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-03-02 19:14:40 -0500
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-03-02 19:14:40 -0500
commitc1c1f7c51a1d3d45728c36134e434be443361019 (patch)
tree2a9949005a61ca5329949c74e1ea3b5f95fe8b1b
parentdac98c3702d03b417ae1c87c3299213fd8d21e71 (diff)
downloadmysqlerl-c1c1f7c51a1d3d45728c36134e434be443361019.tar.gz
mysqlerl-c1c1f7c51a1d3d45728c36134e434be443361019.zip
Add last support.
-rw-r--r--src/mysqlerl.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c
index b9c8d06..3421394 100644
--- a/src/mysqlerl.c
+++ b/src/mysqlerl.c
@@ -250,10 +250,38 @@ handle_first(MYSQL *dbh, ETERM *msg)
exit(2);
}
- num_fields = mysql_num_fields(results);
- fields = mysql_fetch_fields(results);
- mysql_data_seek(results, 0);
+ num_fields = mysql_num_fields(results);
+ fields = mysql_fetch_fields(results);
resultoffset = 0;
+ mysql_data_seek(results, resultoffset);
+
+ ecols = make_cols(fields, num_fields);
+ erows = make_rows(1, num_fields);
+ resp = erl_format("{selected, ~w, ~w}", ecols, erows);
+ erl_free_term(erows);
+
+ erl_free_term(ecols);
+ write_msg(resp);
+ erl_free_term(resp);
+}
+
+void
+handle_last(MYSQL *dbh, ETERM *msg)
+{
+ MYSQL_FIELD *fields;
+ ETERM *ecols, *erows, *resp;
+ unsigned int num_fields;
+
+ logmsg("DEBUG: got last msg.");
+ if (results == NULL) {
+ logmsg("ERROR: got last message w/o cursor.");
+ exit(2);
+ }
+
+ num_fields = mysql_num_fields(results);
+ fields = mysql_fetch_fields(results);
+ resultoffset = numrows - 1;
+ mysql_data_seek(results, resultoffset);
ecols = make_cols(fields, num_fields);
erows = make_rows(1, num_fields);
@@ -315,6 +343,9 @@ dispatch_db_cmd(MYSQL *dbh, ETERM *msg)
FIRST_MSG, strlen(FIRST_MSG)) == 0) {
handle_first(dbh, msg);
} else if (strncmp((char *)ERL_ATOM_PTR(tag),
+ LAST_MSG, strlen(LAST_MSG)) == 0) {
+ handle_last(dbh, msg);
+ } else if (strncmp((char *)ERL_ATOM_PTR(tag),
NEXT_MSG, strlen(NEXT_MSG)) == 0) {
handle_next(dbh, msg);
} else {