Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

android - How to pass two or more selection argument in "query" method

I am using query method, but I don't no how to pass more than one selection argument in query method.

My query method should return result as same as this sql statement :

SELECT _id FROM CONATCT_TAGS WHERE TAG1='tagname' OR
                                   TAG2='tagname' OR 
                                   TAG3='tagname' OR 
                                   TAG4='tagname' OR
                                   TAG5='tagname';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to use the built-in optimization in the Android SQLite connection you could do something like this instead:

String table = "CONTACT_TAGS";
String[] columns = {"_id"};
String where = "TAG1=? OR TAG2=? OR TAG3=? OR TAG4=? OR TAG5=?";
String[] args = {"tagname", "tagname", "tagname", "tagname", "tagname"};

SQLiteDatabase db = myDatabaseHelper.getReadableDatabase();
Cursor cursor = db.query(table, columns, where, args, null, null, null);

The difference from @raultum's solution is that you let the database connector decide how to interpret the submitted data. This is extra interesting from a security perspective.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...