bltoolkit icon indicating copy to clipboard operation
bltoolkit copied to clipboard

SQLite like operator doesn't work with special symbols

Open dvladimirovich opened this issue 8 years ago • 8 comments

I have an app which works with SQLite as data store. There is an issue when I'm using context search. If I use simple phrases BLToolkit converts it in LIKE '%<search string>%' and everything works fine. But I want to use special characters as _ to have an ability do search if I've forgotten what char must be here (e.g. when name is written in different languages). And when I print string like: _ванов in my search field BLToolkit generates next query: LastQuery.txt And it uses ESCAPE~ for _ symbol. As a result it can't find anything... How could I resolve this problem?

dvladimirovich avatar May 31 '17 09:05 dvladimirovich

This by design, by default string.Contains() escapes special symbols, use Sql.Like() extension, it should not escape

ili avatar May 31 '17 16:05 ili

There is a little problem. I'm using layered approach in my app, so UI layer knows nothing about others... And I pass Expression tree predicate not simple sql

dvladimirovich avatar May 31 '17 19:05 dvladimirovich

Is there some flag to turn off escaping? Or could you give me some advice on how to resolve this problem?

dvladimirovich avatar Jun 01 '17 10:06 dvladimirovich

@dvladimirovich heh... really have no other idea :(

ili avatar Jun 03 '17 06:06 ili

You could rewrite your Expression Tree befor handing over to linq2db. And replace every contains with Sql.like

jogibear9988 avatar Jun 03 '17 07:06 jogibear9988

Oh, I see...I suspected that I would have to do just that. And I did not want to do this, but I had to...

dvladimirovich avatar Jun 03 '17 16:06 dvladimirovich

i think with expressionvisitor it should not be a big task, see https://stackoverflow.com/questions/17728188/rewrite-expression-to-replace-list-contains-with-custom-method

jogibear9988 avatar Jun 03 '17 16:06 jogibear9988

Yeah, I've already had such experience in rewriting Expression trees using expression visitor=)

dvladimirovich avatar Jun 03 '17 16:06 dvladimirovich