-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Subquery in query builder #5810
Comments
Thank you for taking time. First, I just want to ask you why do you use such a complex SQL statement with Query Builder? Next, your sample code is too long to see and understand. Please write minimum code to reproduce it. I think Query Builder does not work when you set such a complex SQL string in an argument and escaping on. The next minor version v4.2.0, Query Builder will have enhancement of Subqueries. |
Hi, I did suspect it was a lot.
We are using datatables on our site, and are using dynamic columns on them, so if the column is included, is passes a data element or table column name to a class function that then builds the datatable results. The only way I can see of doing the correspondences column is with a subquery as a contact can have more than one tel number / email address. I do admit it's quite an "extra" function, but it does provide the functionality our customers are looking for. I did look at the idea of writing it manually, but that does mean, writing one function for these complex tables along side the one we already have that builds the query based on what's in the datatable.
I suspected that might be the case. I will attempt to edit the queries down and will reply with some better examples of the error in time. That new sub query addition might be what I need. If the new update will allow that, I might be able to resolve my problem anyway. I will give it a go this coming week. Thanks for the helpful reply and I will write an update with new information shortly. |
Thank you for reply. I would like to ask you to:
And as you know, Query Builder can't handle complex SQL string. |
|
@SupremeSimon If i am wrong, reopen or create new issue, please. |
PHP Version
8.0
CodeIgniter4 Version
4.1.9
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MySQL 8.0.27
What happened?
The CI query breaks with a written subquery that contains a WHERE AND in it.
I have a query that needs to build from a base query and data from a datatable.
When the users search on the datatable, the search value gets passed into a function that adds the search value into a orLike query builder function.
In debugging I've just written this query manually and the same issue occurs.
I've only noticed it break when you add an AND to it. A single WHERE it doesn't have a problem with.
I have also found out that if you switch off the escape function, the query generates correctly. (Although in test this morning with the most basic query example I'm going to use in the reproduce step, it's actually not fixing it)
Steps to Reproduce
The full query I'm using is:
Without the and in the orLike function or with the escape set to false I get a working query:
If you set the escape to true and have the AND 1 = 1 in there, you get the following. (I'm using AND 1 = 1 as an example, There are many other AND's that I had in the actual query, I've just removed them for simplicity, the behavior is the same)
NOTE the ":" at the start and end of the LIKE statement and the lack of "%%". This query is broken now.
In tests done whist writing this. I broke down my query to its fundamentals. A sub query in a WHERE statement.
This query, regardless of if the escape is on or off, produces:
Again with the ":" at the start and end of the WHERE statement (In this case, just a WHERE, so this issues doesn't just relate to the orLike)
But removing the AND 1 = 1 or any additional WHERE statement will cause the query to generate correctly.
I hope this is enough info to reproduce.
Expected Output
I am expecting the query to generate correctly without the ":" characters getting added.
The query I'm writing should be valid even with it being a subquery in a where statement.
Anything else?
No response
The text was updated successfully, but these errors were encountered: