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
Use Regex in Query #698
Comments
If by support you mean handling of RegEx class usage in linq queries, then no. |
I'll look if this is possible to implement... |
It's just another extension. PR will be appreciated. |
for example [Sql.Expression(ProviderName.MySql, "{0} REGEXP {1}")]
public static bool RegExp(string regex, string data)
{
throw new NotImplementedException();
}
db.GetTable<Person>().Where(_ => RegExp("bla-bla-bla", _.Name)).ToList() the only thing it would be sensitive to database RegEx dialect. To make honest support it would be needed to create extension and convert c# RegEx to DB RegEx. If somebody knows how to convert one RegEx dialect to other it would be easy to implement support like: public static class Sql
{
public static class Regex
{
public static bool Match(Regex regex, string data) => regex.IsMatch(data);
}
}
db.GetTable<Person>().Where(_ => Sql.Regex.Match(new Regex("bla-bla-bla"), _.Name)).ToList(); |
pull #1077 |
Is it also possible to support this:
it means use the .NET Regex Class. Where can I look to implement this? |
It is possible. But, how different regexp syntax in other databases? If dialects are too different - i prefer do not introduce Regex.IsMatch replacement. |
Don't know how different they are. But I think most should be the same (if it is supported). Where do I have to look to implement smth. like this? |
We have to be sure that syntax is not different. We supports more than 10 databases and it will introduce undefined behavior for others. If you want to replace |
ef core also supports it: https://blogs.msdn.microsoft.com/mvpawardprogram/2016/11/22/entity-framework-core/ |
Link is about third party npgsql EF Provider - only Postgre SQL. |
Of course regular expression syntax can have subtle differences in every engine, even in different versions of the same engine. Only some basic regular expressions, using the common subset of features may work. It's just like the SQL language itself. It's pretty much standardized, but only to a limited degree. Here are my findings:
So, having a truly portable regular expressions in LINQ to DB is a hard task. I think implementing a simple generic wrappers is doable, but it's going to be a supportability nightmare. Users will have hard time understanding why are there error messages returned by SQL Server when their perfect LINQ to DB should just run. |
My take on this: (1) I don't see why someone would attempt to create an abstraction layer to unify all regexps flavors:
(2) On the other hand, just like all other provider-specific SQL extensions linq2db exposes, I see value in using these functions even when they're not portable. I see linq2db more as "full access to RDMBS power" than a "minimal common layer between all RDBMS". In fact, even basic operations can't be bridged between providers, did you know that Bottom line: I think adding those as some kind of provider-specific |
But atm. I do not work on this (okay the issue is already 5 years old :-) ) |
fixed in #4392 |
don't close until the PR is merged. |
/azp run test-all |
Something new to add to the discussion of: "should we simply use Now VS IDE is attempting to provide colorization and intellisense for known string DSLs, including regexes. I think it would be even more confusing to get pattern tooltips and completions that are incorrect in this instance. |
Do we support Regex in Linq (converted to sql)?
mysql:
https://stackoverflow.com/questions/18780194/how-to-regex-in-a-sql-query
sqlite:
https://stackoverflow.com/questions/5071601/how-do-i-use-regex-in-a-sqlite-query
postgres:
https://www.postgresql.org/docs/9.0/static/functions-matching.html
oracle:
https://docs.oracle.com/cd/B12037_01/appdev.101/b10795/adfns_re.htm
sap hana:
http://help-legacy.sap.com/saphelp_hanaplatform/helpdata/en/b4/0d483dd34d47aa9cc89b4d8a6e617e/content.htm?frameset=/en/dc/f1045ce51d45119cfe8ba17cf9da4f/frameset.htm¤t_toc=/en/2e/1ef8b4f4554739959886e55d4c127b/plain.htm&node_id=113
mssql:
http://devnambi.com/2016/sql-server-regex/
The text was updated successfully, but these errors were encountered: