java - search an array in sqlite table -


i have 1 table this:

      database.execsql("create  table if not exists food_table (food_id integer primary key  autoincrement  not null , food_name char, food_raw char)"); 

and have string array this:

    public static arraylist<string> rawsnames = new arraylist<string>(); 

now want search in table , if of raw of food in rawsnames return food_name .

i :

string raws = adapternotes.rawsnames.tostring().replace("]", "").replace("[", ""); cursor cursor = g.database.rawquery("select * food_table food_raw '%" + raws + "%' ", null);     while (cursor.movetonext()) {         string name = cursor.getstring(cursor.getcolumnindex("food_name")); 

but when food's raw changed doesn't work.

please me.

it appears food_table contains fields:

food_id : unique id assigned food item
food_name : name of food item
food_raw : ingredients separated ,

now, since possible ingredients same, order different stored in database, simple where %"a, b, c"% won't work b, a, c valid ingredients same food (just order different).

hence, need match each individual ingredient instead of ingredients whole:

string req = ""; for(string rawname : rawnames)   req += " food_raw %"+rawname+"% and"; if(req.length() > 4)   req = req.substring(0, req.length()-4); // remove last " and" string query = "select * food_table "+req; 

using query should able obtain food name, regardless of item order.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -