From 0871101e0df1ae0f80fc2bdec88e1f0a320b6f01 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 28 Jul 2008 12:37:38 -0400 Subject: Shorten up the code a bit by stashing the tag_name. --- src/mysqlerl.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/mysqlerl.c b/src/mysqlerl.c index ff24b64..c757f22 100644 --- a/src/mysqlerl.c +++ b/src/mysqlerl.c @@ -12,6 +12,7 @@ #include #include +const char *CONNECT_MSG = "connect"; const char *QUERY_MSG = "sql_query"; const char *PARAM_QUERY_MSG = "sql_param_query"; const char *SELECT_COUNT_MSG = "sql_select_count"; @@ -423,33 +424,27 @@ void dispatch_db_cmd(MYSQL *dbh, ETERM *msg) { ETERM *tag; + char *tag_name; tag = erl_element(1, msg); - if (strncmp((char *)ERL_ATOM_PTR(tag), - QUERY_MSG, strlen(QUERY_MSG)) == 0) { + tag_name = (char *)ERL_ATOM_PTR(tag); + if (strncmp(tag_name, QUERY_MSG, strlen(QUERY_MSG)) == 0) handle_query(dbh, msg); - } else if (strncmp((char *)ERL_ATOM_PTR(tag), - PARAM_QUERY_MSG, strlen(PARAM_QUERY_MSG)) == 0) { + else if (strncmp(tag_name, PARAM_QUERY_MSG, strlen(PARAM_QUERY_MSG)) == 0) handle_param_query(dbh, msg); - } else if (strncmp((char *)ERL_ATOM_PTR(tag), - SELECT_COUNT_MSG, strlen(SELECT_COUNT_MSG)) == 0) { + else if (strncmp(tag_name, SELECT_COUNT_MSG, strlen(SELECT_COUNT_MSG)) == 0) handle_select_count(dbh, msg); - } else if (strncmp((char *)ERL_ATOM_PTR(tag), - SELECT_MSG, strlen(SELECT_MSG)) == 0) { + else if (strncmp(tag_name, SELECT_MSG, strlen(SELECT_MSG)) == 0) handle_select(dbh, msg); - } else if (strncmp((char *)ERL_ATOM_PTR(tag), - FIRST_MSG, strlen(FIRST_MSG)) == 0) { + else if (strncmp(tag_name, FIRST_MSG, strlen(FIRST_MSG)) == 0) handle_first(dbh, msg); - } else if (strncmp((char *)ERL_ATOM_PTR(tag), - LAST_MSG, strlen(LAST_MSG)) == 0) { + else if (strncmp(tag_name, LAST_MSG, strlen(LAST_MSG)) == 0) handle_last(dbh, msg); - } else if (strncmp((char *)ERL_ATOM_PTR(tag), - NEXT_MSG, strlen(NEXT_MSG)) == 0) { + else if (strncmp(tag_name, NEXT_MSG, strlen(NEXT_MSG)) == 0) handle_next(dbh, msg); - } else if (strncmp((char *)ERL_ATOM_PTR(tag), - PREV_MSG, strlen(PREV_MSG)) == 0) { + else if (strncmp(tag_name, PREV_MSG, strlen(PREV_MSG)) == 0) handle_prev(dbh, msg); - } else { + else { logmsg("WARNING: message type %s unknown.", (char *)ERL_ATOM_PTR(tag)); erl_free_term(tag); exit(3); -- cgit v1.2.3