List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java
@SuppressWarnings("Recycle") private void update_0_1() throws URISyntaxException { String v0_principalURL = accountManager.getUserData(account, "principal_url"), v0_addressBookPath = accountManager.getUserData(account, "addressbook_path"); Constants.log.debug("Old principal URL = " + v0_principalURL); Constants.log.debug("Old address book path = " + v0_addressBookPath); URI principalURI = new URI(v0_principalURL); // update address book if (v0_addressBookPath != null) { String addressBookURL = principalURI.resolve(v0_addressBookPath).toASCIIString(); Constants.log.debug("New address book URL = " + addressBookURL); accountManager.setUserData(account, "addressbook_url", addressBookURL); }//from w w w .java2s . c o m // update calendars ContentResolver resolver = context.getContentResolver(); Uri calendars = Calendars.CONTENT_URI.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name) .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type) .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true").build(); @Cleanup Cursor cursor = resolver.query(calendars, new String[] { Calendars._ID, Calendars.NAME }, null, null, null); while (cursor != null && cursor.moveToNext()) { int id = cursor.getInt(0); String v0_path = cursor.getString(1), v1_url = principalURI.resolve(v0_path).toASCIIString(); Constants.log.debug("Updating calendar #" + id + " name: " + v0_path + " -> " + v1_url); Uri calendar = ContentUris.appendId( Calendars.CONTENT_URI.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name) .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type) .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true"), id).build(); ContentValues newValues = new ContentValues(1); newValues.put(Calendars.NAME, v1_url); if (resolver.update(calendar, newValues, null, null) != 1) Constants.log.debug("Number of modified calendars != 1"); } accountManager.setUserData(account, "principal_url", null); accountManager.setUserData(account, "addressbook_path", null); accountManager.setUserData(account, KEY_SETTINGS_VERSION, "1"); }
From source file:heartware.com.heartware_master.DBAdapter.java
public HashMap<String, String> getProfilePassword(String id) { HashMap<String, String> profileMap = new HashMap<String, String>(); SQLiteDatabase database = this.getReadableDatabase(); String selectQuery = "SELECT " + PASSWORD + " FROM " + PROFILES_TABLE + " WHERE " + PROFILE_ID + "='" + id + "'"; Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do {//from ww w . ja va 2 s . c o m profileMap.put(PASSWORD, cursor.getString(0)); } while (cursor.moveToNext()); } return profileMap; }
From source file:it.bradipao.berengar.DbTool.java
public static JSONObject db2json(SQLiteDatabase mDB, String sDbName) { // vars/*from w w w .ja va 2 s. c om*/ JSONObject jsonDB = new JSONObject(); JSONArray jsonNameTables = new JSONArray(); JSONArray jsonTables = new JSONArray(); // read tables String sqlquery = "select * from sqlite_master"; Cursor cur = mDB.rawQuery(sqlquery, null); // iterate through tables int iTableNum = 0; String sTableName = ""; String sTableSql = ""; while (cur.moveToNext()) { sTableName = cur.getString(cur.getColumnIndex("name")); sTableSql = cur.getString(cur.getColumnIndex("sql")); if (GOLOG) Log.d(LOGTAG, "TABLE NAME : " + sTableName); // skip metadata, sequence, and uidx before exporting tables if (!sTableName.equals("android_metadata") && !sTableName.equals("sqlite_sequence") && !sTableName.startsWith("uidx") && !sTableName.startsWith("idx_") && !sTableName.startsWith("_idx")) { // add new table iTableNum++; jsonNameTables.put(sTableName); // try exporting table jsonTables.put(table2json(mDB, sTableName, sTableSql)); } } cur.close(); // final json building try { // json db format jsonDB.put("jsondb_format", "1"); // database name if ((sDbName != null) && (!sDbName.isEmpty())) jsonDB.put("db_name", sDbName); else jsonDB.put("db_name", "database.sqlite"); // tables number and name jsonDB.put("tables_num", String.valueOf(iTableNum)); jsonDB.put("tables_name", jsonNameTables); // tables jsonDB.put("tables", jsonTables); } catch (JSONException e) { Log.e(LOGTAG, "error in db2json", e); } // return String return jsonDB; }
From source file:com.hemou.android.core.sync.persistence.DatabaseCache.java
private <E> List<E> loadFromDB(final SQLiteOpenHelper helper, final PersistableResource<E> persistableResource) { final SQLiteDatabase db = getReadable(helper); if (db == null) return null; Cursor cursor = persistableResource.getCursor(db); try {/*from ww w. j a v a 2 s. c o m*/ if (!cursor.moveToFirst()) return null; List<E> cached = new ArrayList<E>(); do cached.add(persistableResource.loadFrom(cursor)); while (cursor.moveToNext()); return cached; } finally { cursor.close(); } }
From source file:com.samknows.measurement.storage.TestResultDataSource.java
private List<TestResult> getTestResults(String selection, String limit) { List<TestResult> ret = new ArrayList<TestResult>(); Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, SKSQLiteHelper.TABLE_TESTRESULT_ALLCOLUMNS, selection, null, null, null, order, limit); cursor.moveToFirst();// w w w .j a v a 2 s. c o m while (!cursor.isAfterLast()) { ret.add(cursorToTestResult(cursor)); cursor.moveToNext(); } cursor.close(); return ret; }
From source file:foam.zizim.android.BoskoiService.java
public static List<BlogData> getSimpleBlogData() { Cursor cursor; cursor = BoskoiApplication.mDb.fetchAllSimpleBlog(); List blog = new ArrayList<BlogData>(); if (cursor.moveToFirst()) { int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_ID); int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_TITLE); int dateIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_DATE); int linkIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_LINK); do {/* www .j a va 2 s . c om*/ BlogData blogData = new BlogData(); blogData.setId(Util.toInt(cursor.getString(idIndex))); blogData.setTitle(cursor.getString(titleIndex)); blogData.setLink(cursor.getString(linkIndex)); blogData.setDate(cursor.getString(dateIndex)); blog.add(blogData); } while (cursor.moveToNext()); } cursor.close(); return blog; }
From source file:cn.edu.wyu.documentviewer.RecentsProvider.java
/** * Purge all internal data whose authority matches the given * {@link Predicate}./*from w ww . jav a 2 s . c om*/ */ private void purgeByAuthority(Predicate<String> predicate) { final SQLiteDatabase db = mHelper.getWritableDatabase(); final DocumentStack stack = new DocumentStack(); Cursor cursor = db.query(TABLE_RECENT, null, null, null, null, null, null); try { while (cursor.moveToNext()) { try { final byte[] rawStack = cursor.getBlob(cursor.getColumnIndex(RecentColumns.STACK)); DurableUtils.readFromArray(rawStack, stack); if (stack.root != null && predicate.apply(stack.root.authority)) { final String key = getCursorString(cursor, RecentColumns.KEY); db.delete(TABLE_RECENT, RecentColumns.KEY + "=?", new String[] { key }); } } catch (IOException ignored) { } } } finally { //IoUtils.closeQuietly(cursor); IOUtils.closeQuietly(cursor); } cursor = db.query(TABLE_STATE, new String[] { StateColumns.AUTHORITY }, null, null, StateColumns.AUTHORITY, null, null); try { while (cursor.moveToNext()) { final String authority = getCursorString(cursor, StateColumns.AUTHORITY); if (predicate.apply(authority)) { db.delete(TABLE_STATE, StateColumns.AUTHORITY + "=?", new String[] { authority }); Log.d(TAG, "Purged state for " + authority); } } } finally { //IoUtils.closeQuietly(cursor); IOUtils.closeQuietly(cursor); } cursor = db.query(TABLE_RESUME, null, null, null, null, null, null); try { while (cursor.moveToNext()) { try { final byte[] rawStack = cursor.getBlob(cursor.getColumnIndex(ResumeColumns.STACK)); DurableUtils.readFromArray(rawStack, stack); if (stack.root != null && predicate.apply(stack.root.authority)) { final String packageName = getCursorString(cursor, ResumeColumns.PACKAGE_NAME); db.delete(TABLE_RESUME, ResumeColumns.PACKAGE_NAME + "=?", new String[] { packageName }); } } catch (IOException ignored) { } } } finally { //IoUtils.closeQuietly(cursor); IOUtils.closeQuietly(cursor); } }
From source file:com.smarthome.deskclock.Alarms.java
public static Alarm calculateNextAlert(final Context context) { Alarm alarm = null;/* w ww . j av a 2 s . com*/ long minTime = Long.MAX_VALUE; long now = System.currentTimeMillis(); Cursor cursor = getFilteredAlarmsCursor(context.getContentResolver()); if (cursor != null) { if (cursor.moveToFirst()) { do { Alarm a = new Alarm(cursor); // A time of 0 indicates this is a repeating alarm, so // calculate the time to get the next alert. if (a.time == 0) { a.time = calculateAlarm(a); } else if (a.time < now) { Log.v("Disabling expired alarm set for " + Log.formatTime(a.time)); // Expired alarm, disable it and move along. enableAlarmInternal(context, a, false); continue; } if (a.time < minTime) { minTime = a.time; alarm = a; } } while (cursor.moveToNext()); } cursor.close(); } return alarm; }
From source file:com.googlecode.android_scripting.facade.ContactsFacade.java
/** * Exactly as per <a href=/*from w ww. j av a 2s . c o m*/ * "http://developer.android.com/reference/android/content/ContentResolver.html#query%28android.net.Uri,%20java.lang.String[],%20java.lang.String,%20java.lang.String[],%20java.lang.String%29" * >ContentResolver.query</a> */ @Rpc(description = "Content Resolver Query", returns = "result of query as Maps") public List<JSONObject> queryContent( @RpcParameter(name = "uri", description = "The URI, using the content:// scheme, for the content to retrieve.") String uri, @RpcParameter(name = "attributes", description = "A list of which columns to return. Passing null will return all columns") @RpcOptional JSONArray attributes, @RpcParameter(name = "selection", description = "A filter declaring which rows to return") @RpcOptional String selection, @RpcParameter(name = "selectionArgs", description = "You may include ?s in selection, which will be replaced by the values from selectionArgs") @RpcOptional JSONArray selectionArgs, @RpcParameter(name = "order", description = "How to order the rows") @RpcOptional String order) throws JSONException { List<JSONObject> result = new ArrayList<JSONObject>(); String[] columns = jsonToArray(attributes); String[] args = jsonToArray(selectionArgs); Cursor cursor = mContentResolver.query(Uri.parse(uri), columns, selection, args, order); if (cursor != null) { String[] names = cursor.getColumnNames(); while (cursor.moveToNext()) { JSONObject message = new JSONObject(); for (int i = 0; i < cursor.getColumnCount(); i++) { String key = names[i]; String value = cursor.getString(i); message.put(key, value); } result.add(message); } cursor.close(); } return result; }