List of usage examples for android.database Cursor close
void close();
From source file:com.yozio.android.YozioDataStoreImpl.java
public int getNumEvents() { synchronized (this) { int count = -1; try {/*from w w w . j a va 2 s . co m*/ Cursor cursor = dbHelper.getReadableDatabase() .rawQuery("SELECT COUNT(*) FROM " + EVENTS_TABLE + where(), null); cursor.moveToFirst(); count = cursor.getInt(0); cursor.close(); } catch (SQLiteException e) { Log.e(LOGTAG, "getNumEvents", e); } finally { dbHelper.close(); } return count; } }
From source file:com.googlecode.android_scripting.facade.SmsFacade.java
@Rpc(description = "Returns a List of all message IDs.") public List<Integer> smsGetMessageIds(@RpcParameter(name = "unreadOnly") Boolean unreadOnly, @RpcParameter(name = "folder") @RpcDefault("inbox") String folder) { Uri uri = buildFolderUri(folder);/*from ww w. j a v a 2 s. co m*/ List<Integer> result = new ArrayList<Integer>(); String selection = buildSelectionClause(unreadOnly); String[] columns = { "_id" }; Cursor cursor = mContentResolver.query(uri, columns, selection, null, null); while (cursor != null && cursor.moveToNext()) { result.add(cursor.getInt(0)); } cursor.close(); return result; }
From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java
private List<String> getExistingFields(Class<?> clazz) { List<String> names = new ArrayList<>(); StringBuilder sb = new StringBuilder("pragma table_info("); sb.append(SQLBuilder.getTableName(clazz)); sb.append(");"); Cursor cursor = db.rawQuery(sb.toString(), new String[] {}); if ((cursor != null) && cursor.moveToFirst()) { do {//from w ww . j a v a2 s.c o m names.add(cursor.getString(1)); } while (cursor.moveToNext()); cursor.close(); } return names; }
From source file:asu.edu.msse.gpeddabu.moviedescriptions.AddMovie.java
public void getGenreList() { genreArr = new ArrayList<>(); try {//from www .j av a 2 s .c o m MovieDB db = new MovieDB(con); SQLiteDatabase crsDB = db.openDB(); Cursor cur = crsDB.rawQuery("select distinct genre from movie;", null); while (cur.moveToNext()) { genreArr.add(cur.getString(0)); } cur.close(); crsDB.close(); db.close(); } catch (Exception ex) { android.util.Log.w(this.getClass().getSimpleName(), "Exception getting genre info: " + ex.getMessage()); } }
From source file:pl.selvin.android.syncframework.content.TableInfo.java
public boolean hasDirtData(SQLiteDatabase db) { Cursor c = db.query(name, null, _.isDirtyP, new String[] { "1" }, null, null, null); if (c.moveToFirst()) { c.close(); return true; }//from w w w .j a v a2 s .co m c.close(); return false; }
From source file:com.mobileaffairs.seminar.videolib.VideoLibSyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {//ww w . j a v a2s.c o m String videosJson = readVideosFromRemoteService(); try { JSONArray jsonArray = new JSONArray(videosJson); Log.i("SyncAdapter", "Number of entries " + jsonArray.length()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Cursor cs = provider.getLocalContentProvider().query( Uri.parse(VideoLibContentProvider.CONTENT_URI + "/" + jsonObject.getString("id")), null, null, null, null); long count = cs.getCount(); cs.close(); if (count == 0) { ContentValues values = new ContentValues(); values.put("_id", jsonObject.getString("id")); values.put("title", jsonObject.getString("title")); values.put("duration", jsonObject.getString("duration")); values.put("videoUrl", jsonObject.getString("url")); byte[] imageBytes = readImage(jsonObject.getString("thumbnail_small")); if (imageBytes != null && imageBytes.length > 0) { values.put("thumbnail", imageBytes); } provider.getLocalContentProvider().insert(VideoLibContentProvider.CONTENT_URI, values); } syncResult.fullSyncRequested = true; } } catch (Exception e) { e.printStackTrace(); } }
From source file:net.eledge.android.toolkit.db.abstracts.Dao.java
public List<E> find(String rawQuery, String... params) { Cursor cursor = db.rawQuery(rawQuery, params); if (cursor != null) { if (cursor.getCount() > 0) { // mapToEntities will close cursor return mapToEntities(cursor); } else {//from w ww. j av a2 s . com cursor.close(); } } return new ArrayList<>(); }
From source file:com.pdftron.pdf.utils.Utils.java
public static String getUriDisplayName(Context context, Uri contentUri) { String displayName = null;/* w w w . j a v a2 s. co m*/ String[] projection = { OpenableColumns.DISPLAY_NAME }; Cursor cursor = null; if (contentUri.getScheme().equalsIgnoreCase("file")) { return contentUri.getLastPathSegment(); } try { cursor = context.getContentResolver().query(contentUri, projection, null, null, null); if (cursor != null && cursor.moveToFirst()) { int nameIndex = cursor.getColumnIndexOrThrow(projection[0]); if (nameIndex >= 0) { displayName = cursor.getString(nameIndex); } } } catch (Exception e) { displayName = null; } if (cursor != null) { cursor.close(); } return displayName; }
From source file:info.staticfree.android.units.UnitUsageDBHelper.java
/** * Increments the usage counter for the given unit. * @param unit name of the unit/*from www . java 2 s.co m*/ * @param db the unit usage database */ public static void logUnitUsed(String unit, ContentResolver cr) { final String[] selectionArgs = { unit }; final Cursor c = cr.query(UsageEntry.CONTENT_URI, INCREMENT_QUERY_PROJECTION, UsageEntry._UNIT + "=?", selectionArgs, null); if (c.getCount() > 0) { c.moveToFirst(); final int useCount = c.getInt(c.getColumnIndex(UsageEntry._USE_COUNT)); final int id = c.getInt(c.getColumnIndex(UsageEntry._ID)); final ContentValues cv = new ContentValues(); cv.put(UsageEntry._USE_COUNT, useCount + 1); cr.update(ContentUris.withAppendedId(UsageEntry.CONTENT_URI, id), cv, null, null); } else { final ContentValues cv = new ContentValues(); cv.put(UsageEntry._UNIT, unit); cv.put(UsageEntry._USE_COUNT, 1); cv.put(UsageEntry._FACTOR_FPRINT, getFingerprint(unit)); cr.insert(UsageEntry.CONTENT_URI, cv); } c.close(); }
From source file:com.ruuhkis.cookies.CookieSQLSource.java
/** * // www .ja v a2 s . c o m * @return a list of all cookies stored in cookies table */ public List<SQLCookie> getCookies() { List<SQLCookie> cookies = new ArrayList<SQLCookie>(); Cursor cursor = db.query(CookieSQLHelper.COOKIE_TABLE_NAME, null, null, null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { cookies.add(cursorToCookie(cursor)); cursor.moveToNext(); } cursor.close(); return cookies; }