aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-03-02 00:15:52 -0500
committerBrian Cully <bjc@kublai.com>2008-03-02 00:15:52 -0500
commit10d9f2e0a27438361fdc30a3bb853d71d5266671 (patch)
tree2efdbddabe42c28c2801b58ffa42d619cc3f6b1d /src
parentd86216b6176ce1587584cb988bf73e6825ad3bb8 (diff)
downloadmysqlerl-10d9f2e0a27438361fdc30a3bb853d71d5266671.tar.gz
mysqlerl-10d9f2e0a27438361fdc30a3bb853d71d5266671.zip
fix i/j screwup and get descs working.
Diffstat (limited to 'src')
-rw-r--r--src/mysqlerl.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c
index b1729f6..686d72f 100644
--- a/src/mysqlerl.c
+++ b/src/mysqlerl.c
@@ -199,22 +199,29 @@ handle_sql_query(MYSQL *dbh, ETERM *cmd)
cols = (ETERM **)malloc(num_fields * sizeof(ETERM *));
for (i = 0; i < num_fields; i++) {
logmsg("DEBUG: cols[%d]: %s", i, fields[i].name);
- cols[i] = erl_format("~s", fields[i].name);
+ cols[i] = erl_mk_string(fields[i].name);
}
ecols = erl_mk_list(cols, num_fields);
num_rows = mysql_num_rows(result);
rows = (ETERM **)malloc(num_rows * sizeof(ETERM *));
for (i = 0; i < num_rows; i++) {
- MYSQL_ROW row;
ETERM **rowtup, *rt;
+ unsigned long *lengths;
+ MYSQL_ROW row;
unsigned int j;
row = mysql_fetch_row(result);
+ lengths = mysql_fetch_lengths(result);
+
rowtup = (ETERM **)malloc(num_fields * sizeof(ETERM *));
for (j = 0; j < num_fields; j++) {
- logmsg("DEBUG: rows[%d][%d]: %s", i, j, row[j]);
- rowtup[j] = erl_format("~s", row[j]);
+ logmsg("DEBUG: rows[%d][%d] (%d): '%s'", i, j, lengths[j], row[j]);
+ if (row[j])
+ rowtup[j] = erl_mk_estring(row[j], lengths[j]);
+ else
+ rowtup[j] = erl_mk_atom("NULL");
+ logmsg("DEBUG: rowtup[%d]: %d", j, rowtup[j]);
}
logmsg("DEBUG: making tuple of %d", num_fields);
rt = erl_mk_tuple(rowtup, num_fields);
@@ -222,15 +229,19 @@ handle_sql_query(MYSQL *dbh, ETERM *cmd)
logmsg("ERROR: couldn't allocate %d-tuple", num_fields);
exit(3);
}
+ logmsg("DEBUG: copying rt");
rows[i] = erl_format("~w", rt);
+ logmsg("DEBUG: freeing row fields");
for (j = 0; j < num_fields; j++)
- erl_free_term(rowtup[i]);
+ erl_free_term(rowtup[j]);
free(rowtup);
erl_free_term(rt);
}
+ logmsg("DEBUG: making row list");
erows = erl_mk_list(rows, num_rows);
+ logmsg("DEBUG: preparing response");
resp = erl_format("{selected, ~w, ~w}",
ecols, erows);
@@ -253,6 +264,7 @@ handle_sql_query(MYSQL *dbh, ETERM *cmd)
}
erl_free(q);
+ logmsg("DEBUG: prepping buffers and sending.");
buflen = erl_term_len(resp);
buf = (char *)malloc(buflen);
erl_encode(resp, (unsigned char *)buf);