diff options
author | Brian Cully <bjc@kublai.com> | 2012-02-09 17:07:44 -0500 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2012-02-09 17:07:44 -0500 |
commit | f408c9aa01105f1a9d0826144269a465c3185014 (patch) | |
tree | 036b3063919e7a535e4b2b002f0dc445b30ffc03 /c_src | |
parent | b2cb8bcbb9495b3c13741661624145700374b33e (diff) | |
download | mysqlerl-f408c9aa01105f1a9d0826144269a465c3185014.tar.gz mysqlerl-f408c9aa01105f1a9d0826144269a465c3185014.zip |
Fix crashes when there are no results in port driver.
Diffstat (limited to 'c_src')
-rw-r--r-- | c_src/mysqlerl.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/c_src/mysqlerl.c b/c_src/mysqlerl.c index 4be6be9..32fa36f 100644 --- a/c_src/mysqlerl.c +++ b/c_src/mysqlerl.c @@ -145,12 +145,16 @@ set_mysql_results(MYSQL_STMT *handle) mysql_stmt_close(sth); } sth = handle; + resultoffset = 0; /* Get result metadata. */ if (results) { mysql_free_result(results); } results = mysql_stmt_result_metadata(sth); + if (results == NULL) { + return; + } /* Buffer results. */ if (r_bind) { @@ -179,8 +183,6 @@ set_mysql_results(MYSQL_STMT *handle) mysql_stmt_bind_result(sth, r_bind); mysql_stmt_store_result(sth); - - resultoffset = 0; numrows = mysql_stmt_num_rows(sth); } @@ -364,11 +366,12 @@ handle_query(ETERM *cmd) if (results) { resp = handle_mysql_result(); } else { - if (mysql_num_fields(results) == 0) + if (mysql_stmt_field_count(handle) == 0) { resp = erl_format("{updated, ~i}", numrows); - else + } else { resp = erl_format("{error, {mysql_error, ~i, ~s}}", mysql_stmt_errno(handle), mysql_stmt_error(handle)); + } } } @@ -585,7 +588,7 @@ handle_param_query(ETERM *msg) if (results) { resp = handle_mysql_result(); } else { - if (mysql_num_fields(results) == 0) + if (mysql_stmt_field_count(handle) == 0) resp = erl_format("{updated, ~i}", numrows); else resp = erl_format("{error, {mysql_error, ~i, ~s}}", @@ -633,7 +636,7 @@ handle_select_count(ETERM *msg) set_mysql_results(handle); if (results) { resp = erl_format("{ok, ~i}", mysql_stmt_affected_rows(handle)); - } else if (mysql_num_fields(results) == 0) { + } else if (mysql_stmt_field_count(handle) == 0) { resp = erl_format("{ok, ~i}", mysql_stmt_affected_rows(handle)); } else { resp = erl_format("{error, {mysql_error, ~i, ~s}}", |