小编Fra*_*sco的帖子

Android/SQLite - WHERE子句上的位操作

我想知道在Android中是否可以这样做:

public Cursor getFlowsByCategory(int type, int categoryID, int limit) {

    SQLiteDatabase db = dbHelper.getReadableDatabase();

    final String[] columns = {ID, FLAGS, SUBJECT, AMOUNT, AMOUNT_NO, CATEGORY};
    final String selection = "((" + FLAGS + " & ?) >> 1 = ?) AND (" + CATEGORY + " = ?)";
    final String[] selectionArgs = {Integer.toString(Flow.FLOW_TYPE), Integer.toString(type), Integer.toString(categoryID)};

    return db.query(TABLE, columns, selection, selectionArgs, null, null, ID + " DESC", Integer.toString(limit));

}
Run Code Online (Sandbox Code Playgroud)

FLAGS是一个1字节的位掩码,我只想选择掩码的第二位(位置1)的行.掩码(Flow.FLOW_TYPE)是0b00000010,类型参数可以是0或1.它应该工作,但它没有:我做错了什么?

sql sqlite android bit-manipulation where

5
推荐指数
1
解决办法
1490
查看次数

标签 统计

android ×1

bit-manipulation ×1

sql ×1

sqlite ×1

where ×1