/** * 查询黑名单号码的拦截模式 * * @param number * @return 号码的拦截模式,不是黑名单号码就返回 null */ public String queryForMode(String number) { String result = null; SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.rawQuery("select mode from blacknumber where number = ?", new String[] {number}); if (cursor.moveToNext()) result = cursor.getString(0); cursor.close(); db.close(); return result; }
/** * 查询黑名单号码是否存在 * * @param number * @return */ public boolean query(String number) { boolean result = false; SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.rawQuery("select * from blacknumber where number = ?", new String[] {number}); if (cursor.moveToNext()) result = true; cursor.close(); db.close(); return result; }
/** * 查询全部黑名单号码 * * @return List<BlackNumberInfo> */ public List<BlackNumberInfo> queryAll() { List<BlackNumberInfo> result = new ArrayList<BlackNumberInfo>(); SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.rawQuery("select number, mode from blacknumber order by _id desc", null); while (cursor.moveToNext()) { BlackNumberInfo info = new BlackNumberInfo(); info.setNumber(cursor.getString(0)); info.setMode(cursor.getString(1)); result.add(info); } cursor.close(); db.close(); return result; }
/** * 查询部分黑名单号码 * * @return List<BlackNumberInfo> */ public List<BlackNumberInfo> queryPart(int offset, int maxnumber) { // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // e.printStackTrace(); // } List<BlackNumberInfo> result = new ArrayList<BlackNumberInfo>(); SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.rawQuery( "select number, mode from blacknumber order by _id desc limit ? offset ?", new String[] {String.valueOf(maxnumber), String.valueOf(offset)}); while (cursor.moveToNext()) { BlackNumberInfo info = new BlackNumberInfo(); info.setNumber(cursor.getString(0)); info.setMode(cursor.getString(1)); result.add(info); } cursor.close(); db.close(); return result; }