-
Notifications
You must be signed in to change notification settings - Fork 664
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
Searching like with bracket (, ) , [, ] #385
Comments
I am not sure we can fix it before Monday. You can use indexOf() function to perform this search:
|
Thank you for a well described issue. The We must fix this - I have a feeling it must be in the same files as edited for this commit: efc33e6 Now - the alasql("SELECT * FROM ? WHERE compDisplay like '%[1535]%' ",[compListTest]); you will get all results back as its searching for any string that contains 1, 5, or 3 or (and all the example data fulfills this) A workaround for both issues would be to escape the Here is a working version of your example while we prepare a release that fixes the issues var compListTest = [
{"compDisplay" : "MGT. LTD.-SUNSHINE (N-R) [1535]"},
{"compDisplay" : "INVESTMENT LIMITED/ [JC01]"},
{"compDisplay" : "(METRO C. III) [2823]"}
];
// Problem 1: searching with ( or )
found=alasql("SELECT * FROM ? WHERE compDisplay like '%III\\\\) \\\\[2823\\\\]%' ",[compListTest]);
console.log(JSON.stringify(found))
// [{"compDisplay":"(METRO C. III) [2823]"}]
// Problem 2: searching with [ ]
found=alasql("SELECT * FROM ? WHERE compDisplay like '%\\\\[1535\\\\]%' ",[compListTest]);
// should be MGT. LTD.-SUNSHINE (N-R) [1535]
console.log(JSON.stringify(found))
//[{"compDisplay":"MGT. LTD.-SUNSHINE (N-R) [1535]"}] |
@mathiasrw We can do more strong version of LIKE (with only % and .) and include RegEx as special type. What do you think? |
@agershun I think its important that |
Thanks yours for prompt reply. I can use it from my solution first. |
Ok. We will reduce to this specification: See:
Lately we can extend it with |
Sounds great !
we must remember to escape chars in |
I found the SQL LIKE JavaScript function in SO, but is should be checked how it works before implementing into AlaSQL: alasql.utils.like = function (pattern,value) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
var re = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return pattern.replace(re, '\\$1').replace("%", ".*").replace("_", ".").match(value);
} Now AlaSQL uses LIKE function in many statement |
Looks as a good start. Inputs for emprovements:
Future:
|
@mathiasrw Thank you for detail analysis! Hope... I can do it )) |
:) |
Just updated AlaSQL. Now LIKE works like in other SQL dialects. Now it properly supports: SELECT "abcdef" LIKE "%bc%"
SELECT "abcdef" LIKE "_bc%"
SELECT "abcdef" LIKE "[aq]bc%"
SELECT "abcdef" LIKE "[^qw]bc%"
SELECT "(abcdef)" LIKE "(%)"
SELECT '[abc]' LIKE '![%!]' ESCAPE '!' I m,odified test366 where replaced '?' to '_' and added ESCAPE clause to skipped tests. Unfortunately, this relization is 'slow', because I wrote own parser and didnot use Regular Expressions to convert SQL search pattern to JS one. As the next step we need to realize REGEXP operator and REGEXP_LIKE() function. |
Woooohooooo!!! Lets make it work before we optimise :) |
I think we can cache (memoize) patterns for this LIKE. In the future, not now )) |
Good idea ! |
Closed per request from #628 |
Like pattern cache was added in #1822. |
I want to search following json by asql and the following problem found.
How can I change text to solve it.
Thanks!
The text was updated successfully, but these errors were encountered: