Click here to Skip to main content
12,070,351 members (44,426 online)
Rate this:
 
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 2:33am

1 solution

Rate this: bad
 
good
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
NULL	NULL
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);
con.Open();
DataTable dt = new DataTable();
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
da.Fill(dt);
And got two rows: 2, and 3.

Check your data!
  Permalink  
v2
Comments
Cool Smith 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 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 15-Feb-13 9:29am
   
thank you very much. so even if i do this '%@! @@ @# $ @% @^ @& @* @( @) ''%', it doesn't have any negative effects right
OriginalGriff 15-Feb-13 9:34am
   
You might want to escape the "%" in the middle, but otherwise it's fine!
Cool Smith 15-Feb-13 9:44am
   
thank you very much
OriginalGriff 15-Feb-13 10:24am
   
You're welcome!
Marcus Kramer 15-Feb-13 10:20am
   
+5.
Cool Smith 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 15-Feb-13 12:08pm
   
Without looking at your data? No idea at all! :laugh:
Cool Smith 15-Feb-13 12:10pm
   
in the database, the data in the field is Today's Task
OriginalGriff 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2016
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