From c1c1f7c51a1d3d45728c36134e434be443361019 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sun, 2 Mar 2008 19:14:40 -0500 Subject: Add last support. --- src/mysqlerl.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src') 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); @@ -314,6 +342,9 @@ dispatch_db_cmd(MYSQL *dbh, ETERM *msg) } else if (strncmp((char *)ERL_ATOM_PTR(tag), 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); -- cgit v1.2.3