tosenzzz / trimpath

Automatically exported from code.google.com/p/trimpath
0 stars 0 forks source link

TrimQuery: LIKE is not true to SQL syntax #19

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The % and _ didn't work at all (except that TrimQuery would replace just
ONE % with .* in the regex), so I fixed it and added an RLIKE in case you
do want to use regular expressions (just remember to use two backslashes in
place of one for your special characters).

            var LIKE_regex = /(\S+)\sLIKE\s'(.+?)'/g;
            var specialChars = ['.', '(', ')', '*', '?', '+', '{', '}'];
            var matchArr;
            while(matchArr = LIKE_regex.exec(js)) {
                for (var i = 0, l = specialChars.length; i < l; i++)
                    matchArr[2] = matchArr[2].replace(specialChars[i], '\\' +
specialChars[i]);
                matchArr[2] = matchArr[2].replace(/%/g, '.*');
                matchArr[2] = matchArr[2].replace(/_/g, '.');
                js = js.replace(LIKE_regex, "$1.match(/^" + matchArr[2] + "$/)");
            }

            var RLIKE_regex = /(\S+)\sRLIKE\s'(.+?)'/g;
            while(matchArr = RLIKE_regex.exec(js)) {
                js = js.replace(RLIKE_regex, "$1.match(/" + matchArr[2] + "/)");
            }

Original issue reported on code.google.com by scottwk...@gmail.com on 22 Sep 2008 at 3:33

GoogleCodeExporter commented 8 years ago
Is this project dead?  I'm using it as the foundation of Nike Basketball's 
upcoming feature called The Family... 
Also, I added case insensitivity in there after the matches for both LIKE and 
RLIKE.  I'd like to discuss other 
possible changes if this project is still alive.

Original comment by scottwk...@gmail.com on 17 Oct 2008 at 3:23