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
SQLSTATE[HY000]: General error: 3696 The regular expression contains an unclosed bracket expression. on line: 499 in /var/www/html/wire/core/WireDatabasePDO.php #1173
Comments
Very loosely related, posting here to provide context (https://bugs.mysql.com/bug.php?id=95347):
MySQL 8.0 docs (https://dev.mysql.com/doc/refman/8.0/en/regexp.html) state that...
Note: this might not be related at all. Engine change probably is, but not the latter part. In fact looking at the regexp above, it does look like a real issue. I mean — there is indeed one unclosed bracket there. @ryancramerdesign probably knows better, but looks to me like it's not doing exactly what it should, and if so (assuming that there's one extraneous bracket) escaping would fix the error, but also result in wrong behaviour. |
@teppokoivula @adrianbj Yes, it does look like there is an extra bracket there. I just tried removing it here, and am getting the same results as with it there, so it's a mystery why MySQL doesn't seem to care (except Adrian's version), or if it is there for some reason that I've forgotten, and needs to be escaped. Adrian, you mentioned that escaping the first bracket fixed the issue there, can you confirm that it does match 2-3 character words in a In my case (on MAMP) I get the same results whether using (Note as soon as you hit 4 characters it starts using a fulltext index rather than this regexp). |
Thanks @ryancramerdesign and @teppokoivula So I get the same results whether I escape the first Let me step back a bit. This is the code I have been using for a long time without problems (until MySQL update).
This is an ajax search which triggers as soon as there are 3 characters entered in an input to match a member's name (title). If I type
This used to work fine and match a member whose name was "Roger Brown", but now I get that unescaped bracket error and if I remove (or escape) that extra bracket, I don't get any results. However, if I do the same selector search with
which returns the correct result. Also, in case it's of interest, if I modify the regex version of the search to find
then it works and the member is found correctly. So to sum up, Does that help? |
The select query you had directly above the quoted text had zero brackets in it at all. So the error was not referring to that query. What I understand is triggering the error you are seeing is if using a Asking for a full word match
With your tests I'd stick to just Back to the
We aren't trying to match a literal bracket, we want it to interpret the bracket as a metacharacter to create a named character class, so unless I'm misreading it, no brackets should be escaped here. Here's an updated RLIKE expression to try if you get a chance:
|
Sorry, I pasted the wrong one - I have updated the post to show the correct one.
Well, it would, except we are getting that exception being thrown because this version of MySQL doesn't like the extra bracket. Here are some example tests / results: I also just tested:
and that deals with the error and also returns the correct matching members, so it looks like that is what is needed. Will you update the PW core with that change? |
Great! That one also works in prior versions so looks like that's the one
to use. I will update to that tomorrow. Thanks.
…On Tue, May 19, 2020, 3:57 PM Adrian Jones ***@***.***> wrote:
The select query you had directly above the quoted text had zero brackets
in it at all. So the error was not referring to that query.
Sorry, I pasted the wrong one - I have updated the post to show the
correct one.
We know that the ~=rog isn't working in your case, but since you said your
test did a fallback to a %=rog that one should have matched.
Well, it would, except we are getting that exception being thrown because
this version of MySQL doesn't like the extra bracket.
Here are some example tests / results:
[image: image]
<https://user-images.githubusercontent.com/871211/82371544-384be780-99cf-11ea-849a-f74e167d359f.png>
[image: image]
<https://user-images.githubusercontent.com/871211/82371607-531e5c00-99cf-11ea-800e-f271492ede3b.png>
[image: image]
<https://user-images.githubusercontent.com/871211/82371727-8660eb00-99cf-11ea-9ea6-44160934f917.png>
[image: image]
<https://user-images.githubusercontent.com/871211/82371755-92e54380-99cf-11ea-8222-a34105bd5972.png>
I also just tested:
$regex = "([[:blank:]]|[[:punct:]]|[[space]]|^)$v([[:blank:]]|[[:punct:]]|[[space]]|$)";
and that deals with the error and also returns the correct matching
members, so it looks like that is what is needed. Will you update the PW
core with that change?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1173 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQEUFGRHK2IM4OCYKKNDDRSLQBLANCNFSM4NCUAURA>
.
|
Thank you! |
@ryancramerdesign - just looking at the latest commits and of course, the original issue is fixed, but I did just notice that if you try:
you get this error: The query that is generated is:
Should the |
Thanks Adrian, I've pushed a fix. I ended up doing a pretty major
refactoring of all the Database classes and PageFinder this week, lots and
lots of changes, so there will likely be more of these. Please let me know
of any others you come across.
…On Fri, May 22, 2020 at 2:22 PM Adrian Jones ***@***.***> wrote:
@ryancramerdesign <https://github.com/ryancramerdesign> - just looking at
the latest commits and of course, the original issue is fixed, but I did
just notice that if you try:
$pages->find("name~=aaa");
you get this error:
Exception: SQLSTATE[HY000]: General error: 3685 Illegal argument to a
regular expression. on line: 499 in
/Users/ajones/Sites/ecoreportcard/wire/core/WireDatabasePDO.php
The query that is generated is:
SELECT pages.id,pages.parent_id,pages.templates_id
FROM `pages`
WHERE (pages.name RLIKE '[[:<:]]aaa[[:>:]]') AND (pages.status<1024)
GROUP BY pages.id
Should the ~ condition in a selector support the name field?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1173 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQEUHKNASTAFISSCQRJFTRS27FPANCNFSM4NCUAURA>
.
|
@ryancramerdesign - unfortunately that doesn't seem to help. The generated query is now:
and I am still getting the same error. |
Also, while you're in DB mode, any chance you could please take a look at: #1142 |
The query works here at least. And the generated query is what it should be
now. The problem before was that the regexp wasn't part of the bind params
when it should have been. Maybe this is a MySQL 8.x difference again? I
don't know, but I can't spot any errors with the query itself, unless MySQL
8 no longer supports this kind of regex?
…On Fri, May 22, 2020 at 3:02 PM Adrian Jones ***@***.***> wrote:
@ryancramerdesign <https://github.com/ryancramerdesign> - unfortunately
that doesn't seem to help. The generated query is now:
SELECT pages.id,pages.parent_id,pages.templates_id
FROM `pages`
WHERE (pages.name RLIKE :str)
AND (pages.status<:int)
GROUP BY pages.id
and I am still getting the same error.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1173 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQEUCEVABYF2UBRCLXTSLRS3D47ANCNFSM4NCUAURA>
.
|
This seems to explain the problem: |
A little OT, but it seems a shame to me that I can no longer see the exact query that is processed with the bound parameters replaced with the actual values. On the last dev version of PW, via Tracy's Debug Mode panel > Selector Queries I see:
but with today's DB refactoring, now all I see is:
which makes it harder to debug selectors. Any chance there is a way I can get the final query instead for Tracy? FYI - this is where I am collected selector queries for display in that panel: |
This seems to explain the problem:
https://stackoverflow.com/a/60906360/1524576
Thanks, yes that does explain it. So it looks like this is a case where
we'd have to do version detection, as it appears the pre 8.x MySQL versions
and 8.x are completely incompatible in this way. Luckily, I don't think we
need to use RLIKE boundaries elsewhere, except maybe in ProFields
Textareas. I'm just glad that this one isn't a result of 3.0.157 changes,
as there were tons of changes this week.
I understand it's harder to debug queries now that several things have been
converted to binds, but I think the benefits here definitely outweigh the
drawbacks. I was always a little unhappy about having to not use bind
values there, but just didn't know another way to keep those queries
portable in the way they needed to be, until recently. The tools provided
by Tracy were essential in making this update possible. I am also on a hunt
to find a way to have debug versions of queries that have the bind values
present in the query. It'll be possible since the DatabaseQuery class is
now keeping track of these (rather than just PDO). So it's already on the
map. I'll be working on this likely in 3.0.158. Is Tracy pulling these from
Database::queryLog() or somewhere else?
…On Fri, May 22, 2020 at 3:16 PM Adrian Jones ***@***.***> wrote:
This seems to explain the problem:
https://stackoverflow.com/a/60906360/1524576
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1173 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQEUH62OCVBAMWZ74HHIDRS3FQBANCNFSM4NCUAURA>
.
|
I completely understand the desire to use binds and glad to hear that you're keen to find a way to have debug versions that will show the values.
Great, glad to hear it was useful!
Just hooking into As noted above, you can see the code here: https://github.com/adrianbj/TracyDebugger/blob/48b4ea7b4565f03d566620550b1ea976accd0a15/TracyDebugger.module.php#L486-L489 PS - if you have any ideas for making this table better, please let me know. |
Okay thanks, I'll have a closer look and find a way to make the data
available. I was thinking I could populate into the query log somehow, but
if pulling from PageFinder getQuery() those bind keys need to remain there,
so may need to setup a specific method for this purpose.
…On Fri, May 22, 2020 at 4:00 PM Adrian Jones ***@***.***> wrote:
I completely understand the desire to use binds and glad to hear that
you're keen to find a way to have debug versions that will show the values.
The tools provided by Tracy were essential in making this update possible.
Great, glad to hear it was useful!
Is Tracy pulling these from Database::queryLog() or somewhere else?
Just hooking into PageFinder::getQuery. I don't think I can use queryLog
- IIRC there isn't a way to match selectors to SQL queries via that, which
is the key feature of the "Selector Queries" table.
As noted above, you can see the code here:
https://github.com/adrianbj/TracyDebugger/blob/48b4ea7b4565f03d566620550b1ea976accd0a15/TracyDebugger.module.php#L486-L489
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1173 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQEUDCKVHJ23WQRP5UJZ3RS3KUXANCNFSM4NCUAURA>
.
|
I am not sure about this - I think 5.x also supports This might be useful: https://www.codeproject.com/Articles/4421/Henry-Spencer-s-Regexp-Engine-Revisited and it references what is supported by the spencer regex library which is what was previously used by MySQL before 8 went to ICU regex. |
@adrianbj Prior to 8.x does support a I thought there's always a possibility the online info wasn't right, and
...with one of these below, which one works?
I'm guessing option B, based on the info in the link you sent. I'm going to try and get setup with MySQL 8 here so I can test this stuff here as well. |
Just wanted to let you know that I just released RockFinder3 (https://github.com/baumrock/RockFinder3). As you can see in the readme I rely on the plain SQL on several places. The less critical part is dumping SQL for debugging, but the more critical part is when I use SQL for joining data as sub-queries or for extending the basic features of plain databaseSelect queries. Take this example: $owners = $RockFinder3
->find("template=person")
->addColumns(['title', 'age', 'weight'])
->setName('owner');
$cats = $RockFinder3
->find("template=cat")
->addColumns(['title', 'owner'])
->join($owners)
->getSQL();
db($RockFinder3->getObject("
SELECT AVG(`owner:age`) FROM ($cats) AS tmp
")); This worked until the latest update using bind values:
This is how it used to work until the update: https://github.com/baumrock/RockFinder3#option-2-sql-string-modification This also breaks the whole Would be great to get some words on how/if/when I can expect an update that also works for my module. Thank you! PS: I'm using |
@adrianbj Version 3.0.158 does convert bind queries to value queries, just for the ones returned by $database->queryLog(). I checked and Tracy appears to be picking those up, so that's good. It's the PageFinder selector queries that it isn't, but there's a way to get them now. There's a new
@BernhardBaumrock I don't know what that could be, but if your module depends on queries not using bind values, then I don't think there would be a way around that. But I think it's more likely that that's not the case. The changes on this part continued this week, so give the latest version 3.0.158 a try and maybe it'll work with your module? Let me know if not. |
@ryancramerdesign - you can ignore my comment on the relevant commit for this. I see what to do now, but you have a bug in the |
After I add |
…eturns the query (string) with all bind variables populated into the SQL
@adrianbj Just fixed, thanks :) |
@ryancramerdesign thx, the update did also fix the breaking change for RockFinder3 - everything working again :) |
Short description of the issue
This error appears when using a selector like:
Optional: Suggestion for a possible fix
The generated SQL is:
To fix, you can escape the first square bracket so the query looks like:
Error happens on two different servers:
Server A
MySQL Server: 8.0.19
MySQL Client: mysqlnd 7.4.4
Server B:
MySQL Server: 8.0.20-0ubuntu0.20.04.1
MySQL Client: mysqlnd 7.4.3
This error didn't happen last year (this is a seasonal site) and I just recently did a full server software update which I am certain updated the version of MySQL, so I expect that is the problem but it will start breaking lots of sites I would expect.
The text was updated successfully, but these errors were encountered: