aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mysqlerl.c20
-rw-r--r--src/mysqlerl_connection.erl2
2 files changed, 15 insertions, 7 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c
index b5ad31c..0ce2703 100644
--- a/src/mysqlerl.c
+++ b/src/mysqlerl.c
@@ -159,11 +159,9 @@ write_cmd(const char *cmd, msglen_t len)
{
msglen_t nlen;
- nlen = htonl(len + 3);
+ nlen = htonl(len);
if (restartable_write((unsigned char *)&nlen, sizeof(nlen)) == -1)
return -1;
- if (restartable_write((unsigned char *)" - ", 3) == -1)
- return -1;
if (restartable_write((unsigned char *)cmd, len) == -1)
return -1;
@@ -177,15 +175,25 @@ dispatch_db_cmd(MYSQL *dbh, msg_t *msg)
tag = erl_element(1, msg->cmd);
if (strncmp((char *)ERL_ATOM_PTR(tag), QUERY_MSG, sizeof(QUERY_MSG)) == 0) {
- ETERM *query;
- char *q;
+ ETERM *query, *resp;
+ char *q, *buf;
+ int buflen;
+
query = erl_element(2, msg->cmd);
q = erl_iolist_to_string(query);
erl_free_term(query);
logmsg("DEBUG: got query msg: %s.", q);
- write_cmd(q, strlen(q));
+ resp = erl_format("{ok, ~s}", q);
erl_free(q);
+
+ buflen = erl_term_len(resp);
+ buf = (char *)malloc(buflen);
+ erl_encode(resp, (unsigned char *)buf);
+ erl_free_term(resp);
+
+ write_cmd(buf, buflen);
+ free(buf);
} else {
logmsg("WARNING: message type %s unknown.", (char *)ERL_ATOM_PTR(tag));
erl_free_term(tag);
diff --git a/src/mysqlerl_connection.erl b/src/mysqlerl_connection.erl
index fb0479c..53ac85f 100644
--- a/src/mysqlerl_connection.erl
+++ b/src/mysqlerl_connection.erl
@@ -76,7 +76,7 @@ handle_query(Ref, Query) ->
make_request(Ref, Req) ->
port_command(Ref, term_to_binary(Req)),
receive
- {Ref, {data, Res}} -> {ok, Res};
+ {Ref, {data, Res}} -> binary_to_term(Res);
Other ->
error_logger:warning_msg("Got unknown query response: ~p~n",
[Other]),