Dbo: crash when sort QueryModel for query, including orderBy with bound values
Pseudocode bellow is what I am trying to do.
Query query; ... query.orderBy("id = ? desc").bind(special_object); QueryModel model; model.setQuery(query); model.sort(another column); // crash "ERROR: bind message supplies X parameters, but prepared statement "..." requires X-1
I think, if some part of query (for example, "orderBy") is replaced (or removed), then parameters bound to that part should be replaced (or removed) as well.
Updated by Koen Deforche almost 10 years ago
- Status changed from New to Feedback
I'm not sure that will work in general (Wt Dbo does not attempt to parse queries to that level of understanding).
In this case, you should choose to let the query model handle the sorting, and remove it from the original query.
Updated by Boris Nagaev almost 10 years ago
Wt Dbo can memorize a 'parent' of each bound value. This would be particular WHERE or ORDER BY clause. This can be implemented, since order of bind's must be the same as order of corresponding .orderBy(), .where(), etc. When query model sorts the query, these bound values will be discarded as well as original ORDER BY (their parent).
For my particular case I have a workaround. This ticket was created to make behaviour of Wt::Dbo more predictable.
Updated by Koen Deforche over 9 years ago
I think that I understand what you aim after: orderBy(...).bind(x) would tie 'x' to the orderBy() clause.
However, this is currently not an implied relation: .bind(x) can be called at any time in the query, before or after the orderBy() clause, including at the very end...
I do understand the possibility now, but I am not sure whether we should implement it (as it does complicate things).