Example usage for android.database Cursor getCount

List of usage examples for android.database Cursor getCount

Introduction

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

Prototype

int getCount();

Source Link

Document

Returns the numbers of rows in the cursor.

Usage

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

public static Hashtable<String, Object> getHeaderRecordCatchedData(String group, long serverMsgNum,
        Context context) {//from   w  w  w  .  j a  va 2  s  . co  m
    int groupid = getGroupIdFromName(group, context);

    Hashtable<String, Object> result = null;

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    Cursor c = dbread.rawQuery("SELECT _id, server_article_id, catched FROM headers WHERE subscribed_group_id="
            + groupid + " AND server_article_number=" + serverMsgNum, null);

    if (c.getCount() == 1) {
        c.moveToFirst();

        result = new Hashtable<String, Object>(3);
        result.put("id", c.getInt(0));
        result.put("server_article_id", c.getString(1));
        if (c.getInt(2) == 1)
            result.put("catched", true);
        else
            result.put("catched", false);
    }

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

    return result;
}

From source file:cn.loveapple.client.android.shiba.database.impl.BookMarkDaoImpl.java

/**
 * {@linkplain Cursor }?{@linkplain BookMarkEntity URL}???
 * //from  w ww. ja v  a2 s  .c  o m
 * @param cursor
 * @return
 */
private BookMarkEntity getUrlHistoryEntity(Cursor cursor) {
    if (cursor == null || cursor.getCount() < 1) {
        return null;
    }
    BookMarkEntity entity = new BookMarkEntity();
    entity.setUrl(cursor.getString(0));
    entity.setTitle(cursor.getString(1));
    entity.setTimestamp(new Date(cursor.getLong(2)));

    return entity;
}

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();// w w w  .  j a  va 2  s  .  c  o m
    startActivityUnderTest();

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

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

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

public void testToggleFavoritesState() {
    ContentResolver contentResolver = getInstrumentation().getContext().getContentResolver();
    deleteAllFavorites(contentResolver);
    createReportIntent();//from ww  w . ja  v a  2  s .c  o m
    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:DictionaryDatabase.java

public long findWordID(String word) {
    long returnVal = -1;
    SQLiteDatabase db = getReadableDatabase();

    Cursor cursor = db.rawQuery("SELECT _id FROM " + TABLE_DICTIONARY + " WHERE " + FIELD_WORD + " = ?",
            new String[] { word });
    if (cursor.getCount() == 1) {
        cursor.moveToFirst();/*  w w w . ja v a2s  .c o  m*/
        returnVal = cursor.getInt(0);
    }
    return returnVal;
}

From source file:DictionaryDatabase.java

public String getDefinition(long id) {
    String returnVal = "";
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT definition FROM " + TABLE_DICTIONARY + " WHERE  _id = ?",
            new String[] { String.valueOf(id) });
    if (cursor.getCount() == 1) {
        cursor.moveToFirst();//from w  ww.j  a v a2  s . co  m
        returnVal = cursor.getString(0);
    }
    return returnVal;
}

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();//from   w  w w.  jav  a2s .c  o m
    return count;
}

From source file:net.nordist.lloydproof.CorrectionStorage.java

public int count() {
    openReadDB();//  ww  w.ja  v  a  2s  .c o m
    Cursor cursor = readDB.query(TABLE_NAME, new String[] { "COUNT(1)" }, null, null, null, null, null);
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        return cursor.getInt(0);
    } else {
        return 0;
    }
}

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

public E findOne(String rawQuery, String... params) {
    if (StringUtils.isNotEmpty(rawQuery)) {
        Cursor cursor = db.rawQuery(rawQuery, params);
        if ((cursor != null) && (cursor.getCount() == 1)) {
            E entity = mapToEntities(cursor).get(0);
            cursor.close();/*from ww  w .ja v  a2 s  .c  o m*/
            return entity;
        }
    }
    return null;
}

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 w w. j a v a 2  s .c  om
            cursor.close();
        }
    }
    return new ArrayList<>();
}