如何执行源码查询内部应用程序?
-
12-09-2019 - |
题
我正尝试使用这一查询后,我的机器数据库,但是它没有返回的任何数据。我失去了一些东西?
SQLiteDatabase db = mDbHelper.getReadableDatabase();
String select = "Select _id, title, title_raw from search Where(title_raw like " + "'%Smith%'" +
")";
Cursor cursor = db.query(TABLE_NAME, FROM,
select, null, null, null, null);
startManagingCursor(cursor);
return cursor;
解决方案
这将返回所需的光标
Cursor cursor = db.query(TABLE_NAME, new String[] {"_id", "title", "title_raw"},
"title_raw like " + "'%Smith%'", null, null, null, null);
其他提示
可替换地,db.rawQuery(SQL,selectionArgs两个)存在
Cursor c = db.rawQuery(select, null);
这也将工作,如果你想匹配的模式是一个变量。
dbh = new DbHelper(this);
SQLiteDatabase db = dbh.getWritableDatabase();
Cursor c = db.query("TableName", new String[]{"ColumnName"}
, "ColumnName LIKE ?" ,new String[]{_data+"%"}, null, null, null);
while(c.moveToNext())
{
// your calculation goes here
}
我来这里是为了提醒的如何设置查询,但现有的实例是难以遵循。这是一个实例有更多的解释。
SQLiteDatabase db = helper.getReadableDatabase();
String table = "table2";
String[] columns = {"column1", "column3"};
String selection = "column3 =?";
String[] selectionArgs = {"apple"};
String groupBy = null;
String having = null;
String orderBy = "column3 DESC";
String limit = "10";
Cursor cursor = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy, limit);
参数
table
:名称表的要查询columns
:列名,你希望返回。不返回的数据,你不需要的。selection
:行数据,你想要返回的列(这是其中的条款。)selectionArgs
:这是取代为?
在selection
串以上。groupBy
和having
:这个群体中的重复数据的列的数据具有一定的条件。任何不必要的参数可以设置空。orderBy
:对数据进行排序limit
:限制的数量的结果返回
试试这个,这适用于我的代码 名是一个字符串:
cursor = rdb.query(true, TABLE_PROFILE, new String[] { ID,
REMOTEID, FIRSTNAME, LASTNAME, EMAIL, GENDER, AGE, DOB,
ROLEID, NATIONALID, URL, IMAGEURL },
LASTNAME + " like ?", new String[]{ name+"%" }, null, null, null, null);
不隶属于 StackOverflow