与Android这样SQLiteDatabase查询 [英] Android SQLiteDatabase query with LIKE

查看:156
本文介绍了与Android这样SQLiteDatabase查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的名字表3名,Allakhazam,节奏口技和狡猾。

I have 3 names, Allakhazam, Beatbox and Cunning in my NAMES Table.

public Cursor fetchNamesByConstraint(String filter) {

    mDb.query(true, DATABASE_NAMES_TABLE, new String[] { KEY_ROWID,
            KEY_NAME }, KEY_NAME + " LIKE ?",
            new String[] { filter }, null, null, null,
            null);

    return mCursor;
}

我叫有A作为过滤的功能,但我的指针函数返回一个0计数时,它至少应该回到我1.任何人都可以看看有什么毛病code?

I call the function with "A" as the filter, but my cursor is returning a 0 count when it should at least return me a 1. Anyone can see what's wrong with the code?

推荐答案

这条语句将返回其键名等于字符串指定,如果您使用通配符,那么你就可以得到想要的结果字符串中的所有记录。像:

this statement will return all the records whose keyname equals string specified by string, if you use wild card, then you can get desired results. Like:

mDb.query(true, DATABASE_NAMES_TABLE, new String[] { KEY_ROWID,
            KEY_NAME }, KEY_NAME + " LIKE ?",
            new String[] { filter+"%" }, null, null, null,
            null);

威尔列出的所有记录开头词过滤器。

Will Lists all the records starting with word in filter.

mDb.query(true, DATABASE_NAMES_TABLE, new String[] { KEY_ROWID,
            KEY_NAME }, KEY_NAME + " LIKE ?",
            new String[] {"%"+ filter+ "%" }, null, null, null,
            null);

威尔列出所有包含过滤词的记录。

Will Lists all the records containing word in filter.

这篇关于与Android这样SQLiteDatabase查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