From 2c799d15e608d3139bc94e4bf1156767b5e9e5a3 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sun, 2 Mar 2008 18:41:34 -0500 Subject: Get next working, at least until you hit the end of the records. --- src/mysqlerl.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/mysqlerl.c b/src/mysqlerl.c index 94e5640..ffac9fb 100644 --- a/src/mysqlerl.c +++ b/src/mysqlerl.c @@ -15,6 +15,7 @@ const char *QUERY_MSG = "sql_query"; const char *PARAM_QUERY_MSG = "sql_param_query"; const char *SELECT_COUNT_MSG = "sql_select_count"; +const char *NEXT_MSG = "sql_next"; MYSQL_RES *results = NULL; @@ -230,6 +231,34 @@ handle_select_count(MYSQL *dbh, ETERM *msg) erl_free_term(resp); } +void +handle_next(MYSQL *dbh, ETERM *msg) +{ + MYSQL_FIELD *fields; + ETERM *ecols, *erows, *resp; + unsigned int num_fields; + + logmsg("DEBUG: got next msg."); + if (results == NULL) { + logmsg("ERROR: got next message w/o cursor."); + exit(2); + } + + num_fields = mysql_num_fields(results); + 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); + + erl_free_term(ecols); + erl_free_term(erows); + + write_msg(resp); + erl_free_term(resp); +} + void dispatch_db_cmd(MYSQL *dbh, ETERM *msg) { @@ -245,6 +274,9 @@ dispatch_db_cmd(MYSQL *dbh, ETERM *msg) } else if (strncmp((char *)ERL_ATOM_PTR(tag), SELECT_COUNT_MSG, strlen(SELECT_COUNT_MSG)) == 0) { handle_select_count(dbh, msg); + } else if (strncmp((char *)ERL_ATOM_PTR(tag), + NEXT_MSG, strlen(NEXT_MSG)) == 0) { + handle_next(dbh, msg); } else { logmsg("WARNING: message type %s unknown.", (char *)ERL_ATOM_PTR(tag)); erl_free_term(tag); -- cgit v1.2.3