Example usage for android.database Cursor getInt

List of usage examples for android.database Cursor getInt

Introduction

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

Prototype

int getInt(int columnIndex);

Source Link

Document

Returns the value of the requested column as an int.

Usage

From source file:com.liferay.alerts.model.Alert.java

public Alert(Cursor cursor) {
    _id = cursor.getLong(cursor.getColumnIndex(ID));
    _userId = cursor.getLong(cursor.getColumnIndex(USER_ID));

    try {/*from  w  w  w  .  j ava2 s  . c om*/
        _payload = new JSONObject(cursor.getString(cursor.getColumnIndex(PAYLOAD)));
    } catch (JSONException je) {
    }

    _read = (cursor.getInt(cursor.getColumnIndex(READ)) == 1);
    _timestamp = cursor.getLong(cursor.getColumnIndex(TIMESTAMP));
}

From source file:com.manning.androidhacks.hack023.dao.TodoDAO.java

public Todo isTodoInDb(ContentResolver contentResolver, Long serverId) {
    Todo todo = null;/*from   w  w w  .  j a v  a2 s .co  m*/

    Cursor cursor = contentResolver.query(TodoContentProvider.CONTENT_URI, null,
            TodoContentProvider.COLUMN_SERVER_ID + "=" + serverId, null, null);

    if (cursor.moveToNext()) {
        String name = cursor.getString(cursor.getColumnIndexOrThrow(TodoContentProvider.COLUMN_TITLE));
        int status = cursor.getInt(cursor.getColumnIndexOrThrow(TodoContentProvider.COLUMN_STATUS_FLAG));

        todo = new Todo();
        todo.setId(serverId);
        todo.setTitle(name);
        todo.setStatus(status);
    }

    cursor.close();
    return todo;
}

From source file:foam.zizim.android.BoskoiService.java

public static CategoriesData[] getParentCategories() {
    Cursor cursor = BoskoiApplication.mDb.fetchParentCategories();
    CategoriesData result[] = new CategoriesData[cursor.getCount()];

    int i = 0;//from w w  w. j  a  v  a 2 s .c o m
    if (cursor.moveToFirst()) {
        int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE);
        int titleNL = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_NL);
        int titleLA = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_LA);
        int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_ID);
        int parentId = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_PARENT_ID);
        int color = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_COLOR);
        int desc = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_DESC);

        do {
            CategoriesData cat = new CategoriesData();
            cat.setCategoryId(cursor.getInt(idIndex));
            cat.setCategoryTitle(cursor.getString(titleIndex));
            cat.setCategoryTitleNL(cursor.getString(titleNL));
            cat.setCategoryTitleLA(cursor.getString(titleLA));
            cat.setCategoryParentId(cursor.getInt(parentId));
            cat.setCategoryColor(cursor.getString(color));
            cat.setCategoryDescription(cursor.getString(desc));

            result[i] = cat;

            i++;
        } while (cursor.moveToNext());
    }

    cursor.close();
    return result;
}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

public static synchronized long isReadMsg(String msgId) {
    long count = 0;
    String sql = "select * from " + DatabaseHelper.TABLES_NAME_IM_MESSAGE + " where msgid = '" + msgId + "'";
    Cursor cursor = getInstance().sqliteDB().rawQuery(sql, null);
    if (cursor != null && cursor.getCount() > 0) {
        if (cursor.moveToFirst()) {
            count = cursor.getInt(cursor.getColumnIndex("readcount"));
            cursor.close();/*from  w ww.  j av a 2 s  .  co m*/
            cursor = null;
        }
    }
    return count;
}

From source file:com.hybris.mobile.lib.commerce.loader.ContentAdapterLoader.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    if (mOnRequestListener != null) {
        mOnRequestListener.afterRequestBeforeResponse();
    }/*  ww  w  .  j  a  v  a 2s  .  c o m*/

    boolean isDataSynced = false;

    if (data != null) {
        Log.i(TAG, "Loader finished to load " + data.getCount() + " result(s)");

        mCursorAdapter.swapCursor(data);

        if (data.getCount() > 0) {
            isDataSynced = data.getInt(data.getColumnIndex(
                    CatalogContract.DataBaseDataSimple.ATT_STATUS)) == CatalogContract.SyncStatus.UPTODATE
                            .getValue();
        }

    } else {
        isDataSynced = true;
    }

    if (mOnRequestListener != null) {
        mOnRequestListener.afterRequest(isDataSynced);
    }

}

