如何通过在&QUOT两个或更多个选项的参数;查询"方法 [英] How to pass two or more selection argument in "query" method
问题描述
我使用的查询方法,但我不就没怎么传递查询方法不止一个选择参数。
我的查询方法应该是相同的返回结果,因为这条SQL语句:
选择_id从CONATCT_TAGS其中Tag1 ='标记名'OR TAG2 ='标记名'OR TAG3 ='标记名'OR TAG4 ='标记名'OR TAG5 ='标记名';
尝试类似的东西。
SQLiteDatabase DB = YourDatabaseHelper.getReadableDatabase();
字符串表=CONTACT_TAGS;
的String []栏= {_id};
字符串,其中=TAG1 ='标记名'OR TAG2 ='标记名'OR TAG3 ='标记名'OR TAG4 ='标记名'OR TAG5 ='标记名';
// 执行
光标= db.query(表,字段,WHERE,NULL,NULL,NULL,NULL);
如果你阅读的文档<一href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#query%28java.lang.String,%20java.lang.String%5b%5d,%20java.lang.String,%20java.lang.String%5b%5d,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%29">Cursor.query()方法,可以找到选择定义
如下:
选择:过滤器宣称要返回的行,格式化为 SQL WHERE子句(不包括在WHERE本身)。传递null意志 返回所有行对给定表。
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';
Try something like that..
SQLiteDatabase db = YourDatabaseHelper.getReadableDatabase();
String TABLE = "CONTACT_TAGS";
String[] FIELDS = { "_id" };
String WHERE = "TAG1='tagname' OR TAG2='tagname' OR TAG3='tagname' OR TAG4='tagname' OR TAG5='tagname' ";
// Execute
cursor = db.query(TABLE, FIELDS, WHERE, null, null, null, null);
If you read the documentation of the Cursor.query() method you find the definition for selection
as follows:
selection: A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table.
这篇关于如何通过在&QUOT两个或更多个选项的参数;查询&QUOT;方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!