mercredi 4 novembre 2015

SQLite multiple column search - android

I am using 2 separate searches at the moment, both work fine by themselves. but I can't figure out how to join the 2?

Result I'm after is, IF col1 contains word1 AND col2 contains word2

col1 contains single words, col2 contains multiple words.

These are the 2 separate queries that work fine by themselves.

String selection = col1+ " LIKE ?";
String[] selection_args = {word1};
Cursor cursor = sqlitedatabase.query(TABLE_NAME, All_Cols, selection, selection_args, null, null, null);


String selection =  col2+ " LIKE ?";
String[] selection_args = {"%"+word2+"%"};
Cursor cursor = sqlitedatabase.query(TABLE_NAME, All_Cols, selection, selection_args, null, null, null);

I'm new to android studio and sqlite, I guess my question and code confirms that anyway ;-))

Thanks

Aucun commentaire:

Enregistrer un commentaire