From source file:com.socialize.util.ImageUtils.java

public int getOrientation(Context context, Uri photoUri) {
    /* it's on the external media. */
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    if (cursor == null) {
        return 0;
    }//from  www  .  j  av a2s  .  c o m

    if (cursor.getCount() != 1) {
        return -1;
    }

    cursor.moveToFirst();
    return cursor.getInt(0);
}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

/**
 * @return/*from  ww  w. ja v  a 2 s .  co m*/
 */
public static int getMaxVersion() {
    String sql = "select max(version) as maxVersion from " + DatabaseHelper.TABLES_NAME_IM_MESSAGE;
    Cursor cursor = getInstance().sqliteDB().rawQuery(sql, null);
    if (cursor != null && cursor.getCount() > 0) {
        if (cursor.moveToFirst()) {
            int maxVersion = cursor.getInt(cursor.getColumnIndex("maxVersion"));
            cursor.close();
            ;
            return maxVersion;
        }
    }
    return 0;
}

From source file:foam.zizim.android.BoskoiService.java

public static CategoriesData[] getCategoriesFromParent(int categoryId) {
    Cursor cursor = BoskoiApplication.mDb.fetchCategoriesFromParent(categoryId);
    CategoriesData result[] = new CategoriesData[cursor.getCount()];

    int i = 0;// w  w  w  .j av  a  2s  .  co  m
    if (cursor.moveToFirst()) {
        int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE);
        int titleNL = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_NL);
        int titleLA = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_LA);
        int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_ID);
        int parentId = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_PARENT_ID);
        int color = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_COLOR);
        int desc = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_DESC);

        do {
            CategoriesData cat = new CategoriesData();
            cat.setCategoryId(cursor.getInt(idIndex));
            cat.setCategoryTitle(cursor.getString(titleIndex));
            cat.setCategoryTitleNL(cursor.getString(titleNL));
            cat.setCategoryTitleLA(cursor.getString(titleLA));
            cat.setCategoryParentId(cursor.getInt(parentId));
            cat.setCategoryColor(cursor.getString(color));
            cat.setCategoryDescription(cursor.getString(desc));

            result[i] = cat;

            i++;
        } while (cursor.moveToNext());
    }

    cursor.close();
    return result;
}

From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java

private Object getValueFromCursor(Cursor cursor, int index, int columnType) {
    switch (columnType) {
    case Cursor.FIELD_TYPE_FLOAT:
        return cursor.getFloat(index);
    case Cursor.FIELD_TYPE_INTEGER:
        return cursor.getInt(index);
    case Cursor.FIELD_TYPE_BLOB:
        // convert byte[] to binary string; it's good enough, because
        // WebSQL doesn't support blobs anyway
        return new String(cursor.getBlob(index));
    case Cursor.FIELD_TYPE_STRING:
        return cursor.getString(index);
    }//w ww. jav a2s  .c o  m
    return null;
}

From source file:com.jaspersoft.android.jaspermobile.util.SavedItemHelper.java

public void deleteUnsavedItems() {
    String selection = SavedItemsTable.DOWNLOADED + " =?";
    Cursor cursor = context.getContentResolver().query(MobileDbProvider.SAVED_ITEMS_CONTENT_URI,
            new String[] { SavedItemsTable._ID, SavedItemsTable.FILE_PATH }, selection, new String[] { "0" },
            null);//from  w  ww.  ja v a  2s  .  c  o  m

    if (cursor == null)
        return;

    if (cursor.moveToFirst()) {
        do {
            int id = cursor.getInt(cursor.getColumnIndex(SavedItemsTable._ID));
            Uri uri = Uri.withAppendedPath(JasperMobileDbProvider.SAVED_ITEMS_CONTENT_URI, String.valueOf(id));
            deleteSavedItem(uri);
        } while (cursor.moveToNext());
    }

    cursor.close();
}