List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.clutch.ClutchStats.java
public ArrayList<ABRow> getABLogs() { SQLiteDatabase db = getReadableDatabase(); String[] args = {};/*from www. j av a2 s .c o m*/ ArrayList<ABRow> res = new ArrayList<ABRow>(); Cursor cur = db.rawQuery("SELECT uuid, ts, data FROM ablog ORDER BY ts", args); cur.moveToFirst(); while (!cur.isAfterLast()) { String uuid = cur.getString(0); double ts = cur.getDouble(1); JSONObject data; try { data = new JSONObject(cur.getString(2)); } catch (JSONException e) { Log.w(TAG, "Could not serialize to JSON: " + cur.getString(3)); cur.moveToNext(); continue; } res.add(new ABRow(uuid, ts, data)); cur.moveToNext(); } db.close(); return res; }
From source file:com.example.cmput301.model.DatabaseManager.java
/** * Get the local task list./*from w ww . j av a 2s . c o m*/ * * @return A list of tasks in the local table of the database * @throws JSONException */ public ArrayList<Task> getLocalTaskList() { try { ArrayList<Task> out = new ArrayList<Task>(); Cursor c = db.rawQuery("SELECT * FROM " + StringRes.LOCAL_TASK_TABLE_NAME, new String[] {}); if (c.moveToFirst()) { while (c.isAfterLast() == false) { JSONObject obj = toJsonTask(c.getString(c.getColumnIndex(StringRes.COL_CONTENT))); out.add(toTask(obj)); c.moveToNext(); } return out; } } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
private void mergeDbs() { Log.d(LOG_TAG, "update received - juggling dbs"); // Get main database, attach temp db to it. SQLiteDatabase mainDb = dataService.getHelper().getWritableDatabase(); mainDb.execSQL("attach database ? as ka_temp", new Object[] { dataService.getDatabasePath("ka_temp").getAbsolutePath() }); mainDb.beginTransaction();// w ww.j a va2 s . c o m try { // Maintain download status. String sql = "select max(download_status), dlm_id, youtube_id from video where download_status != ? group by youtube_id"; Cursor c = mainDb.rawQuery(sql, new String[] { "" + Video.DL_STATUS_NOT_STARTED }); Cursor c1; String[] videoIds = new String[c.getCount()]; int i = 0; while (c.moveToNext()) { String youtube_id = c.getString(c.getColumnIndex("youtube_id")); String download_status = c.getString(c.getColumnIndex("max(download_status)")); long dlm_id = c.getLong(c.getColumnIndex("dlm_id")); videoIds[i++] = youtube_id; ContentValues v = new ContentValues(); v.put("download_status", download_status); v.put("dlm_id", dlm_id); String[] idArg = new String[] { youtube_id }; mainDb.update("ka_temp.video", v, "youtube_id = ?", idArg); // cursor over parent topics of this video sql = "select ka_temp.topic._id from ka_temp.topic, ka_temp.topicvideo, ka_temp.video where ka_temp.video.youtube_id=? and ka_temp.topicvideo.video_id=ka_temp.video.readable_id and ka_temp.topicvideo.topic_id=ka_temp.topic._id"; c1 = mainDb.rawQuery(sql, idArg); Log.d(LOG_TAG, String.format("updating counts for %d topics", c1.getCount())); while (c1.moveToNext()) { String topicId = c1.getString(c1.getColumnIndex("_id")); DatabaseHelper.incrementDownloadedVideoCounts(mainDb, topicId, "ka_temp.topic"); } c1.close(); } c.close(); mainDb.execSQL("delete from topic"); mainDb.execSQL("insert into topic select * from ka_temp.topic"); mainDb.execSQL("delete from topicvideo"); mainDb.execSQL("insert into topicvideo select * from ka_temp.topicvideo"); mainDb.execSQL("delete from video"); mainDb.execSQL("insert into video select * from ka_temp.video"); mainDb.setTransactionSuccessful(); } finally { mainDb.endTransaction(); mainDb.execSQL("detach database ka_temp"); } Log.d(LOG_TAG, "finished juggling"); }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesTerminalSailingSpaceSyncService.java
/** * Check the ferries terminal space sailing table for any starred entries. * If we find some, save them to a list so we can re-star those after we * flush the database.// ww w . j a v a2 s . c o m */ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(FerriesTerminalSailingSpace.CONTENT_URI, new String[] { FerriesTerminalSailingSpace.TERMINAL_ID }, FerriesTerminalSailingSpace.TERMINAL_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:com.example.cmput301.model.DatabaseManager.java
/** * Get the remote task list.//from ww w. ja v a 2s. c o m * * @return A list of tasks in the remote table of the database * @throws JSONException */ //fixed public ArrayList<Task> getRemoteTaskList() { try { Log.d("refresh", "STARTING REMOTE TASK LIST"); ArrayList<Task> out = new ArrayList<Task>(); Cursor c = db.rawQuery("SELECT * FROM " + StringRes.REMOTE_TASK_TABLE_NAME, new String[] {}); if (c.moveToFirst()) { while (c.isAfterLast() == false) { JSONObject obj = toJsonTask(c.getString(c.getColumnIndex(StringRes.COL_CONTENT))); out.add(toTask(obj)); c.moveToNext(); } } Log.d("refresh", "sizeof remotetasklist = " + out.size()); return out; } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:com.dileepindia.cordova.sms.SMSPlugin.java
private PluginResult deleteSMS(JSONObject filter, CallbackContext callbackContext) { Log.d("SMSPlugin", "deleteSMS"); String uri_filter = filter.has("box") ? filter.optString("box") : "inbox"; int fread = filter.has("read") ? filter.optInt("read") : -1; int fid = filter.has("_id") ? filter.optInt("_id") : -1; String faddress = filter.optString("address"); String fcontent = filter.optString("body"); Context ctx = this.cordova.getActivity(); int n = 0;//w ww. j ava 2 s. co m try { Uri uri = Uri.parse("content://sms/" + uri_filter); Cursor cur = ctx.getContentResolver().query(uri, null, "", null, null); while (cur.moveToNext()) { int id = cur.getInt(cur.getColumnIndex("_id")); boolean matchId = (fid > -1) && (fid == id); int read = cur.getInt(cur.getColumnIndex("read")); boolean matchRead = (fread > -1) && (fread == read); String address = cur.getString(cur.getColumnIndex("address")).trim(); boolean matchAddr = (faddress.length() > 0) && (address.equals(faddress)); String body = cur.getString(cur.getColumnIndex("body")).trim(); boolean matchContent = (fcontent.length() > 0) && (body.equals(fcontent)); if ((matchId) || (matchRead) || (matchAddr) || (matchContent)) { ctx.getContentResolver().delete(uri, "_id=" + id, null); n++; } } callbackContext.success(n); } catch (Exception e) { callbackContext.error(e.toString()); } return null; }
From source file:cn.apputest.ctria.service.UploadFailRecordService.java
public void uploadrecord() { Cursor cars = mgr.queryTheCursorCarsFailUpload(); List<CarsFailUploadDataEntity> list_c = new ArrayList<CarsFailUploadDataEntity>(); if (cars.getCount() != 0) { System.out.println("???"); while (cars.moveToNext()) { CarsFailUploadDataEntity carsfailupload = new CarsFailUploadDataEntity(); carsfailupload.setUserID(cars.getString(cars.getColumnIndex("userID"))); carsfailupload.setBaseStationID(cars.getString(cars.getColumnIndex("baseStationID"))); carsfailupload.setIsOverWeight(cars.getString(cars.getColumnIndex("isOverWeight"))); carsfailupload.setStatus4PermitRunCert(cars.getString(cars.getColumnIndex("status4PermitRunCert"))); carsfailupload.setStatus4TransportCert_Head( cars.getString(cars.getColumnIndex("status4TransportCert_Head"))); carsfailupload.setStatus4TransportCert_Tail( cars.getString(cars.getColumnIndex("status4TransportCert_Tail"))); carsfailupload.setStatus4InsuranceCert_Head( cars.getString(cars.getColumnIndex("status4InsuranceCert_Head"))); carsfailupload.setStatus4InsuranceCert_Cargo( cars.getString(cars.getColumnIndex("status4InsuranceCert_Cargo"))); carsfailupload.setStatus4InsuranceCert_Tail( cars.getString(cars.getColumnIndex("status4InsuranceCert_Tail"))); carsfailupload.setStatus4SpecialEquipUsage( cars.getString(cars.getColumnIndex("status4SpecialEquipUsage"))); carsfailupload.setPlateNumber(cars.getString(cars.getColumnIndex("plateNumber"))); carsfailupload.setID(cars.getInt(cars.getColumnIndex("ID"))); list_c.add(carsfailupload);/*from w w w . ja v a2 s .c o m*/ } cars.close(); for (CarsFailUploadDataEntity carsFailUploadDataEntity : list_c) { postcarcheckrecord(carsFailUploadDataEntity); if (IsOK) { mgr.DeleteCarsFailUpload(carsFailUploadDataEntity.getID()); System.out.println("?"); } } } else { System.out.println("???"); } /** * ? */ Cursor people = mgr.queryTheCursorPeopleFailUpload(); List<PeopleFailUploadDataEntity> list_p = new ArrayList<PeopleFailUploadDataEntity>(); if (people.getCount() != 0) { System.out.println("???"); while (people.moveToNext()) { PeopleFailUploadDataEntity peoplefailupload = new PeopleFailUploadDataEntity(); peoplefailupload.setUserID(people.getString(people.getColumnIndex("userID"))); peoplefailupload.setBaseStationID(people.getString(people.getColumnIndex("baseStationID"))); peoplefailupload .setStatus4DriverLicense(people.getString(people.getColumnIndex("status4DriverLicense"))); peoplefailupload.setStatus4JobCert(people.getString(people.getColumnIndex("status4JobCert"))); peoplefailupload.setID(people.getInt(people.getColumnIndex("ID"))); peoplefailupload.setDriverName(people.getString(people.getColumnIndex("driverName"))); list_p.add(peoplefailupload); } people.close(); for (PeopleFailUploadDataEntity peopleFailUploadDataEntity : list_p) { postpersoncheckrecord(peopleFailUploadDataEntity); if (IsOK) { mgr.DeletePeopleFailUpload(peopleFailUploadDataEntity.getID()); System.out.println("?"); } } } else { System.out.println("???"); } // stopSelf(); }
From source file:com.hichinaschool.flashcards.libanki.Tags.java
public void bulkAdd(List<Long> ids, String tags, boolean add) { List<String> newTags = split(tags); if (newTags == null || newTags.isEmpty()) { return;/* www. ja va 2 s . com*/ } // cache tag names register(newTags); // find notes missing the tags String l; if (add) { l = "tags not "; } else { l = "tags "; } StringBuilder lim = new StringBuilder(); for (String t : newTags) { if (lim.length() != 0) { lim.append(" or "); } lim.append(l).append("like '% ").append(t).append(" %'"); } Cursor cur = null; List<Long> nids = new ArrayList<Long>(); ArrayList<Object[]> res = new ArrayList<Object[]>(); try { cur = mCol.getDb().getDatabase().rawQuery( "select id, tags from notes where id in " + Utils.ids2str(ids) + " and (" + lim + ")", null); if (add) { while (cur.moveToNext()) { nids.add(cur.getLong(0)); res.add(new Object[] { addToStr(tags, cur.getString(1)), Utils.intNow(), mCol.usn(), cur.getLong(0) }); } } else { while (cur.moveToNext()) { nids.add(cur.getLong(0)); res.add(new Object[] { remFromStr(tags, cur.getString(1)), Utils.intNow(), mCol.usn(), cur.getLong(0) }); } } } finally { if (cur != null) { cur.close(); } } // update tags mCol.getDb().executeMany("update notes set tags=:t,mod=:n,usn=:u where id = :id", res); }
From source file:com.ubikod.urbantag.model.TagManager.java
/** * Get all tags from a pivot table/*ww w .j a v a 2s . c o m*/ * @param pivotTable pivot table name * @param pivotColumn pivot table column * @param id * @return */ private List<Tag> dbGetAllFor(String pivotTable, String pivotColumn, int id) { open(); String query = "SELECT " + DatabaseHelper.TAG_COL_ID + ", " + DatabaseHelper.TAG_COL_NAME + ", " + DatabaseHelper.TAG_COL_COLOR + ", " + DatabaseHelper.TAG_COL_NOTIFY + " FROM " + DatabaseHelper.TABLE_TAGS + " tags INNER JOIN " + pivotTable + " pivot ON tags." + DatabaseHelper.TAG_COL_ID + "=pivot." + DatabaseHelper.CONTENT_TAG_COL_TAG + " WHERE pivot." + pivotColumn + "=?"; Cursor c = mDB.rawQuery(query, new String[] { String.valueOf(id) }); List<Tag> tags = new ArrayList<Tag>(); if (c.getCount() == 0) { c.close(); close(); return tags; } c.moveToFirst(); do { Tag t = cursorToTag(c); tags.add(t); } while (c.moveToNext()); c.close(); close(); return tags; }
From source file:mobisocial.socialkit.musubi.Musubi.java
public DbIdentity userForGlobalId(Uri feedUri, String personId) { byte[] idHash = MusubiUtil.convertToByteArray(personId); long shortHash = MusubiUtil.shortHash(idHash); Uri uri = new Uri.Builder().scheme("content").authority(Musubi.AUTHORITY) .appendPath(DbThing.MEMBER.toString()).appendPath(feedUri.getLastPathSegment()).build(); String selection = DbIdentity.COL_ID_SHORT_HASH + " = ?"; String[] selectionArgs = new String[] { Long.toString(shortHash) }; String sortOrder = null;/*from w w w . j a v a 2s . c om*/ Cursor c = mContext.getContentResolver().query(uri, DbIdentity.COLUMNS, selection, selectionArgs, sortOrder); try { while (c != null && c.moveToNext()) { DbIdentity mate = DbIdentity.fromStandardCursor(mContext, c); if (mate.getId().equals(personId)) { return mate; } } Log.e(TAG, "id not found #" + shortHash); return null; } finally { if (c != null) { c.close(); } } }