List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.futureplatforms.kirin.extensions.databases.DatabasesBackend.java
public JSONArray coerceToJSONArray(String[] columnNames, Cursor cursor) { JSONArray array = new JSONArray(); while (!cursor.isAfterLast()) { JSONObject obj = coerceToJSONObject(columnNames, cursor); array.put(obj);//from www. j a v a 2 s . c om cursor.moveToNext(); } return array; }
From source file:com.guess.license.plate.Task.LoadingTaskConn.java
private ServerError insOrUpDB(JSONObject jsObj, String objJS, String[] columns, String whereClause, String[] whereArgs, ContentValues values, int serverVersion) throws JSONException { ServerError result = ServerError.NO_ERROR; Cursor cursor = db.query(objJS, columns, whereClause, whereArgs, null, null, null); int count = cursor.getCount(); if (count > 0) { // Getting the version int currDBVersion = 0; while (cursor.moveToNext()) { if (cursor.isNull(0)) currDBVersion = 0;//from w w w. j a va 2 s.c o m else currDBVersion = cursor.getInt(0); } if (objJS.equals(WebConf.JSON_OBJECTS[0])) { if (currDBVersion == serverVersion) { return ServerError.OLD_BUILD; } db.update(objJS, values, whereClause, whereArgs); } else if (objJS.equals(WebConf.JSON_OBJECTS[1])) { // In case the plate processed is a new version update it in the DB if (currDBVersion != serverVersion) { db.update(objJS, values, whereClause, whereArgs); } } else if (objJS.equals(WebConf.JSON_OBJECTS[2])) { // In case the language processed is a new version update it in the DB if (currDBVersion != serverVersion) { db.update(objJS, values, whereClause, whereArgs); } } } else { db.insert(objJS, null, values); } return result; }
From source file:at.bitfire.davdroid.resource.LocalCollection.java
/** * Finds a specific resource by ID. Only records matching sqlFilter are taken into account. * @param localID ID of the resource/* w w w. ja v a2 s . com*/ * @param populate true: populates all data fields (for instance, contact or event details); * false: only remote file name and ETag are populated * @return resource with either ID/remote file/name/ETag or all fields populated * @throws RecordNotFoundException when the resource couldn't be found * @throws LocalStorageException when the content provider couldn't be queried */ public T findById(long localID, boolean populate) throws LocalStorageException { try { @Cleanup Cursor cursor = providerClient.query(ContentUris.withAppendedId(entriesURI(), localID), new String[] { entryColumnRemoteName(), entryColumnETag() }, sqlFilter, null, null); if (cursor != null && cursor.moveToNext()) { T resource = newResource(localID, cursor.getString(0), cursor.getString(1)); if (populate) populate(resource); return resource; } else throw new RecordNotFoundException(); } catch (RemoteException ex) { throw new LocalStorageException(ex); } }
From source file:net.benmoran.affectsampler.AffectSerializer.java
public JSONArray toJSONArray() throws JSONException { Uri samples = AffectSamples.CONTENT_URI; String[] projection = new String[] { AffectSamples.COMMENT, AffectSamples.SCHEDULED_DATE, AffectSamples.CREATED_DATE, AffectSamples.EMOTION, AffectSamples.INTENSITY }; Cursor cursor = mContentResolver.query(samples, projection, null, null, AffectSamples.CREATED_DATE + " ASC"); JSONArray arr = new JSONArray(); int emIndex = cursor.getColumnIndex(AffectSamples.EMOTION); int inIndex = cursor.getColumnIndex(AffectSamples.INTENSITY); int cdIndex = cursor.getColumnIndex(AffectSamples.CREATED_DATE); int sdIndex = cursor.getColumnIndex(AffectSamples.SCHEDULED_DATE); int coIndex = cursor.getColumnIndex(AffectSamples.COMMENT); for (cursor.moveToPosition(0); !cursor.isLast(); cursor.moveToNext()) { JSONObject o = new JSONObject(); o.put(AffectSamples.EMOTION, cursor.getDouble(emIndex)); o.put(AffectSamples.INTENSITY, cursor.getDouble(inIndex)); if (cursor.getLong(sdIndex) > 0) { o.put(AffectSamples.SCHEDULED_DATE, cursor.getLong(sdIndex)); } else {// ww w . j ava2 s. c o m o.put(AffectSamples.SCHEDULED_DATE, null); } o.put(AffectSamples.CREATED_DATE, cursor.getLong(cdIndex)); if (cursor.getString(coIndex) != null) { o.put(AffectSamples.COMMENT, cursor.getString(coIndex)); } else { o.put(AffectSamples.COMMENT, null); } arr.put(o); } cursor.close(); return arr; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void logSentMessage(String msgId, String group, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); /* Check first that the number of logged messages for this group is not greater than the * limit impossed per group, because if it's greater we must delete number-limit older logs * until the table only has the limit. This is done this way because on the MessageList a set * is built with the post messages from that group, and then every loaded message's msgId is checked * to see if it's in the set (to check for replies to our messages), so allowing it to grow too much * could make the MessageView slow//from w w w .ja va 2 s.c om */ Cursor c = dbwrite.rawQuery( "SELECT _id FROM sent_posts_log WHERE subscribed_group_id=" + groupid + " ORDER BY _id", null); int count = c.getCount(); int toKill = count - UsenetConstants.SENT_POSTS_LOG_LIMIT_PER_GROUP; int kennyId; if (toKill > 0) { // Delete some more than needed so we don't have to do this on every post sent toKill += UsenetConstants.SENT_POST_KILL_ADITIONAL; c.moveToFirst(); for (int i = 0; i < toKill; i++) { kennyId = c.getInt(0); dbwrite.execSQL("DELETE FROM sent_posts_log WHERE _id=" + kennyId); c.moveToNext(); } } c.close(); // Now we have room for sure, insert the log ContentValues cv = new ContentValues(2); cv.put("server_article_id", msgId); cv.put("subscribed_group_id", groupid); dbwrite.insert("sent_posts_log", null, cv); dbwrite.close(); db.close(); }
From source file:at.bitfire.davdroid.resource.LocalGroup.java
/** * Lists all members of this group.//w ww . j a v a2s .c o m * @return list of all members' raw contact IDs * @throws ContactsStorageException on contact provider errors */ protected long[] getMembers() throws ContactsStorageException { assertID(); List<Long> members = new LinkedList<>(); try { @Cleanup Cursor cursor = addressBook.provider.query( addressBook.syncAdapterURI(ContactsContract.Data.CONTENT_URI), new String[] { Data.RAW_CONTACT_ID }, GroupMembership.MIMETYPE + "=? AND " + GroupMembership.GROUP_ROW_ID + "=?", new String[] { GroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id) }, null); while (cursor != null && cursor.moveToNext()) members.add(cursor.getLong(0)); } catch (RemoteException e) { throw new ContactsStorageException("Couldn't list group members", e); } return ArrayUtils.toPrimitive(members.toArray(new Long[members.size()])); }
From source file:com.bellman.bible.service.db.mynote.MyNoteDBAdapter.java
public List<MyNoteDto> getMyNotesInBook(BibleBook book) { Log.d(TAG, "about to getMyNotesInPassage:" + book.getOSIS()); List<MyNoteDto> notesList = new ArrayList<MyNoteDto>(); Cursor c = db.query(MyNoteQuery.TABLE, MyNoteQuery.COLUMNS, MyNoteColumn.KEY + " LIKE ?", new String[] { String.valueOf(book.getOSIS() + ".%") }, null, null, null); try {//w w w . j ava 2s. c o m if (c.moveToFirst()) { while (!c.isAfterLast()) { MyNoteDto mynote = getMyNoteDto(c); notesList.add(mynote); c.moveToNext(); } } } finally { c.close(); } Log.d(TAG, "myNotesInPassage set to " + notesList.size() + " item long list"); return notesList; }
From source file:com.lee.sdk.utils.Utils.java
/** * ?????????//ww w . j a va 2s . c o m * * @param context {@link Context} * @param shortcutName ?? * @param packageName ?? * @param uri {@link Uri} * * @return ???DB?true */ private static boolean hasShortcut(Context context, String shortcutName, String packageName, Uri uri) { if (context == null || TextUtils.isEmpty(shortcutName) || TextUtils.isEmpty(packageName) || uri == null) { return true; } boolean res = false; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, new String[] { "title", "intent" }, "title=?", new String[] { shortcutName }, null); if (cursor != null && cursor.moveToFirst()) { int index = cursor.getColumnIndex("intent"); if (index >= 0 && index < cursor.getColumnCount()) { do { String intentString = cursor.getString(index); if (intentString != null && intentString.contains(packageName)) { res = true; break; } } while (cursor.moveToNext()); } } } catch (Exception e) { res = true; } finally { if (cursor != null) { cursor.close(); cursor = null; } } return res; }
From source file:it.ms.theing.loquitur.functions.Storage.java
/** * Get a list of keys and related values * @param genre/*from w ww .j ava 2s . co m*/ * The genre of the key * @return * a string conaining a json array of json objects structure : * [ { key:<name>, value:<value>} , ... ] */ @JavascriptInterface public String getList(String genre) { Cursor cursor = dataBase.rawQuery("select * from alias where genre=?", new String[] { genre.toUpperCase() }); cursor.moveToFirst(); JSONArray ja = new JSONArray(); while (!cursor.isAfterLast()) { JSONObject jo = new JSONObject(); try { jo.put("key", cursor.getString(1)); jo.put("value", cursor.getString(2)); } catch (JSONException e) { } ja.put(jo); cursor.moveToNext(); } return ja.toString(); }
From source file:at.bitfire.davdroid.resource.LocalCollection.java
/** * Finds a specific resource by remote file name. Only records matching sqlFilter are taken into account. * @param remoteName remote file name of the resource * @param populate true: populates all data fields (for instance, contact or event details); * false: only remote file name and ETag are populated * @return resource with either ID/remote file/name/ETag or all fields populated * @throws RecordNotFoundException when the resource couldn't be found * @throws LocalStorageException when the content provider couldn't be queried *//*from w w w .j a v a 2 s . co m*/ public T findByRemoteName(String remoteName, boolean populate) throws LocalStorageException { String where = entryColumnRemoteName() + "=?"; if (sqlFilter != null) where += " AND (" + sqlFilter + ")"; try { @Cleanup Cursor cursor = providerClient.query(entriesURI(), new String[] { entryColumnID(), entryColumnRemoteName(), entryColumnETag() }, where, new String[] { remoteName }, null); if (cursor != null && cursor.moveToNext()) { T resource = newResource(cursor.getLong(0), cursor.getString(1), cursor.getString(2)); if (populate) populate(resource); return resource; } else throw new RecordNotFoundException(); } catch (RemoteException ex) { throw new LocalStorageException(ex); } }