예제 #1
0
파일: Dao.java 프로젝트: afayp/Gank
 public boolean isExists(Good good) {
   Cursor cursor =
       db.rawQuery("select _id from Good where _id = " + "'" + good.get_id() + "'", null);
   if (cursor.getCount() > 0) {
     return true; // 已经有了
   }
   return false;
 }
예제 #2
0
파일: Dao.java 프로젝트: afayp/Gank
  public List<Good> getGoodFromDB() {
    List<Good> goodList = new ArrayList<Good>();
    Cursor cursor = db.rawQuery("SELECT * FROM Good", null);
    //        Cursor cursor = db.query("Good", null, null, null, null, null, null);
    Log.e("Gank", "开始查询!");
    if (cursor.moveToFirst()) {
      do {
        Good good = new Good();
        good.set_id(cursor.getString(cursor.getColumnIndex("_id")));
        good.setWho(cursor.getString(cursor.getColumnIndex("who")));

        Log.e("Gank", "开始查询!who = " + cursor.getString(cursor.getColumnIndex("who")));

        good.setPublishedAt(cursor.getString(cursor.getColumnIndex("publishedAt")));
        good.setDesc(cursor.getString(cursor.getColumnIndex("desc")));
        good.setType(cursor.getString(cursor.getColumnIndex("type")));
        good.setUrl(cursor.getString(cursor.getColumnIndex("url")));
        goodList.add(good);
      } while (cursor.moveToNext());
    }

    if (cursor != null) {
      cursor.close();
    }
    db.close();
    return goodList;
  }
예제 #3
0
파일: Dao.java 프로젝트: afayp/Gank
 public void saveGood(Good good) {
   if (isExists(good)) {
     Log.e("Gank", "已经存在!");
     return;
   }
   db.execSQL(
       "INSERT INTO Good VALUES("
           + "'"
           + good.get_id()
           + "',"
           + "'"
           + good.getWho()
           + "',"
           + "'"
           + good.getPublishedAt()
           + "',"
           + "'"
           + good.getDesc()
           + "',"
           + "'"
           + good.getType()
           + "',"
           + "'"
           + good.getUrl()
           + "'"
           + ")");
   db.close();
   Log.e("Gank", "开始存:" + good.toString());
 }
예제 #4
0
파일: Dao.java 프로젝트: afayp/Gank
 public void deleteGood(Good good) {
   db.execSQL("delete from Good where _id = " + "'" + good.get_id() + "'");
 }