aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-07-28 12:37:38 -0400
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-07-28 14:44:18 -0400
commit0871101e0df1ae0f80fc2bdec88e1f0a320b6f01 (patch)
treeccdec4e37ccabef2ea7bafbd1f89887471d0ace6 /src
parent887ab7a574ea437a8c42b0dfd6537015214f94d6 (diff)
downloadmysqlerl-0871101e0df1ae0f80fc2bdec88e1f0a320b6f01.tar.gz
mysqlerl-0871101e0df1ae0f80fc2bdec88e1f0a320b6f01.zip
Shorten up the code a bit by stashing the tag_name.
Diffstat (limited to 'src')
-rw-r--r--src/mysqlerl.c29
1 files 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 <mysql.h>
#include <string.h>
+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);