Android SQLite"BETWEEN"不包含或返回所有记录

fis*_*ssk 5 sqlite android between

看起来非常简单的任务,尝试使用以下内容在Android应用程序中的SQLite数据库中获取给定范围的记录/行:

String[] projection = {"_id"};
String selection = "_id between ? and ?";
String[] selectionArgs = {"1", "10"};

queryBuilder.query(db, projection, selection, selectionArgs, null, null, null);
Run Code Online (Sandbox Code Playgroud)

使用上面的selectionArgs,我只得到两行,第1行和第10行.如果我将arg更改为其他任何内容,我将获得整个(整个记录/行集),就像没有条件一样.一直在敲打我的头脑,为什么它的工作方式如此,或许在SQLite中使用"之间"有一些特殊的事情要知道?任何评论/帮助非常感谢.

Lal*_*ani 0

我检查了一下你这边的问题,效果很好,

方法

public Cursor GetBetween(String[] projection,String selection, String[] args){
        return db.query(TBL_NAME, projection, selection, args, null, null, null);
    }
Run Code Online (Sandbox Code Playgroud)

执行

        String[] projection = new String[]{"_id"};
        String[] selectionArgs = new String[]{"1","3"};
        String selection = "_id between ? and ?";
        Cursor cursorGetBetween = helper.GetBetween(projection,selection, selectionArgs);
        startManagingCursor(cursorGetBetween);
        cursorGetBetween.moveToFirst();
        while(!cursorGetBetween.isAfterLast()){
            Log.d("value of cursorGetBetween", cursorGetBetween.getString(0));
            cursorGetBetween.moveToNext();
        }
Run Code Online (Sandbox Code Playgroud)

输出

01-31 18:42:58.176: D/value of cursorGetBetween(647): 1
01-31 18:42:58.176: D/value of cursorGetBetween(647): 2
01-31 18:42:58.176: D/value of cursorGetBetween(647): 3
Run Code Online (Sandbox Code Playgroud)