SQLite string searching

DarkMann

Member
Licensed User
Longtime User
I'm working on my first App that uses a SQLite database and all seems to be going quite well. I can read the database into my app, change data within records and make sure the changes are stored, all with no problem.

Now, as part of the major functionality of the program, I need to be able to filter my list of data and display only part of it. I have no problem with the display of the list, but I just don't know enough SQL to figure out how to return a set of results that contain the string (or strings) typed into the filter.

my basic select - to get all records looks like this:

B4X:
SELECT _id,Common,Scientific,Seen FROM t_birds

and this works just fine. I need to look for a partial string within the Common column and return the results.


B4X:
SELECT _id,Common,Scientific,Seen FROM t_birds WHERE Common **SOME STRING**

I have tried loads of stuff using what I can find around the net, but nothing actually gives me a new list.

Any suggestions much appreciated.

David
 

devlei

Active Member
Licensed User
Longtime User
Try the following:
B4X:
"SELECT _id, Common, Scientific, Seen FROM t_birds WHERE Common='Some String'"
or if your Some String is in a variable (SomeString)
B4X:
"SELECT _id, Common, Scientific, Seen FROM t_birds WHERE Common='" & SomeString & "'"

Note: The single quotes (') identify the string.

Dave
 
Upvote 0

DarkMann

Member
Licensed User
Longtime User
Hi,

Thanks to all for the hints.

I am at work at present, but will report back later.

David
 
Upvote 0

DarkMann

Member
Licensed User
Longtime User
Hi again,

Just to follow up to say thanks once more.

Using LIKE with single quotes around the wildcard %s and the required string as Erel suggests works fine. Don't know why I didn't use SQL before now, as it saves a lot of effort.

Should have some work to show now in the next few days.

David
 
Upvote 0

timo

Active Member
Licensed User
Longtime User
I've found this thread while searching for something else. I just wanted to add that I've had some problems using LIKE v/s '=' with strings in SqLite.
It seems that LIKE 'string' is not allways case sensitive (but = 'string' yes).
I'm anyway not shure about that, but it's what i encountered.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…