如何在android中的所有表中搜索字符串?

时间:2014-08-19 06:12:34

标签: android sqlite

如何在所有表格列中搜索字符串?

有什么帮助吗?

这是我的数据库创建方法

感谢

@Override
    public void onCreate(SQLiteDatabase db) 
    {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_TITLE
                + " TEXT NOT NULL , " + KEY_COUNTRY_ID
                + " TEXT NOT NULL , " + KEY_DESCRIPTION
                + " TEXT NOT NULL , " + KEY_IDP
                + " TEXT NOT NULL , " + KEY_CATEGORYP
                + " TEXT NOT NULL , " + KEY_CREATED_P
                + " TEXT NOT NULL , " + KEY_CREATED_P2
                + " TEXT NOT NULL , " + KEY_CREATED_BY
                + " TEXT NOT NULL , " + KEY_KEYS
                + " TEXT NOT NULL , " + KEY_READ_BY
                + " TEXT NOT NULL, " + KEY_DIR 
                + " TEXT NOT NULL, " + KEY_CITY 
                + " TEXT NOT NULL, " + KEY_LINK + " TEXT NOT NULL);");
    }

1 个答案:

答案 0 :(得分:4)

您可以为每个单独的列使用LIKE查询和循环

像这样:

    public Cursor searchDB(String query) { 
    return db.query(true, DB_TABLE, new String[] { KEY_ROWID, KEY_COLUMN1, KEY_COLUMN2,
    KEY_COLUMN3 }, KEY_COLUMN1 + " LIKE" + "'%" + query + "%' OR " + KEY_COLUMN2 + 
    " LIKE" + "'%" + query + "%' OR " + KEY_COLUMN3 + " LIKE" + "'%" + query + "%'", 
    null, null, null, null, null); 
} 

希望得到帮助