/** data follow by recordTime */ public List<gtdContent> retrieveData() { StringBuilder bd = new StringBuilder(); bd.append("select * from ") .append(GtdTable.TABLE_NAME) .append(" order by ") .append(GtdTable.ITEM_WRITTEN_MILLSECECOND) .append(" desc"); Log.d("SQL_RETRIEVE", bd.toString()); Cursor cursor = helper.find(bd.toString(), null); List<gtdContent> list = new ArrayList<gtdContent>(cursor.getCount()); while (cursor.moveToNext()) { gtdContent _om = new gtdContent(); _om.setSmsID(cursor.getInt(cursor.getColumnIndex(GtdTable.SMS_ID))); _om.setStartTime(cursor.getString(cursor.getColumnIndex(GtdTable.START_TIME))); _om.setEndTime(cursor.getString(cursor.getColumnIndex(GtdTable.END_TIME))); _om.setPlace(cursor.getString(cursor.getColumnIndex(GtdTable.PLACE))); _om.setContent(cursor.getString(cursor.getColumnIndex(GtdTable.CONTENT))); _om.setGtdStatus(cursor.getString(cursor.getColumnIndex(GtdTable.GTDSTATUS))); _om.setGtdType(cursor.getString(cursor.getColumnIndex(GtdTable.GTDTYPE))); _om.setWrite_time(cursor.getLong(cursor.getColumnIndex(GtdTable.ITEM_WRITTEN_MILLSECECOND))); Log.d("SQL_RETRIEVE", _om.getContent()); list.add(_om); } return list; }
/** * insert Data * * @param om smsDataModule * @return */ public long insert(gtdContent om) { try { ContentValues values = new ContentValues(); Log.d("SQL_ADD", GtdTable.TABLE_NAME + " ~~ " + om.getContent()); values.put(GtdTable.START_TIME, om.getStartTime()); values.put(GtdTable.END_TIME, om.getEndTime()); values.put(GtdTable.PLACE, om.getPlace()); values.put(GtdTable.CONTENT, om.getContent()); values.put(GtdTable.GTDSTATUS, om.getGtdStatus()); values.put(GtdTable.GTDTYPE, om.getGtdType()); values.put(GtdTable.ITEM_WRITTEN_MILLSECECOND, om.getWrite_time()); return helper.save(GtdTable.TABLE_NAME, values); } catch (Exception e) { Log.d("addData Exception", e.toString()); e.printStackTrace(); return -1; } }
/** data follow by today tomorrow */ public List<gtdContent> retrieveTime() { StringBuilder bd = new StringBuilder(); bd.append("select * from ") .append(GtdTable.TABLE_NAME) .append(" where ") .append(GtdTable.GTDSTATUS) .append(" = ") .append("todo"); Log.d("SQL_RETRIEVE", bd.toString()); System.out.println(bd.toString()); // Cursor cursor = helper.find(bd.toString(), null); calendar = new CalendarDateBean(); long todayBegin = calendar.getTodayBeginZero(); long todayEnd = calendar.getTodayEndZero(); Cursor cursor = helper.find( "select * from GTDTable where startTime<? and startTime>?", new String[] { String.valueOf(todayEnd), String.valueOf(todayBegin), }); List<gtdContent> list = new ArrayList<gtdContent>(cursor.getCount()); while (cursor.moveToNext()) { gtdContent _om = new gtdContent(); _om.setSmsID(cursor.getInt(cursor.getColumnIndex(GtdTable.SMS_ID))); _om.setStartTime(cursor.getString(cursor.getColumnIndex(GtdTable.START_TIME))); _om.setEndTime(cursor.getString(cursor.getColumnIndex(GtdTable.END_TIME))); _om.setPlace(cursor.getString(cursor.getColumnIndex(GtdTable.PLACE))); _om.setContent(cursor.getString(cursor.getColumnIndex(GtdTable.CONTENT))); _om.setGtdStatus(cursor.getString(cursor.getColumnIndex(GtdTable.GTDSTATUS))); _om.setGtdType(cursor.getString(cursor.getColumnIndex(GtdTable.GTDTYPE))); _om.setWrite_time(cursor.getLong(cursor.getColumnIndex(GtdTable.ITEM_WRITTEN_MILLSECECOND))); Log.d("SQL_RETRIEVE", _om.getContent()); list.add(_om); } return list; }