@Override public synchronized void insertThread(ThreadInfo threadInfo) { SQLiteDatabase db = mHelper.getWritableDatabase(); db.execSQL( "insert into thread_info(thread_id,url,start,end,finished) values(?,?,?,?,?)", new Object[] { threadInfo.getId(), threadInfo.getUrl(), threadInfo.getStart() + "", threadInfo.getEnd() + "", threadInfo.getFinished() + "" }); db.close(); }
@Override public List<ThreadInfo> getThreads(String url) { List<ThreadInfo> list = new ArrayList<ThreadInfo>(); SQLiteDatabase db = mHelper.getReadableDatabase(); Cursor cursor = db.rawQuery("select * from thread_info where url = ?", new String[] {url}); while (cursor.moveToNext()) { ThreadInfo threadInfo = new ThreadInfo(); threadInfo.setId(cursor.getInt(cursor.getColumnIndex("thread_id"))); threadInfo.setUrl(cursor.getString(cursor.getColumnIndex("url"))); threadInfo.setStart(cursor.getLong(cursor.getColumnIndex("start"))); threadInfo.setEnd(cursor.getLong(cursor.getColumnIndex("end"))); threadInfo.setFinished(cursor.getLong(cursor.getColumnIndex("finished"))); list.add(threadInfo); } cursor.close(); db.close(); return list; }