So I've been dragging with this one for some time now and simply can't find the solutions
Let's say I have a table called NAME with values like
John Doe
Jane Doe
etc.
I just want to pull the first word.... so everything after the first space ' ' will not show
I'm pulling the data into a Cursor as it's over 2000 records
Any thoughts on a raw query that will do such a thing?
Thanks in advance
Yeshai
You just get the string from db as a string and use something like
String[] strs = dbString.split(" ");
str[0] should be what you need.
Related
So i have a data base and in the app while the user searches for something with the ' character, like "wendy's house", i send a query with the WHERE as "wendy's house" and here is where it crushes.
I would like to know please what should i do with the string in order that ill be able to send it in the query and the result the user gets will stay unharmed.
Thanks in advance.
Here you have an answer how to escape the apostrophe in your SQL:
INSERT INTO Person
(First, Last)
VALUES
('Joe', 'O''Brien')
/\
right here
Or
SELECT First, Last FROM Person WHERE Last = 'O''Brien'
https://stackoverflow.com/a/1912100/2065587
In my application I take entry from user as :-
Name:- -------------------------
Favorite Fruit:- a)
b)
c)
--------- Add More ----------
Then I want to save it into a Sqlite database. Now I provide user to type in edittext search like this:-
Search Fruit:- Apple,Banana
And then I want to query my database and Print the name of those who like atleast Apple and Banana.
Now my issue is how do I make my database columns to achieve results faster.
Should I make two columns Name and FruitsLiked or something else. Because if I make only two colums then how do I search into database.
Thanks
Create one table n two columns. First column is for name , second one comma separated list of fruits.
Then as db query use like keyword based query
what i am trying to use is that i want to select cities from my LocationByCity table in sqlite database each time As user inters search word in a search box,
for example if user enters F i want all the CityNames Starting From F ,so how can i do that?
Thanx in advance.
I'd have to check up, but I believe you want to use the LIKE keyword.
Syntax somthing along the lines of:
Select Fieldname From Tablename where fieldname LIKE ('%$myvar%');
where the % signs are wildcard characters.
Not sure if sqlite has fulltext indexing so you should be aware that can get very slow depending on how many rows you have in the table.
I've done quite a bit of research on what I thought would be an easy question but I cannot find what I am looking for. I am simply trying to return a record as a match with only a search term matching part of the text in the record.
For example, if the user searches for "ed" I would like any record that contains "ed" to be returned. So if there was a record with the name "Edward" in the name column it would be returned as a match. If there was a record with "finished" in the description, it would also return that record as a match.
I have looked into full text search but not sure if this is something that I would need to do or if it would even do what I need.
As always, I'm not looking for an answer per say, I'm just looking for a direction.
Never used SQLite before, but does it have the "LIKE" operator?
In MySQL, you can do something like:
SELECT name FROM list WHERE name LIKE '%ed%';
Here is some code that will do what you want if you are querying a content provider. If you are querying a sqlite database object directly, the parameters are similar but different.
String search = "ed";
// surround it with the SQL wildcard '%'
String q = "%" + search + "%"
Cursor c = getContentResolver().query(uri,
new String[] { column1, column2 },
"column_name like ?",
new String[] { q },
null);
The snippet will search the content provider at uri for the string ed in column_name.
i am sorry to ask again since i asked something similar to this earlier, but am in serious need of help here. situation is this, i have an Arraylist with values of strings, which i have converted to an array i want to query a "NAME" column in my sqlite database and return rows that have the string values in the name column.
e.g the `String [] a = {"do this", "do that", "help here"}; but it grows dynamically and can have a lenght with respect to the database column.(i mean it can't grow past the size of the database table.)
how can i construct an sqlite query to return rows that have this string in their array? Am having sqlite error of "incorrect syntax" or "bind or column index out of bounds" when using the suggestions from this post.
[http://stackoverflow.com/questions/3985263/using-an-array-to-query-an-sqlite-database-android][1]
i have no idea how to query the table anymore. please help, any help will be greatly appreciated. Thank you
In a nutshell: The function you want is ContentResolver.query(). You get the resolver via context.getContentResolver().
You pass in:
Uri - the URI of your content provider.
Projection - the columns you want.
selection - okay, that's where it gets interesting. Create a string here that looks like this: NAME=? OR NAME=? OR NAME=?.
selectionArgs - this is essentially the string array a in your question.
sortOrder - whatever you want.
If you're not using a content provider, you can use SQLiteDatabase's query function which works in an almost identical fashion.