Click here to Skip to main content
11,805,035 members (66,323 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQLite
am trying to perform a search for this string
! @ # $ % ^ & * ( ) '

then i used the sql syntax
Select ID From Tasks Where task LIKE '[!] [@] [#] [$] [%] [^] [&] [*] [(] [)] ''%'

but i dont get any result, any help
Posted 15-Feb-13 1:33am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Probably you want:
SELECT ID FROM Tasks WHERE task LIKE '! @ # $ \% ^ & * ( ) ''%' ESCAPE '\'

"in the database, the data in the field is Today's Task"

Check again - I just created a SQLite DB, with a table Tasks and three entries:
ID(int) Task(nvarchar(50)
1	Hello
2	Today's Task
3	XX Today's Task XX
Then I hacked some C#:
string strCon = @"data source=D:\Temp\TestingSQLite.sldb";
SQLiteConnection con = new SQLiteConnection(strCon);
SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Tasks WHERE task LIKE '%Today''s Task%'", con);
DataTable dt = new DataTable();
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
And got two rows: 2, and 3.

Check your data!
Cool Smith at 15-Feb-13 8:07am
hello, so even in other text, i only need to escape the % wilcard. say for example i need to search for "these are some wildcars & ! !" without the quote
OriginalGriff at 15-Feb-13 8:25am
Yes - the only wildcards in SQLite LIKE comparisions are % and _ for "zero or more of any character" and "any single character" respectively, so they are the only ones you need to escape (except single quote, obviously!)
Cool Smith at 15-Feb-13 9:29am
thank you very much. so even if i do this '%@! @@ @# $ @% @^ @& @* @( @) ''%', it doesn't have any negative effects right
OriginalGriff at 15-Feb-13 9:34am
You might want to escape the "%" in the middle, but otherwise it's fine!
Cool Smith at 15-Feb-13 9:44am
thank you very much
OriginalGriff at 15-Feb-13 10:24am
You're welcome!
Marcus Kramer at 15-Feb-13 10:20am
Cool Smith at 15-Feb-13 11:43am
Hello I tried this statement
SELECT ID FROM Tasks WHERE task LIKE '%Today''s Task%'
and it failed to find the item, any idea what is wrong?
OriginalGriff at 15-Feb-13 12:08pm
Without looking at your data? No idea at all! :laugh:
Cool Smith at 15-Feb-13 12:10pm
in the database, the data in the field is Today's Task
OriginalGriff at 15-Feb-13 12:26pm
Answer updated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 305
1 Sergey Alexandrovich Kryukov 268
2 CPallini 210
3 Richard Deeming 190
4 CHill60 150
0 OriginalGriff 3,255
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100