projectnami icon indicating copy to clipboard operation
projectnami copied to clipboard

FIND_IN_SET to PATINDEX translation missing %s

Open rmc47 opened this issue 6 years ago • 2 comments

At the moment, the FIND_IN_SET translation (used by bbPress's topic subscription notifications) turns into PATINDEX: https://github.com/ProjectNami/projectnami/blob/master/wp-includes/translations.php#L1151

However, the pattern argument isn't surrounded by %s, which https://docs.microsoft.com/en-us/sql/t-sql/functions/patindex-transact-sql suggests it must be, so returns no results:

SELECT PATINDEX(',456,',',123,456,789,')
-- returns 0

SELECT PATINDEX('%,456,%',',123,456,789,')
-- returns 5

I'll submit a PR to fix this, but @LitKnd pointed out that since SQL 2016, there's the rather nice STRING_SPLIT function which might offer a neater solution. What's your feeling on how many folks would be hit by upping the current SQL 2012 requirement?

rmc47 avatar Mar 28 '19 11:03 rmc47

To answer your question regarding SQL 2016 commands https://projectnami.org/sql-edition-usage-stats-for-2018/

Looks like 23.5% of installations run on a version below 2016.

Perhaps a version check to switch between the two solutions?

We're not opposed to using newer commands in certain use cases. For example, there is no way to translate a GROUP_CONCAT until SQL 2017 and STRING_AGG. Sooner or later we will need to implement it for a number of plugins out there.

patrickebates avatar Apr 05 '19 03:04 patrickebates

Thanks for digging into it. I wouldn't worry about STRING_SPLIT for now - Kendra did some benchmarking, and performance seemed indistinguishable from PATINDEX.

rmc47 avatar Apr 05 '19 06:04 rmc47