List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<QuizAttempt> getUnsentQuizAttempts() { String s = QUIZATTEMPTS_C_SENT + "=? "; String[] args = new String[] { "0" }; Cursor c = db.query(QUIZATTEMPTS_TABLE, null, s, args, null, null, null); c.moveToFirst();//from w ww . j av a 2s .c o m ArrayList<QuizAttempt> quizAttempts = new ArrayList<QuizAttempt>(); while (c.isAfterLast() == false) { try { QuizAttempt qa = new QuizAttempt(); qa.setId(c.getLong(c.getColumnIndex(QUIZATTEMPTS_C_ID))); qa.setData(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_DATA))); qa.setUserId(c.getLong(c.getColumnIndex(QUIZATTEMPTS_C_USERID))); User u = this.getUser(qa.getUserId()); qa.setUser(u); quizAttempts.add(qa); } catch (UserNotFoundException unfe) { // do nothing } c.moveToNext(); } c.close(); return quizAttempts; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<Course> getLearningCourses(long userId) { ArrayList<Course> courses = new ArrayList<Course>(); String order = COURSE_C_ORDER_PRIORITY + " DESC, " + COURSE_C_TITLE + " ASC"; String where = COURSE_C_SHORTNAME + " NOT IN (" + MobileLearning.CLIENT_COUNSELLING_COURSES + ")"; Cursor c = db.query(COURSE_TABLE, null, where, null, null, null, order); //Cursor c = db.query(COURSE_TABLE, null, null, null, null, null, order); c.moveToFirst();/*from w w w . jav a2 s . c om*/ 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<Client> getAllClients(String userName) { String s = CLIENT_C_HEALTHWORKER + "=? "; String[] args = new String[] { userName }; Cursor c = db.query(CLIENT_TABLE, null, s, args, null, null, null); Client client;// www. j ava 2s .c o m ArrayList<Client> clients = new ArrayList<Client>(); c.moveToFirst(); while (c.isAfterLast() == false) { client = new Client(); client.setClientId(c.getInt(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.setClientLifeStage(c.getString(c.getColumnIndex(CLIENT_C_LIFESTAGE))); client.setClientParity(c.getString(c.getColumnIndex(CLIENT_C_PARITY))); client.setHealthWorker(c.getString(c.getColumnIndex(CLIENT_C_HEALTHWORKER))); client.setClientServerId(c.getLong(c.getColumnIndex(CLIENT_C_SERVER_ID))); 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(); } c.close(); return clients; }
From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java
private void openExistingChat(Cursor c) { if (c != null && (!c.isAfterLast())) { int type = c.getInt(c.getColumnIndexOrThrow(Imps.Contacts.TYPE)); String username = c.getString(c.getColumnIndexOrThrow(Imps.Contacts.USERNAME)); long providerId = c.getLong(c.getColumnIndexOrThrow(Imps.Contacts.PROVIDER)); startChat(providerId, username, type, false, null); } else//ww w. ja va2s . co m updateChatList(); }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public QuizStats getQuizAttempt(String digest, long userId) { QuizStats qs = new QuizStats(); qs.setDigest(digest);/* w w w .ja va 2 s . c o m*/ qs.setAttempted(false); qs.setPassed(false); // find if attempted String s1 = QUIZATTEMPTS_C_USERID + "=? AND " + QUIZATTEMPTS_C_ACTIVITY_DIGEST + "=?"; String[] args1 = new String[] { String.valueOf(userId), digest }; Cursor c1 = db.query(QUIZATTEMPTS_TABLE, null, s1, args1, null, null, null); if (c1.getCount() == 0) { return qs; } c1.moveToFirst(); while (c1.isAfterLast() == false) { float userScore = c1.getFloat(c1.getColumnIndex(QUIZATTEMPTS_C_SCORE)); if (userScore > qs.getUserScore()) { qs.setUserScore(userScore); } qs.setMaxScore(c1.getFloat(c1.getColumnIndex(QUIZATTEMPTS_C_MAXSCORE))); c1.moveToNext(); } c1.close(); qs.setAttempted(true); // find if passed String s2 = QUIZATTEMPTS_C_USERID + "=? AND " + QUIZATTEMPTS_C_ACTIVITY_DIGEST + "=? AND " + QUIZATTEMPTS_C_PASSED + "=1"; String[] args2 = new String[] { String.valueOf(userId), digest }; Cursor c2 = db.query(QUIZATTEMPTS_TABLE, null, s2, args2, null, null, null); if (c2.getCount() > 0) { qs.setPassed(true); } c2.close(); /* String s3 = QUIZATTEMPTS_C_USERID + "=? AND " + QUIZATTEMPTS_C_ACTIVITY_DIGEST +"=?"; String[] args3 = new String[] { String.valueOf(userId), digest }; Cursor c3 = db.query(QUIZATTEMPTS_TABLE, new String [] {"MAX("+ QUIZATTEMPTS_C_SCORE +") as userscore"}, s3, args3, null, null, null); c3.moveToFirst(); while (c3.isAfterLast() == false) { int userScore = c3.getInt(c3.getColumnIndex("userscore")); if (userScore > qs.getUserScore()){ qs.setUserScore(userScore); } Log.d(TAG, "Score: " + c3.getInt(c3.getColumnIndex("userscore"))); Log.d(TAG, "passed: " + qs.isPassed()); c3.moveToNext(); } c3.close(); */ return qs; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<ClientSession> getAllClientSessions(String userName) { String s = CLIENT_TRACKER_C_USER + "=? "; String[] args = new String[] { userName }; Cursor c = db.query(CLIENT_TRACKER_TABLE, null, s, args, null, null, null); c.moveToFirst();/*from www . j av a2 s . c o m*/ ClientSession clientSession; ArrayList<ClientSession> clientSessions = new ArrayList<ClientSession>(); while (c.isAfterLast() == false) { clientSession = new ClientSession(); clientSession.setId(c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_ID))); clientSession.setStartDateTime(c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_START))); clientSession.setClientId(c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_CLIENT))); clientSession.setHealthWorker(c.getString(c.getColumnIndex(CLIENT_TRACKER_C_USER))); clientSession.setEndDateTime(c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_END))); clientSessions.add(clientSession); c.moveToNext(); } c.close(); return clientSessions; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public boolean isPreviousSectionActivitiesCompleted(Course course, Activity activity, long userId) { // get this activity Log.d(TAG, "this digest = " + activity.getDigest()); Log.d(TAG, "this actid = " + activity.getActId()); Log.d(TAG, "this courseid = " + activity.getCourseId()); Log.d(TAG, "this sectionid = " + activity.getSectionId()); // get all the previous activities in this section String sql = String.format( "SELECT * FROM " + ACTIVITY_TABLE + " WHERE " + ACTIVITY_C_ACTID + " < %d " + " AND " + ACTIVITY_C_COURSEID + " = %d " + " AND " + ACTIVITY_C_SECTIONID + " = %d", activity.getActId(), activity.getCourseId(), activity.getSectionId()); Log.d(TAG, "sql: " + sql); Cursor c = db.rawQuery(sql, null); if (c != null && c.getCount() > 0) { c.moveToFirst();/*from ww w . j a v a 2 s . co m*/ boolean completed = true; // check if each activity has been completed or not while (c.isAfterLast() == false) { String sqlCheck = String.format("SELECT * FROM " + TRACKER_LOG_TABLE + " WHERE " + TRACKER_LOG_C_ACTIVITYDIGEST + " = '%s'" + " AND " + TRACKER_LOG_C_COMPLETED + " =1" + " AND " + TRACKER_LOG_C_USERID + " = %d", c.getString(c.getColumnIndex(ACTIVITY_C_ACTIVITYDIGEST)), userId); Cursor c2 = db.rawQuery(sqlCheck, null); if (c2 == null || c2.getCount() == 0) { completed = false; break; } c2.close(); c.moveToNext(); } c.close(); return completed; } else { c.close(); return true; } }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public boolean isPreviousCourseActivitiesCompleted(Course course, Activity activity, long userId) { Log.d(TAG, "this digest = " + activity.getDigest()); Log.d(TAG, "this actid = " + activity.getActId()); Log.d(TAG, "this courseid = " + activity.getCourseId()); Log.d(TAG, "this sectionid = " + activity.getSectionId()); // get all the previous activities in this section String sql = String.format( "SELECT * FROM " + ACTIVITY_TABLE + " WHERE (" + ACTIVITY_C_COURSEID + " = %d " + " AND " + ACTIVITY_C_SECTIONID + " < %d )" + " OR (" + ACTIVITY_C_ACTID + " < %d " + " AND " + ACTIVITY_C_COURSEID + " = %d " + " AND " + ACTIVITY_C_SECTIONID + " = %d)", activity.getCourseId(), activity.getSectionId(), activity.getActId(), activity.getCourseId(), activity.getSectionId());/*from w ww. j a v a 2 s . c o m*/ Log.d(TAG, "sql: " + sql); Cursor c = db.rawQuery(sql, null); if (c != null && c.getCount() > 0) { c.moveToFirst(); boolean completed = true; // check if each activity has been completed or not while (c.isAfterLast() == false) { String sqlCheck = String.format("SELECT * FROM " + TRACKER_LOG_TABLE + " WHERE " + TRACKER_LOG_C_ACTIVITYDIGEST + " = '%s'" + " AND " + TRACKER_LOG_C_COMPLETED + " =1" + " AND " + TRACKER_LOG_C_USERID + " = %d", c.getString(c.getColumnIndex(ACTIVITY_C_ACTIVITYDIGEST)), userId); Cursor c2 = db.rawQuery(sqlCheck, null); if (c2 == null || c2.getCount() == 0) { completed = false; break; } c2.close(); c.moveToNext(); } c.close(); return completed; } else { c.close(); return true; } }
From source file:edu.pdx.cecs.orcycle.TripUploader.java
/** * Get all sensor readings corresponding to this time index * @return/*from w w w .ja v a2 s . com*/ */ private JSONArray getJsonSensorReadings(double coordTime) { JSONArray jsonSensorReadings = null; JSONObject jsonSensorReading; int numVals; Cursor cursorSV = null; try { if (null != (cursorSV = mDb.fetchSensorValues(coordTime))) { // Collect sensor readings into a json object jsonSensorReadings = new JSONArray(); // Construct a map between cursor column index if (null == sensorColumn) { sensorColumn = new HashMap<String, Integer>(); sensorColumn.put(TRIP_COORD_SENSOR_ID, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_ID)); sensorColumn.put(TRIP_COORD_SENSOR_TYPE, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_TYPE)); sensorColumn.put(TRIP_COORD_SENSOR_SAMPLES, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_SAMPLES)); sensorColumn.put(TRIP_COORD_SENSOR_NUM_VALS, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_NUM_VALS)); sensorColumn.put(TRIP_COORD_SENSOR_AVG_0, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_AVG_0)); sensorColumn.put(TRIP_COORD_SENSOR_AVG_1, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_AVG_1)); sensorColumn.put(TRIP_COORD_SENSOR_AVG_2, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_AVG_2)); sensorColumn.put(TRIP_COORD_SENSOR_SSD_0, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_SSD_0)); sensorColumn.put(TRIP_COORD_SENSOR_SSD_1, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_SSD_1)); sensorColumn.put(TRIP_COORD_SENSOR_SSD_2, cursorSV.getColumnIndex(DbAdapter.K_SENSOR_SSD_2)); } int numSamples; while (!cursorSV.isAfterLast()) { jsonSensorReading = new JSONObject(); jsonSensorReading.put(TRIP_COORD_SENSOR_ID, cursorSV.getString(sensorColumn.get(TRIP_COORD_SENSOR_ID))); jsonSensorReading.put(TRIP_COORD_SENSOR_TYPE, cursorSV.getInt(sensorColumn.get(TRIP_COORD_SENSOR_TYPE))); jsonSensorReading.put(TRIP_COORD_SENSOR_SAMPLES, (numSamples = cursorSV.getInt(sensorColumn.get(TRIP_COORD_SENSOR_SAMPLES)))); numVals = cursorSV.getInt(sensorColumn.get(TRIP_COORD_SENSOR_NUM_VALS)); switch (numVals) { case 1: jsonSensorReading.put(TRIP_COORD_SENSOR_AVG_0, dr2(cursorSV.getDouble(sensorColumn.get(TRIP_COORD_SENSOR_AVG_0)))); if (numSamples > 0) { jsonSensorReading.put(TRIP_COORD_SENSOR_SSD_0, dr2(Math.sqrt( cursorSV.getDouble(sensorColumn.get(TRIP_COORD_SENSOR_SSD_0)) / numSamples))); } else { jsonSensorReading.put(TRIP_COORD_SENSOR_SSD_0, 0.0); } break; case 3: jsonSensorReading.put(TRIP_COORD_SENSOR_AVG_0, dr2(cursorSV.getDouble(sensorColumn.get(TRIP_COORD_SENSOR_AVG_0)))); jsonSensorReading.put(TRIP_COORD_SENSOR_AVG_1, dr2(cursorSV.getDouble(sensorColumn.get(TRIP_COORD_SENSOR_AVG_1)))); jsonSensorReading.put(TRIP_COORD_SENSOR_AVG_2, dr2(cursorSV.getDouble(sensorColumn.get(TRIP_COORD_SENSOR_AVG_2)))); if (numSamples > 0) { jsonSensorReading.put(TRIP_COORD_SENSOR_SSD_0, dr2(Math.sqrt( cursorSV.getDouble(sensorColumn.get(TRIP_COORD_SENSOR_SSD_0)) / numSamples))); jsonSensorReading.put(TRIP_COORD_SENSOR_SSD_1, dr2(Math.sqrt( cursorSV.getDouble(sensorColumn.get(TRIP_COORD_SENSOR_SSD_1)) / numSamples))); jsonSensorReading.put(TRIP_COORD_SENSOR_SSD_2, dr2(Math.sqrt( cursorSV.getDouble(sensorColumn.get(TRIP_COORD_SENSOR_SSD_2)) / numSamples))); } else { jsonSensorReading.put(TRIP_COORD_SENSOR_SSD_0, 0.0); jsonSensorReading.put(TRIP_COORD_SENSOR_SSD_1, 0.0); jsonSensorReading.put(TRIP_COORD_SENSOR_SSD_2, 0.0); } break; } jsonSensorReadings.put(jsonSensorReading); cursorSV.moveToNext(); } } } catch (Exception ex) { Log.e(MODULE_TAG, ex.getMessage()); } finally { if (null != cursorSV) { cursorSV.close(); } } return jsonSensorReadings; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public List<Long> checkSessionCorrected(long clientId, String username) { String sql = "SELECT * FROM " + CLIENT_TRACKER_TABLE + " WHERE (" + CLIENT_TRACKER_C_CLIENTSTATUS + " = 0 AND " + CLIENT_TRACKER_C_CLIENT + " = ? AND " + CLIENT_TRACKER_C_USER + " = ? );"; long trackerId; Cursor c = db.rawQuery(sql, new String[] { Long.toString(clientId), username }); List<Long> sessionsToBeCorrected = new ArrayList<Long>(); if (c.getCount() == 0) { c.close();//ww w . j a v a 2 s . co m return sessionsToBeCorrected; } else { c.moveToFirst(); while (c.isAfterLast() == false) { trackerId = c.getLong(c.getColumnIndex(CLIENT_TRACKER_C_ID)); sessionsToBeCorrected.add(trackerId); c.moveToNext(); } c.close(); return sessionsToBeCorrected; } }