#107 Unable to use alias_db_lookup() with two different tables

modules (454)
Thomas Gelf

Writing a script like

> alias_db_lookup('dbaliases');
> alias_db_lookup('othertable');

doesn't work, OpenSIPS is reusing the very same prepared statement and executes all queries on the first DB ('dbaliases') in this case.

Summary of todays tests on IRC:

> I have MySQL query log enabled, there is only the first query
> (the first alias_db_lookup) arriving. If I comment out the first
> one, the second one is working correctly. If I switch their order
> in the script, the other one succeeds. So I think we can exclude
> script, param and MySQL errors.
> I did:
> > if (alias_db_lookup('tbl1')) { xlog(...) } else { xlog(...) }
> > if (alias_db_lookup('tbl2')) { xlog(...) } else { xlog(...) }
> xlog proves that both alias_db_lookup commands are executed each
> time.
> It seems that it is running both queries, but on the second call
> it is using the same table name as on the first one. Could this
> be related to the prepared statements? Yeah, it IS running one
> Prepare and two Executes. And the second Execute get's as param
> the (already aliased) ruri, but table remains the same. If it
> doesn't find the alias it is just running the same query twice.

> Other way to prove it: just call alias_db_lookup() twice - if you
> write a wrong table name in the first call, you get:
> > ERROR:db_mysql:get_new_stmt_ctx: failed while mysql_stmt_prepare
> If you use a wrong table name with the second call
> > alias_db_lookup('no_such_table'))
> nothing happens.

Best regards,
Thomas Gelf


    • labels: --> modules
    • milestone: --> trunk
    • assigned_to: nobody --> bogdan_iancu
    • status: open --> open-accepted
    • status: open-accepted --> closed-fixed
  • Fixes, it was a copy'n'paste error.

    Thanks for report,