Android的SQLite的" BETWEEN"不包括或返回所有记录 [英] Android SQLite "BETWEEN" not inclusive or returns all records

查看:128
本文介绍了Android的SQLite的" BETWEEN"不包括或返回所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常简单的任务这似乎试图让记录/行给定范围内,在Android应用程序有以下我的SQLite数据库:

Very simple task it would seem, trying to get a given range of records/rows in my SQLite db in Android app with the following :

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

queryBuilder.query(db, projection, selection, selectionArgs, null, null, null);

通过上述selectionArgs两个如果我ARG变更为别的,我发现了一大堆(整组记录/行),如果没有条件,我想起来了两排,一排1和10。一直敲打我的头一天为什么这个工作它的方式,或许有一些了解使用SQLite中的特别的东西?任何意见/帮助不大AP preciated。

With the above selectionArgs I'm getting just the two rows, row 1 and 10. If I change arg to anything else I'm getting the whole lot (entire set of records/rows) as if there was no condition. Been banging my head for a day why this works the way it does, perhaps there's some special thing to know about the use of "between" in SQLite ? Any comments/help much appreciated.

推荐答案

您可以使用此code。

You can use this code.

private SQLiteDatabase productDatabase;
   public Cursor get_result(){
   Cursor c;
   String sql = "SELECT * FROM " + tableName +"WHERE _id BETWEEN" + value1 +"AND" + value2;
   c = productDatabase.rawQuery(sql, null);
}

Cursor cursor=get_result();
    if(cursor.moveToNext()){
    Log.d("count of product id="+cursor.getString(0));
}

这篇关于Android的SQLite的" BETWEEN"不包括或返回所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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