I need symbolic names for MySQL query parameters because the query uses a really complex expression in its WHERE clause. Unfortunately, the C++ connector does not support named parameters. I had an idea to use two statements, one to set the variables and the other to use them, like below:
const char* req =
" SET @id=?, @from=?, @to=?;"
" SELECT ..., creation_date, ... "
" FROM ... "
" WHERE ... AND (@from is null OR @from is not null AND creation_date >= @from) AND (@to is null OR @to is not null AND creation_date <= @to)";
// in practice, the WHERE condition is even more complex than the above
std::unique_ptr<sql::PreparedStatement>stmt(con->prepareStatement(req));
....
but this does not work, the connector cannot execute multiple statements.
In addition, from what I read it is not clear if the variables will still exist after the first statement is complete.
How can I use symbolic names in a query?