/** * 查看数据库中是否有数据 * * @param urlstr * @return */ public boolean isHasInfos(String urlstr) { SQLiteDatabase database = dbHelper.getReadableDatabase(); String sql = "select count(*) from download_info where url = ?"; Cursor cursor = database.rawQuery(sql, new String[] {urlstr}); cursor.moveToFirst(); int count = cursor.getInt(0); cursor.close(); // 游标返回为0 return count == 0; }
/** * 得到下载具体信息 * * @param urlstr * @return */ public List<DownloadInfo> getInfos(String urlstr) { List<DownloadInfo> list = new ArrayList<DownloadInfo>(); SQLiteDatabase database = dbHelper.getReadableDatabase(); String sql = "select thread_id, start_pos, end_pos, compelete_size, url from download_info where url = ?"; Cursor cursor = database.rawQuery(sql, new String[] {urlstr}); while (cursor.moveToNext()) { DownloadInfo info = new DownloadInfo( cursor.getInt(0), cursor.getInt(1), cursor.getInt(2), cursor.getInt(3), cursor.getString(4)); list.add(info); } return list; }
/** * 下载完成后删除数据库中的数据 * * @param url */ public void delete(String url) { SQLiteDatabase database = dbHelper.getReadableDatabase(); database.delete("dwonload_info", "url = ?", new String[] {url}); database.close(); }