Пример #1
0
 /**
  * 查看数据库中是否有数据
  *
  * @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;
 }
Пример #2
0
 /**
  * 保存下载的数据
  *
  * @param infos
  */
 public void saveInfos(List<DownloadInfo> infos) {
   SQLiteDatabase database = dbHelper.getWritableDatabase();
   for (DownloadInfo info : infos) {
     String sql =
         "insert into  download_info(thread_id, start_pos, end_pos, compelete_size, url) values(?,?,?,?,?)";
     Object[] bindArgs = {
       info.getThreadId(),
       info.getStartPos(),
       info.getEndPos(),
       info.getCompeleteSize(),
       info.getUrl()
     };
     database.execSQL(sql, bindArgs);
   }
 }
Пример #3
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;
 }
Пример #4
0
 /** 关闭数据库 */
 public void closeDb() {
   dbHelper.close();
 }
Пример #5
0
 public void updateInfos(int threadId, int compeleteSize, String urlstr) {
   SQLiteDatabase database = dbHelper.getWritableDatabase();
   String sql = "update download_info set compelete_size=? where thread_id=? and url = ?";
   Object[] bindArgs = {compeleteSize, threadId, urlstr};
   database.execSQL(sql, bindArgs);
 }
Пример #6
0
 /**
  * 下载完成后删除数据库中的数据
  *
  * @param url
  */
 public void delete(String url) {
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   database.delete("dwonload_info", "url = ?", new String[] {url});
   database.close();
 }