diff options
author | Brian Cully <bjc@kublai.com> | 2008-03-02 19:19:10 -0500 |
---|---|---|
committer | Brian Cully <github.20.shmit@spamgourmet.com> | 2008-03-02 19:19:10 -0500 |
commit | 9747eac3e62a5dc1219d4c9982e84935ae35eb4d (patch) | |
tree | 3dcfa011d810dcecb2d7b8c886c08011fdaff6dc /src | |
parent | c1c1f7c51a1d3d45728c36134e434be443361019 (diff) | |
download | mysqlerl-9747eac3e62a5dc1219d4c9982e84935ae35eb4d.tar.gz mysqlerl-9747eac3e62a5dc1219d4c9982e84935ae35eb4d.zip |
Get previous cursor working.
Diffstat (limited to 'src')
-rw-r--r-- | src/mysqlerl.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c index 3421394..d3eea18 100644 --- a/src/mysqlerl.c +++ b/src/mysqlerl.c @@ -325,6 +325,43 @@ handle_next(MYSQL *dbh, ETERM *msg) } void +handle_prev(MYSQL *dbh, ETERM *msg) +{ + MYSQL_FIELD *fields; + ETERM *ecols, *erows, *resp; + unsigned int num_fields; + + logmsg("DEBUG: got prev msg."); + if (results == NULL) { + logmsg("ERROR: got prev message w/o cursor."); + exit(2); + } + + num_fields = mysql_num_fields(results); + fields = mysql_fetch_fields(results); + + ecols = make_cols(fields, num_fields); + logmsg("resultoffset: %d, num_rows: %d", resultoffset, numrows); + if (resultoffset == 0) { + resp = erl_format("{selected, ~w, []}", ecols); + } else { + resultoffset = resultoffset - 1; + mysql_data_seek(results, resultoffset); + 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); + } + + erl_free_term(ecols); + write_msg(resp); + erl_free_term(resp); +} + +void dispatch_db_cmd(MYSQL *dbh, ETERM *msg) { ETERM *tag; @@ -348,6 +385,9 @@ dispatch_db_cmd(MYSQL *dbh, ETERM *msg) } else if (strncmp((char *)ERL_ATOM_PTR(tag), NEXT_MSG, strlen(NEXT_MSG)) == 0) { handle_next(dbh, msg); + } else if (strncmp((char *)ERL_ATOM_PTR(tag), + PREV_MSG, strlen(PREV_MSG)) == 0) { + handle_prev(dbh, msg); } else { logmsg("WARNING: message type %s unknown.", (char *)ERL_ATOM_PTR(tag)); erl_free_term(tag); |