#306 db_mysql multiple issues in run_mysql_cmd wrapper

modules (454)

There seem to be a couple of issues hidden in `run_mysql_cmd` macro:

- if there is no connection, first `if` causes a fall through to checking `mysql_errno()`, which has the return value of the last command, while it assumes checking the (_cmd)'s return code

- the macro is used for both prepared statement and other commands, even though mysql_stmt_* commands report the code via mysql_stmt_errno(), not mysql_errno()

- comparing mysql_errno to error codes and then getting mysql_error when error code==0 seems like a stupid thing to do, unless it's a workaround for some libmysqlclient bug

- "disconect" should be spelled "disconnect" :)

- reported errors are not true in functions using the wrapper - for example re_init_statement reports `if (code<0) { LM_ERR("failed while mysql_stmt_prepare()\n"); ...` while it can fail on db_mysql_connect which also returns the result via the 'code' variable

- if the database disconnectts during mysql_stmt_reppare, statements are going to be reset (reset_all_statements()), the final value of code will be that of db_mysql_connect (probably 0) and ctx->stmt will not be initialised, but mysql_stmt_close() will be run on it, causing a crash

- probably some others I haven't noticed...

Proposed solution - kill the macro and rewrite it in a sane way - I tried fixing the separate problems, but it seems like there are too many issues with it.


<< < 1 2 (Page 2 of 2)
  • Hi Stan,

    Reviewed the fixes and look good - I uploaded your patches on trunk and 1.6

    Many thanks & Best regards,

    • status: open --> closed-fixed
<< < 1 2 (Page 2 of 2)