⬆️ ⬇️

Interesting behavior lib_mysqludf_preg

There is a third-party library for MySQL that allows you to use PCRE in this very MySQL. It is located here at this address mysqludf.com/lib_mysqludf_preg



I will not describe its functions, I’ll dwell only on one interesting point that made me spend about 30 minutes searching for problems.



We will omit a certain project that makes samples from the base using PREG_CAPTURE, where the regular expression is the value in the base column, and the string to be checked is a certain string to be inserted into the query.

')

Total query looks like this:



SELECT something FROM table1 WHERE NOT ISNULL (CONCAT ('/', `field1`, '/'), 'somemystring')



It works fine, gives data or does not issue. Until that moment, a syntactically incorrect and non-compiled regular expression does not appear in one of the field1 values.



An example of such an expression: * something_regexp



Then the PREG_CAPTURE function does not produce any errors, it simply does not return anything in response, as if there were no matches at all for all values ​​of regular expressions, and not only for incorrect ones.



Perhaps the developer of the library and conceived her work, but it causes certain problems. Just be careful.

Source: https://habr.com/ru/post/66173/



All Articles