Example #1
0
  public List<BlackInfo> findAll() {
    List<BlackInfo> list = new ArrayList<BlackInfo>();
    SQLiteDatabase db = helper.getReadableDatabase();
    // "select number,type from blacklist;"
    String sql =
        "select "
            + BlackListDB.BlackList.COLUMN_NUMBER
            + ","
            + BlackListDB.BlackList.COLUMN_TYPE
            + " from "
            + BlackListDB.BlackList.TABLE_NAME;
    Cursor cursor = db.rawQuery(sql, null);
    if (cursor != null) {
      while (cursor.moveToNext()) {
        String number = cursor.getString(0);
        int type = cursor.getInt(1);

        BlackInfo info = new BlackInfo();
        info.number = number;
        info.type = type;

        list.add(info);
      }
      cursor.close();
    }
    db.close();
    return list;
  }
Example #2
0
 public int findType(String number) {
   SQLiteDatabase db = helper.getReadableDatabase();
   // select type from 表名 where number=?;
   String sql =
       "select "
           + BlackListDB.BlackList.COLUMN_TYPE
           + " from "
           + BlackListDB.BlackList.TABLE_NAME
           + " where "
           + BlackListDB.BlackList.COLUMN_NUMBER
           + "=?";
   String[] selectionArgs = new String[] {number};
   Cursor cursor = db.rawQuery(sql, selectionArgs);
   int type = -1;
   if (cursor != null) {
     if (cursor.moveToNext()) {
       type = cursor.getInt(0);
     }
     cursor.close();
   }
   db.close();
   return type;
 }