Sorting custom queries

I am using a custom query and generating a table and enabling SORT and DIR, the ordering arrows of the various fields are present but do not work
Perhaps with custom queries it is not an automatic process and it is necessary to create sorting parameters
What should I do?

This thread might help.

Thanks TomD, I had already read, but what I’m looking for is how to create possible parameters for sorting the fields
I don’t know if it is necessary to create parameters for each field and especially how they go in the query (Where …)

I haven’t used custom queries much. I would have thought you should be able to send a URL parameter or set a variable and use it in a custom query - eg in place of :P2 here:
… but it doesn’t seem to work. I tried with a variable, but it’s ignored and the same value is used for :P1 and for :P2. This looks like a bug.

The possibility of creating customized queries in Wappler is undoubtedly an important thing, but the use of the parameters is a bit nebulous and not easy to understand,
Perhaps a brief tutorial would be needed to understand how to orient yourself and avoid mistakes
Theoretically, to set the filters it should be enough to insert the Get variable and report in the WHERE field LIKE: P1 query, but I have not yet verified if it works well
On the other hand, the order of the various fields is somewhat more complicated

Using dynamic values seems to work fine - for sorting too - but as long as only one variable is used. Eg I can use :P1 after WHERE or ORDER BY, and the expected value appears in the query. However if I use two variables :P1 and :P2, the same value appears for both variables.

This seems like a rather obvious bug, so I may be doing some wrong. In any case, you can start with some straightforward tests using variables with static values and see how custom queries work in principal.

It seems to me that something is wrong

Yes, this is the same issue as I mentioned: the custom query is using the same value for both of the dynamic parts of the query. This certainly looks like a bug - unless we’re both doing something wrong. I don’t remember coming across this issue when I experimented with custom queries when the feature was added.

Hopefully someone more familiar with custom queries can enlighten us or confirm it’s a bug.

Opening the custom query in the activated editor, I noticed that the parameters are positioned after the Select. Perhaps the problem is here
It seems to me that in normal Query actions the parameters are placed first

I’m not quite sure what you mean but it doesn’t look as if you’ve done anything wrong, based on your screenshot. It doesn’t look like there could be a good reason why your :P2 value seems to be ignored when the query is executed.

The problem seems to be in the query syntax

In this case, yes - you’re FROM clause is in the wrong place. This isn’t the same issue.

It’s a real sorry

I tried them all, logical and illogical, but it doesn’t work

Looking at other topics, using custom queries with multiple parameters doesn’t seem to be a problem so I don’t know why there is a problem in this case.

I notice this thread has been assigned to @patrick, so perhaps he will have a solution or explanation.

I did some tests with multiple parameters in custom queries, didn’t have any problems. Dynamic sorting is not possible with custom queries, ORDER BY :Sort will not work. Parameters can only be used for variables in the query, not for keywords like a table name.

Thank you very much Patrick
The problem is that non-customized Queries do not allow additional instructions LIKE - GROUP BY - LIMIT - etc …
And Custom Queries don’t allow other instructions
In this way it is not possible in some cases to conveniently structure a Query that works very well with phpMyAdmin.
I’m trying to work around a project in progress with the use of Views created with phpMyAdmin, but unfortunately I found errors in using Wappler that I solved by talking to the hosting.
To fix -> increased the cache to the limit of availability and now it works
The fact remains that in my opinion a program like Wappler should allow more possibilities for configuring Queries

Views are indeed a nice solution for such cases Marzio. Not sure what problems did you mention, using views … but many of our users are using views already and there are no any Wappler related issues with them.

it is not my intention to create controversy, but Wappler should allow to be able to configure the queries without having to resort to the View. Also because domains are often positioned on shared Hosts that do not allow an adequate increase in the cache.
And consequently the View reports errors, such as "SQLSTATE [HY000]: General error: 1615
Furthermore, the problem previously reported by me and TomD does not seem to have been solved yet
All this, with a spirit of collaboration to improve a good program like Wappler