List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<Activity> getActivitiesDue(int max, long userId) { ArrayList<Activity> activities = new ArrayList<Activity>(); DateTime now = new DateTime(); String nowDateString = MobileLearning.DATETIME_FORMAT.print(now); String sql = "SELECT a.* FROM " + ACTIVITY_TABLE + " a " + " INNER JOIN " + COURSE_TABLE + " m ON a." + ACTIVITY_C_COURSEID + " = m." + COURSE_C_ID + " LEFT OUTER JOIN (SELECT * FROM " + TRACKER_LOG_TABLE + " WHERE " + TRACKER_LOG_C_COMPLETED + "=1 AND " + TRACKER_LOG_C_USERID + "=" + userId + ") tl ON a." + ACTIVITY_C_ACTIVITYDIGEST + " = tl." + TRACKER_LOG_C_ACTIVITYDIGEST + " WHERE tl." + TRACKER_LOG_C_ID + " IS NULL " + " AND a." + ACTIVITY_C_STARTDATE + "<='" + nowDateString + "'" + " AND a." + ACTIVITY_C_TITLE + " IS NOT NULL " + " ORDER BY a." + ACTIVITY_C_ENDDATE + " ASC" + " LIMIT " + max; Cursor c = db.rawQuery(sql, null); c.moveToFirst();//from w ww . j a v a 2 s. c o m while (c.isAfterLast() == false) { Activity a = new Activity(); if (c.getString(c.getColumnIndex(ACTIVITY_C_TITLE)) != null) { a.setTitlesFromJSONString(c.getString(c.getColumnIndex(ACTIVITY_C_TITLE))); a.setCourseId(c.getLong(c.getColumnIndex(ACTIVITY_C_COURSEID))); a.setDigest(c.getString(c.getColumnIndex(ACTIVITY_C_ACTIVITYDIGEST))); activities.add(a); } c.moveToNext(); } if (c.getCount() < max) { //just add in some extra suggested activities unrelated to the date/time String sql2 = "SELECT a.* FROM " + ACTIVITY_TABLE + " a " + " INNER JOIN " + COURSE_TABLE + " m ON a." + ACTIVITY_C_COURSEID + " = m." + COURSE_C_ID + " LEFT OUTER JOIN (SELECT * FROM " + TRACKER_LOG_TABLE + " WHERE " + TRACKER_LOG_C_COMPLETED + "=1) tl ON a." + ACTIVITY_C_ACTIVITYDIGEST + " = tl." + TRACKER_LOG_C_ACTIVITYDIGEST + " WHERE (tl." + TRACKER_LOG_C_ID + " IS NULL " + " OR tl." + TRACKER_LOG_C_COMPLETED + "=0)" + " AND a." + ACTIVITY_C_TITLE + " IS NOT NULL " + " AND a." + ACTIVITY_C_ID + " NOT IN (SELECT " + ACTIVITY_C_ID + " FROM (" + sql + ") b)" + " LIMIT " + (max - c.getCount()); Cursor c2 = db.rawQuery(sql2, null); c2.moveToFirst(); while (c2.isAfterLast() == false) { Activity a = new Activity(); if (c2.getString(c.getColumnIndex(ACTIVITY_C_TITLE)) != null) { a.setTitlesFromJSONString(c2.getString(c2.getColumnIndex(ACTIVITY_C_TITLE))); a.setCourseId(c2.getLong(c2.getColumnIndex(ACTIVITY_C_COURSEID))); a.setDigest(c2.getString(c2.getColumnIndex(ACTIVITY_C_ACTIVITYDIGEST))); activities.add(a); } c2.moveToNext(); } c2.close(); } c.close(); return activities; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<ClientSession> getUnsentClientTrackers(String userName) { ClientSession clientSession;//from w w w . j a v a2 s . co m ArrayList<ClientSession> clientSessions = new ArrayList<ClientSession>(); String sql = "SELECT * FROM " + CLIENT_TRACKER_TABLE + " WHERE " + CLIENT_TRACKER_C_USER + " = ? AND " + CLIENT_TRACKER_C_END + " > 0;"; Cursor c = db.rawQuery(sql, new String[] { userName }); c.moveToFirst(); while (c.isAfterLast() == false) { clientSession = new ClientSession(); clientSession.setHealthWorker(c.getString(c.getColumnIndex(CLIENT_TRACKER_C_USER))); clientSession.setStartDateTime(c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_START))); clientSession.setEndDateTime(c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_END))); clientSession.setId(c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_ID))); clientSession.setClientId(c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_CLIENT))); if (c.getInt(c.getColumnIndex(CLIENT_TRACKER_C_CLIENTSTATUS)) > 0) clientSession.setIsSynced(true); else clientSession.setIsSynced(false); clientSessions.add(clientSession); c.moveToNext(); } return clientSessions; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public Course getCourse(long courseId, long userId) { Course course = null;//w ww . ja v a 2 s . com String s = COURSE_C_ID + "=?"; String[] args = new String[] { String.valueOf(courseId) }; Cursor c = db.query(COURSE_TABLE, null, s, args, null, null, null); c.moveToFirst(); while (c.isAfterLast() == false) { course = new Course(prefs.getString(PrefsActivity.PREF_STORAGE_LOCATION, "")); course.setCourseId(c.getInt(c.getColumnIndex(COURSE_C_ID))); course.setVersionId(c.getDouble(c.getColumnIndex(COURSE_C_VERSIONID))); course.setTitlesFromJSONString(c.getString(c.getColumnIndex(COURSE_C_TITLE))); course.setImageFile(c.getString(c.getColumnIndex(COURSE_C_IMAGE))); course.setLangsFromJSONString(c.getString(c.getColumnIndex(COURSE_C_LANGS))); course.setShortname(c.getString(c.getColumnIndex(COURSE_C_SHORTNAME))); course.setPriority(c.getInt(c.getColumnIndex(COURSE_C_ORDER_PRIORITY))); course.setDescriptionsFromJSONString(c.getString(c.getColumnIndex(COURSE_C_DESC))); course = this.courseSetProgress(course, userId); c.moveToNext(); } c.close(); return course; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public Activity getActivityByActId(int actId) { String sql = "SELECT * FROM " + ACTIVITY_TABLE + " a " + " WHERE " + ACTIVITY_C_ACTID + "=" + actId; Cursor c = db.rawQuery(sql, null); c.moveToFirst();/* w ww . j a v a 2 s . c om*/ Activity a = new Activity(); while (c.isAfterLast() == false) { if (c.getString(c.getColumnIndex(ACTIVITY_C_TITLE)) != null) { a.setDigest(c.getString(c.getColumnIndex(ACTIVITY_C_ACTIVITYDIGEST))); a.setDbId(c.getInt(c.getColumnIndex(ACTIVITY_C_ID))); a.setTitlesFromJSONString(c.getString(c.getColumnIndex(ACTIVITY_C_TITLE))); a.setSectionId(c.getInt(c.getColumnIndex(ACTIVITY_C_SECTIONID))); } c.moveToNext(); } c.close(); return a; }
From source file:edu.stanford.mobisocial.dungbeetle.DBHelper.java
private long getFeedMaxSequenceId(long contactId, String feedName) { Cursor c = getReadableDatabase().query(DbObject.TABLE, new String[] { DbObject.SEQUENCE_ID }, DbObject.CONTACT_ID + "=? AND " + DbObject.FEED_NAME + "=?", new String[] { String.valueOf(contactId), feedName }, null, null, DbObject.SEQUENCE_ID + " DESC LIMIT 1"); try {/* w ww . jav a 2 s . c o m*/ c.moveToFirst(); if (!c.isAfterLast()) { long max = c.getLong(0); Log.i(TAG, "Found max seq num: " + max); return max; } return -1; } finally { c.close(); } }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public Activity getActivityByDigest(String digest) { String sql = "SELECT * FROM " + ACTIVITY_TABLE + " a " + " WHERE " + ACTIVITY_C_ACTIVITYDIGEST + "='" + digest + "'"; Cursor c = db.rawQuery(sql, null); c.moveToFirst();/*from www .j a v a 2 s .c om*/ Activity a = new Activity(); while (c.isAfterLast() == false) { if (c.getString(c.getColumnIndex(ACTIVITY_C_TITLE)) != null) { a.setDigest(c.getString(c.getColumnIndex(ACTIVITY_C_ACTIVITYDIGEST))); a.setDbId(c.getInt(c.getColumnIndex(ACTIVITY_C_ID))); a.setTitlesFromJSONString(c.getString(c.getColumnIndex(ACTIVITY_C_TITLE))); a.setSectionId(c.getInt(c.getColumnIndex(ACTIVITY_C_SECTIONID))); } c.moveToNext(); } c.close(); return a; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<Course> getAllCourses() { ArrayList<Course> courses = new ArrayList<Course>(); String order = COURSE_C_ORDER_PRIORITY + " DESC, " + COURSE_C_TITLE + " ASC"; Cursor c = db.query(COURSE_TABLE, null, null, null, null, null, order); c.moveToFirst();/*from www .j a v a2s .c o m*/ while (c.isAfterLast() == false) { Course course = new Course(prefs.getString(PrefsActivity.PREF_STORAGE_LOCATION, "")); course.setCourseId(c.getInt(c.getColumnIndex(COURSE_C_ID))); course.setVersionId(c.getDouble(c.getColumnIndex(COURSE_C_VERSIONID))); course.setTitlesFromJSONString(c.getString(c.getColumnIndex(COURSE_C_TITLE))); course.setImageFile(c.getString(c.getColumnIndex(COURSE_C_IMAGE))); course.setLangsFromJSONString(c.getString(c.getColumnIndex(COURSE_C_LANGS))); course.setShortname(c.getString(c.getColumnIndex(COURSE_C_SHORTNAME))); course.setPriority(c.getInt(c.getColumnIndex(COURSE_C_ORDER_PRIORITY))); courses.add(course); c.moveToNext(); } c.close(); return courses; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<Course> getCourses(long userId) { ArrayList<Course> courses = new ArrayList<Course>(); String order = COURSE_C_ORDER_PRIORITY + " DESC, " + COURSE_C_TITLE + " ASC"; Cursor c = db.query(COURSE_TABLE, null, null, null, null, null, order); c.moveToFirst();// w w w . j av a2s . c o m while (c.isAfterLast() == false) { Course course = new Course(prefs.getString(PrefsActivity.PREF_STORAGE_LOCATION, "")); course.setCourseId(c.getInt(c.getColumnIndex(COURSE_C_ID))); course.setVersionId(c.getDouble(c.getColumnIndex(COURSE_C_VERSIONID))); course.setTitlesFromJSONString(c.getString(c.getColumnIndex(COURSE_C_TITLE))); course.setImageFile(c.getString(c.getColumnIndex(COURSE_C_IMAGE))); course.setLangsFromJSONString(c.getString(c.getColumnIndex(COURSE_C_LANGS))); course.setShortname(c.getString(c.getColumnIndex(COURSE_C_SHORTNAME))); course.setPriority(c.getInt(c.getColumnIndex(COURSE_C_ORDER_PRIORITY))); course.setDescriptionsFromJSONString(c.getString(c.getColumnIndex(COURSE_C_DESC))); course = this.courseSetProgress(course, userId); courses.add(course); c.moveToNext(); } c.close(); return courses; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<QuizAttempt> getAllQuizAttempts() { ArrayList<QuizAttempt> quizAttempts = new ArrayList<QuizAttempt>(); Cursor c = db.query(QUIZATTEMPTS_TABLE, null, null, null, null, null, null); c.moveToFirst();/* w w w . j a va 2s. c o m*/ while (c.isAfterLast() == false) { QuizAttempt qa = new QuizAttempt(); qa.setId(c.getInt(c.getColumnIndex(QUIZATTEMPTS_C_ID))); qa.setActivityDigest(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_ACTIVITY_DIGEST))); qa.setData(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_DATA))); qa.setSent(Boolean.parseBoolean(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_SENT)))); qa.setCourseId(c.getLong(c.getColumnIndex(QUIZATTEMPTS_C_COURSEID))); qa.setUserId(c.getLong(c.getColumnIndex(QUIZATTEMPTS_C_USERID))); qa.setScore(c.getFloat(c.getColumnIndex(QUIZATTEMPTS_C_SCORE))); qa.setMaxscore(c.getFloat(c.getColumnIndex(QUIZATTEMPTS_C_MAXSCORE))); qa.setPassed(Boolean.parseBoolean(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_PASSED)))); quizAttempts.add(qa); c.moveToNext(); } c.close(); return quizAttempts; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<Client> getClientsForUpdates(String userName, long previousSyncTime) { ArrayList<Client> clients = new ArrayList<Client>(); Client client;/* w ww . jav a 2s . com*/ String sql = "SELECT * FROM " + CLIENT_TABLE + " WHERE " + CLIENT_C_HEALTHWORKER + " = ? AND (" + CLIENT_C_SERVER_ID + " = 0 or " + CLIENT_C_MODIFIED_DATE + " > " + Long.toString(previousSyncTime) + " or " + CLIENT_DELETE_RECORD + " > 0 " + " or " + CLIENT_CLOSE_CASE + " > 0 " + ") AND " + CLIENT_LAST_CREATED + " = 0;"; Cursor c = db.rawQuery(sql, new String[] { userName }); c.moveToFirst(); while (c.isAfterLast() == false) { client = new Client(); client.setClientServerId(c.getLong(c.getColumnIndex(CLIENT_C_SERVER_ID))); client.setHealthWorker(c.getString(c.getColumnIndex(CLIENT_C_HEALTHWORKER))); client.setClientId(c.getLong(c.getColumnIndex(CLIENT_C_ID))); client.setClientName(c.getString(c.getColumnIndex(CLIENT_C_NAME))); client.setClientMobileNumber(c.getLong(c.getColumnIndex(CLIENT_C_MOBILENUMBER))); client.setClientGender(c.getString(c.getColumnIndex(CLIENT_C_GENDER))); client.setClientMaritalStatus(c.getString(c.getColumnIndex(CLIENT_C_MARITALSTATUS))); client.setClientAge(c.getInt(c.getColumnIndex(CLIENT_C_AGE))); client.setClientParity(c.getString(c.getColumnIndex(CLIENT_C_PARITY))); client.setClientLifeStage(c.getString(c.getColumnIndex(CLIENT_C_LIFESTAGE))); client.setAgeYoungestChild(c.getInt(c.getColumnIndex(CLIENT_C_AGEYOUNGESTCHILD))); client.setHusbandName(c.getString(c.getColumnIndex(CLIENT_C_HUSBANDNAME))); client.setMethodName(c.getString(c.getColumnIndex(CLIENT_C_METHODNAME))); client.setClientDeleteRecord(c.getInt(c.getColumnIndex(CLIENT_DELETE_RECORD))); client.setClientCloseCase(c.getInt(c.getColumnIndex(CLIENT_CLOSE_CASE))); client.setAdaptedMethodName( ((c.getString(c.getColumnIndex(CLIENT_ADAPTED_METHOD_NAME))).split("_")[0] != null) ? (c.getString(c.getColumnIndex(CLIENT_ADAPTED_METHOD_NAME))).split("_")[0] : ""); clients.add(client); c.moveToNext(); } return clients; }