public List<ViewItem> getPageInChapter(String chapterUrl) { List<ViewItem> list = new ArrayList<ViewItem>(); try { String selectQuery = "SELECT * FROM " + TABLE_PAGE + " r " + "WHERE r.chapterUrl = '" + chapterUrl + "'"; SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery(selectQuery, null); if (c.moveToFirst()) { do { ViewItem item = new ViewItem(c.getString(c.getColumnIndex("imageUrl"))); item.setChapterUrl(c.getString(c.getColumnIndex("chapterUrl"))); item.setFileUrl(c.getString(c.getColumnIndex("fileUrl"))); item.setOrder(c.getInt(c.getColumnIndex("stt"))); list.add(item); } while (c.moveToNext()); } c.close(); } catch (Exception e) { } return list; }
public int updatePage(ViewItem item) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("chapterUrl", item.getChapterUrl()); values.put("imageUrl", item.getImageUrl()); values.put("fileUrl", item.getFileUrl()); values.put("stt", item.getOrder()); // updating row return db.update(TABLE_PAGE, values, "chapterUrl = ?", new String[] {item.getChapterUrl()}); }
public long createPage(ViewItem item) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("chapterUrl", item.getChapterUrl()); values.put("imageUrl", item.getImageUrl()); values.put("fileUrl", item.getFileUrl()); values.put("stt", item.getOrder()); // insert row long inserted_id = db.insert(TABLE_PAGE, null, values); return inserted_id; }
public ViewItem getPage(String imageUrl) { try { String selectQuery = "SELECT * FROM " + TABLE_PAGE + " r " + "WHERE r.imageUrl = '" + imageUrl + "'"; SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery(selectQuery, null); if (c.moveToFirst()) { ViewItem item = new ViewItem(c.getString(c.getColumnIndex("imageUrl"))); item.setChapterUrl(c.getString(c.getColumnIndex("chapterUrl"))); item.setFileUrl(c.getString(c.getColumnIndex("fileUrl"))); item.setOrder(c.getInt(c.getColumnIndex("stt"))); return item; } c.close(); } catch (Exception e) { } return null; }