Exemplo n.º 1
0
  /**
   * 查询部分显示的数据
   *
   * @param querySize 每次查询的item
   * @param indexOffset
   * @return
   */
  public List<BlackInfo> getPartinfo(int querySize, int indexOffset) {

    SQLiteDatabase db = helper.getWritableDatabase();

    List<BlackInfo> list = new ArrayList<BlackInfo>();

    // limit : 每次查询的条数  offset : 从数据库取数据的时候,从什么位置开始取 offset 2 :  0,1,2

    // sql  = select * from tableName limit querySize offset nindexOffsetum;
    // 注意  : limit 是放在sql末尾,语法原因

    String sql =
        "select "
            + BlacklistDB.Table_db.COLUMN_TYPE
            + ","
            + BlacklistDB.Table_db.COLUMN_NUMBER
            + " from "
            + BlacklistDB.Table_db.TABLE_NAME
            + " limit "
            + querySize
            + " offset "
            + indexOffset;

    Cursor cursor = db.rawQuery(sql, null);

    if (cursor != null) {
      while (cursor.moveToNext()) {

        int type = cursor.getInt(0);

        String number = cursor.getString(1);

        BlackInfo info = new BlackInfo();

        info.number = number;
        info.type = type;

        list.add(info);
      }

      return list;
    }
    db.close();

    return null;
  }
Exemplo n.º 2
0
  /** @return */
  public List<BlackInfo> getAllInfo() {

    SQLiteDatabase db = helper.getWritableDatabase();

    List<BlackInfo> list = new ArrayList<BlackInfo>();

    String sql =
        "select "
            + BlacklistDB.Table_db.COLUMN_TYPE
            + ","
            + BlacklistDB.Table_db.COLUMN_NUMBER
            + " from "
            + BlacklistDB.Table_db.TABLE_NAME;

    Cursor cursor = db.rawQuery(sql, null);

    if (cursor != null) {
      while (cursor.moveToNext()) {

        int type = cursor.getInt(0);

        String number = cursor.getString(1);

        BlackInfo info = new BlackInfo();

        info.number = number;
        info.type = type;

        list.add(info);
      }

      return list;
    }
    db.close();

    return null;
  }