-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Setcontent with a LIKE at the beginning of the string doesn't match #2088
Comments
According to the MySQL documentation (at least in v8.0):
SELECT CAST(
JSON_UNQUOTE( JSON_EXTRACT(json_doc, path) )
AS type
); Which is another solution, but it looks like using JSON_VALUE is simpler (as JSON_EXTRACT can just be switched out for JSON_VALUE, instead of wrapping it in another function). |
Hi @andysh-uk , I have not tested in on my end, but I agree about the proposed solution. I do not think it will affect PostgreSQL, because we use its |
Hi @andysh-uk , don't wanna push you on this, just wondering if you think there's a good fix for this yet? :-) |
Hi @I-Valchev, honestly no I haven't. My concern with introducing Do you know if Also the clause would need to be split to separate MySQL as Sqlite doesn't support |
@andysh-uk afaik, the
Ideally, we'd figure out a fix that works for all DMBSes, or at least MySQL and Sqlite 🤔 |
Ah OK, that may be easier then. I'll give it a try over the weekend. It was just that both JSON_GET_TEXT and JSON_EXTRACT have handlers in
Yeah that'd be ideal, it's hard when different DBMSes do things differently! I'm not too familiar with SQLite, but reading this page:
So it sounds like SQLite already returns |
I've just given this a try, and it looks like this is returning DQL, as the code now fails with the following error:
So I'm at a bit of an impass. I can change the function name used in Doctrine/Functions/JsonExtract to The right thing is to keep the change I've made in |
hi @andysh-uk, in the last few weeks @bobdenotter has worked a lot on a new Does that help with your solution here? |
Hi @I-Valchev, Apologies I've been away from Bolt for a bit, but I've come back to the original project where this issue. It is still an issue in 5.1, so I'm re-visiting this. I've got the changes ready, but I just need to understand how to make the relevant changes in |
There's not much docs on this, unfortunately.. But, if you take a look at (for example) https://github.com/bolt/core/blob/master/yaml-migrations/m_2021-09-16-doctrine.yaml, it might make it a bit more clear. So, I think in this case, it should be something like # Adding JSON_VALUE, see https://github.com/bolt/core/pull/3135
file: packages/doctrine.yaml
since: 5.1.6
add:
doctrine:
orm:
dql:
string_functions:
JSON_VALUE: Bolt\Doctrine\Functions\JsonValue |
…earlier versions of MySQL)
I'm using the equivalent of a setcontent tag in some controller code to match all content records that start with a given letter.
However this doesn't work - it always returns 0 records.
I've narrowed this down in the following code and query:
A content with the title field set to "A Great Big World" does not match in the above query.
If I run JSON_EXTRACT manually in MariaDB, it includes the quotes in the JSON, so the above string begins with
"A
notA
as the LIKE statement is expecting.Including the " in the code does indeed return the record I was expecting:
I believe the solution is to use
JSON_VALUE
instead ofJSON_EXTRACT
- and I'm happy to send a PR, I'm just unsure if this is the right solution (will this break anything elsewhere in Bolt/MySQL?) and also the impact on PostgreSQL - @I-Valchev ?The text was updated successfully, but these errors were encountered: