Example usage for android.database Cursor close

List of usage examples for android.database Cursor close

Introduction

In this page you can find the example usage for android.database Cursor close.

Prototype

void close();

Source Link

Document

Closes the Cursor, releasing all of its resources and making it completely invalid.

Usage

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static List<MhSpRequest> listLatestRequests(Context context, String trollId, int count) {
    List<MhSpRequest> result = new ArrayList<MhSpRequest>();

    String query = String.format(SQL_LIST_REQUESTS, count);

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Calendar calendar = Calendar.getInstance();

    Cursor cursor = database.rawQuery(query, new String[] { trollId });
    while (cursor.moveToNext()) {
        long startTimeMillis = cursor.getLong(0);
        long endTimeMillis = cursor.getLong(1);
        String scriptName = cursor.getString(2);
        String status = cursor.getString(3);

        calendar.setTimeInMillis(startTimeMillis);
        Date date = calendar.getTime();
        PublicScript script = PublicScript.valueOf(scriptName);

        long duration = 0;
        if (endTimeMillis > 0) {
            duration = endTimeMillis - startTimeMillis;
        }// ww  w .  j av a  2s.  c  o  m
        MhSpRequest request = new MhSpRequest(date, duration, script, status);
        result.add(request);
    }

    cursor.close();
    database.close();

    return result;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static Vector<Object> isHeaderInDatabase(Long number, String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();
    Vector<Object> retVal = null;

    String q = "SELECT _id, server_article_id FROM headers WHERE subscribed_group_id=" + groupid
            + " AND server_article_number=" + number;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    if (count > 0) {
        c.moveToFirst();//  w w  w . ja  v a2  s  . com
        retVal = new Vector<Object>(2);
        retVal.add(c.getLong(0));
        retVal.add(c.getString(1));
    }

    c.close();
    dbread.close();
    db.close();

    return retVal;
}

From source file:com.facebook.Settings.java

/**
 * Acquire the current attribution id from the facebook app.
 * @return returns null if the facebook app is not present on the phone.
 *//*from w  w  w  . j  a v a2s  . co  m*/
public static String getAttributionId(ContentResolver contentResolver) {
    Cursor c = null;
    try {
        String[] projection = { ATTRIBUTION_ID_COLUMN_NAME };
        c = contentResolver.query(ATTRIBUTION_ID_CONTENT_URI, projection, null, null, null);
        if (c == null || !c.moveToFirst()) {
            return null;
        }
        String attributionId = c.getString(c.getColumnIndex(ATTRIBUTION_ID_COLUMN_NAME));
        return attributionId;
    } catch (Exception e) {
        Log.d(TAG, "Caught unexpected exception in getAttributionId(): " + e.toString());
        return null;
    } finally {
        if (c != null) {
            c.close();
        }
    }
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static Vector<Long> getUnreadNoncatchedArticleList(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    Vector<Long> artList = null;
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String q = "SELECT server_article_number FROM headers WHERE subscribed_group_id=" + groupid
            + " AND read=0 AND catched=0";
    Cursor c = dbread.rawQuery(q, null);

    int count = c.getCount();
    artList = new Vector<Long>(count);

    c.moveToFirst();//from  w w w. j  av a 2s  .  c om

    for (int i = 0; i < count; i++) {
        artList.add(c.getLong(0));
        c.moveToNext();
    }

    c.close();
    dbread.close();
    db.close();
    return artList;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static HashSet<String> getGroupSentMessagesSet(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    HashSet<String> retVal = null;
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String q = "SELECT server_article_id FROM sent_posts_log WHERE subscribed_group_id=" + groupid;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    retVal = new HashSet<String>(count);
    c.moveToFirst();//from   ww  w .  j a v a 2  s.  c  o m

    for (int i = 0; i < count; i++) {
        retVal.add(c.getString(0));
        c.moveToNext();
    }

    c.close();
    dbread.close();
    db.close();

    return retVal;
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.viewer.ReportViewPageTest.java

public void testRemoveFromFavorites() {
    ContentResolver contentResolver = getInstrumentation().getContext().getContentResolver();
    deleteAllFavorites(contentResolver);
    favoritesHelper.addToFavorites(mResource);

    createReportIntent();//from  w w w. ja v  a  2 s  . c om
    startActivityUnderTest();

    onView(withId(R.id.favoriteAction)).perform(click());

    Cursor cursor = getAllFavorites(contentResolver);
    assertThat(cursor.getCount(), is(0));
    cursor.close();
}

From source file:net.eledge.android.toolkit.db.abstracts.Dao.java

public int count() {
    Cursor cursor = db.rawQuery(SQLBuilder.findAll(clazz), null);
    int count = cursor.getCount();
    cursor.close();
    return count;
}

From source file:Main.java

@Nullable
public static File getFromMediaUri(Context context, ContentResolver resolver, Uri uri) {
    if (uri == null)
        return null;

    if (SCHEME_FILE.equals(uri.getScheme())) {
        return new File(uri.getPath());
    } else if (SCHEME_CONTENT.equals(uri.getScheme())) {
        final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME };
        Cursor cursor = null;
        try {/* www  .j av a  2 s .co m*/
            cursor = resolver.query(uri, filePathColumn, null, null, null);
            if (cursor != null && cursor.moveToFirst()) {
                final int columnIndex = (uri.toString().startsWith("content://com.google.android.gallery3d"))
                        ? cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)
                        : cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
                // Picasa images on API 13+
                if (columnIndex != -1) {
                    String filePath = cursor.getString(columnIndex);
                    if (!TextUtils.isEmpty(filePath)) {
                        return new File(filePath);
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            // Google Drive images
            return getFromMediaUriPfd(context, resolver, uri);
        } catch (SecurityException ignored) {
            // Nothing we can do
        } finally {
            if (cursor != null)
                cursor.close();
        }
    }
    return null;
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.viewer.ReportViewPageTest.java

public void testToggleFavoritesState() {
    ContentResolver contentResolver = getInstrumentation().getContext().getContentResolver();
    deleteAllFavorites(contentResolver);
    createReportIntent();//from   www . java 2s. com
    startActivityUnderTest();

    for (int i = 0; i < 2; i++) {
        onView(withId(R.id.favoriteAction)).perform(click());
        Cursor cursor = getAllFavorites(contentResolver);
        assertThat(cursor.getCount(), is(not(0)));
        cursor.close();

        onView(withId(R.id.favoriteAction)).perform(click());
        cursor = getAllFavorites(contentResolver);
        assertThat(cursor.getCount(), is(0));
        cursor.close();
    }
}

From source file:fr.mixit.android.io.RemoteSessionsHandler.java

private static boolean isSessionUpdated(Uri uri, JSONObject session, ContentResolver resolver)
        throws JSONException {
    final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null);
    try {//from w w  w  .j a v  a2 s  .c o  m
        if (!cursor.moveToFirst())
            return false;

        final String curTitle = cursor.getString(SessionsQuery.TITLE).toLowerCase().trim();
        final String curSummary = cursor.getString(SessionsQuery.SUMMARY).toLowerCase().trim();
        final String curTrackId = cursor.getString(SessionsQuery.TRACK_ID) != null
                ? cursor.getString(SessionsQuery.TRACK_ID).toLowerCase().trim()
                : "";
        final String newTitle = session.getString("name").toLowerCase().trim();
        final String newSummary = session.getString("description").toLowerCase().trim();
        final String newTrackId = session.has("track") ? session.getString("track").toLowerCase().trim() : "";

        return (!curTitle.equals(newTitle) || !curSummary.equals(newSummary) || !curTrackId.equals(newTrackId));
    } finally {
        cursor.close();
    }
}