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.rs.TCOfflineStatementCollection.java

/**
 * return a list of all local statements from db
 * @return List of LocalStatementsItem/*ww w  .j a  va 2s. c  o  m*/
 */
public List<LocalStatementsItem> getCachedStatements() {
    List<LocalStatementsItem> statementArray = new ArrayList<LocalStatementsItem>();

    Cursor cursor;
    SQLiteDatabase database;
    TCLocalStorageDatabaseOpenHelper dbHelper;
    dbHelper = new TCLocalStorageDatabaseOpenHelper(appContext);
    database = dbHelper.getWritableDatabase();
    cursor = database.query(TCOfflineDataManager.LOCAL_STATEMENT_TABLE_NAME, null, null, null, null, null,
            LocalStatements.CREATE_DATE + " DESC"); //query for all the statements

    cursor.moveToFirst(); //go to the beginning of the query and then loop through all the packages, adding them to the return List
    while (!cursor.isAfterLast()) {
        LocalStatementsItem thisPackage = new LocalStatementsItem();
        thisPackage.id = cursor.getInt(0);
        thisPackage.statementId = cursor.getString(cursor.getColumnIndex("statementId"));
        thisPackage.statementJson = cursor.getString(cursor.getColumnIndex("statementJson"));
        thisPackage.createDate = cursor.getLong(cursor.getColumnIndex("createDate"));
        thisPackage.postedDate = cursor.getLong(cursor.getColumnIndex("postedDate"));
        thisPackage.querystring = cursor.getString(cursor.getColumnIndex("querystring"));

        statementArray.add(thisPackage);
        cursor.moveToNext();
    }

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

    return statementArray;
}

From source file:com.google.android.apps.iosched.ui.SessionDetailActivity.java

/** Handle {@link TracksQuery} {@link Cursor}. */
private void onTrackQueryComplete(Cursor cursor) {
    try {/*from  w w  w  .j a v  a2 s.  co  m*/
        if (!cursor.moveToFirst())
            return;

        // Use found track to build title-bar
        ((TextView) findViewById(R.id.title_text)).setText(cursor.getString(TracksQuery.TRACK_NAME));
        UIUtils.setTitleBarColor(findViewById(R.id.title_container), cursor.getInt(TracksQuery.TRACK_COLOR));
    } finally {
        cursor.close();
    }
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private boolean checkDownload() {
    Cursor cursor = mSession.getDownloadManager()
            .query(new DownloadManager.Query().setFilterById(mSession.getUpdateId()));

    if (cursor != null && cursor.moveToFirst()) {
        int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.Impl.COLUMN_STATUS));
        if (DownloadManager.Impl.STATUS_SUCCESS == status) {
            String fileSrc = cursor.getString(cursor.getColumnIndex(DownloadManager.Impl.COLUMN_DATA));
            Uri uri = Uri.parse(fileSrc);
            File file = new File(uri.getPath());
            if (!file.exists()) {
                return false;
            }/*from   w w  w.j  av a 2  s  . c  o m*/

            File root = new File(Environment.getExternalStorageDirectory(),
                    com.mappn.gfan.Constants.IMAGE_CACHE_DIR);
            root.mkdirs();
            File output = new File(root, "aMarket.apk");
            if (!output.exists()) {
                try {
                    Utils.copyFile(new FileInputStream(file), new FileOutputStream(output));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    return false;
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                }
            }
            Utils.installApk(getApplicationContext(), output);
            return true;
        }
    }
    return false;
}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public ArrayList<Calender> getSetE() {
    Log.d("SET_GET", "Geting set exercise");

    String fetchset = "select * from " + CALENDER_TABLE + " ORDER BY " + MONTH + " ASC," + DAY + " ASC";

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(fetchset, null);
    cursor.moveToFirst();/*  w  w  w  . j  ava  2  s.c o m*/

    ArrayList<Calender> temp = new ArrayList<Calender>();

    if (cursor == null) {
        Calender ex = new Calender(0, 0, 0, 0, 0, "empty");
        temp.add(ex);
        Log.d("exiting", "NOTHING");
    }
    if (cursor.getCount() == 0) {
        Log.d("NOTHING", "0 nothing");
    } else {
        cursor.moveToFirst();
        do {
            Calender ex = new Calender();

            ex.setNum(cursor.getInt(cursor.getColumnIndex(CAL_NUM)));
            ex.setMonth(cursor.getInt(cursor.getColumnIndex(MONTH)));
            ex.setDay(cursor.getInt(cursor.getColumnIndex(DAY)));
            ex.setYear(cursor.getInt(cursor.getColumnIndex(YEAR)));
            ex.setName(cursor.getString(cursor.getColumnIndex(CAL_NAME)));

            temp.add(ex);
        } while (cursor.moveToNext());
    }

    cursor.close();
    getReadableDatabase().close();
    return temp;

}

From source file:org.noorganization.instalistsynch.controller.synch.impl.CategorySynch.java

@Override
public void indexLocal(int _groupId, Date _lastIndexTime) {
    String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000");
    boolean isLocal = false;
    GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup();
    if (groupAuth != null) {
        isLocal = groupAuth.getGroupId() == _groupId;
    }/*from  ww  w  .j  a  v a2 s . c  o m*/
    Cursor categoryLogCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType);
    if (categoryLogCursor.getCount() == 0) {
        categoryLogCursor.close();
        return;
    }

    try {
        while (categoryLogCursor.moveToNext()) {
            // fetch the action type
            int actionId = categoryLogCursor.getInt(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION));
            eActionType actionType = eActionType.getTypeById(actionId);

            List<ModelMapping> modelMappingList = mCategoryModelMappingController.get(
                    ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID
                            + " LIKE ?",
                    new String[] { String.valueOf(_groupId), categoryLogCursor
                            .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) });
            ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0);

            switch (actionType) {
            case INSERT:
                // skip insertion because this should be decided by the user if the non local groups should have access to the category
                // and also skip if a mapping for this case already exists!
                if (!isLocal || modelMapping != null) {
                    continue;
                }

                String clientUuid = categoryLogCursor
                        .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID));
                Date clientDate = ISO8601Utils.parse(
                        categoryLogCursor
                                .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)),
                        new ParsePosition(0));
                modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid,
                        new Date(Constants.INITIAL_DATE), clientDate, false);
                mCategoryModelMappingController.insert(modelMapping);
                break;
            case UPDATE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                String timeString = categoryLogCursor
                        .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mCategoryModelMappingController.update(modelMapping);
                break;
            case DELETE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                modelMapping.setDeleted(true);
                timeString = categoryLogCursor
                        .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mCategoryModelMappingController.update(modelMapping);
                break;
            default:
            }

        }
    } catch (Exception e) {
        categoryLogCursor.close();
    }
}

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility.java

/**
 * Pauses all transfers which have the given type.
 *
 * @param type The type of transfers//  w  w w  .  j  av a2s  .com
 */
public void pauseAllWithType(TransferType type) {
    Cursor c = null;
    try {
        c = dbUtil.queryAllTransfersWithType(type);
        while (c.moveToNext()) {
            final int id = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID));
            pause(id);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
}

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility.java

/**
 * Sets all transfers which have the given type to be canceled. Note the
 * TransferState must be TransferState.CANCELED before the transfer is
 * guaranteed to have stopped, and can be safely deleted
 *
 * @param type The type of transfers//ww  w .  java2s  . c om
 */
public void cancelAllWithType(TransferType type) {
    Cursor c = null;
    try {
        c = dbUtil.queryAllTransfersWithType(type);
        while (c.moveToNext()) {
            final int id = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID));
            cancel(id);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
}

From source file:com.cryart.sabbathschool.util.SSCore.java

public SSLesson ssGetTodaysLesson() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(
            "SELECT ss_lessons.* FROM ss_lessons, ss_days, ss_quarters "
                    + "WHERE ss_days.day_date = ? AND ss_days.day_lesson_serial = ss_lessons.serial "
                    + "   AND ss_lessons.lesson_quarter_serial = ss_quarters.serial"
                    + "   AND ss_quarters.quarter_lang = ? ORDER BY ss_lessons.serial " + "ASC LIMIT 1",
            new String[] { this.ssTodaysDate(), LANGUAGE });

    if (cursor != null)
        cursor.moveToFirst();// ww  w . j  av  a2 s  .co m

    return new SSLesson(cursor.getInt(0), cursor.getString(2), cursor.getString(4));
}

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility.java

/**
 * Gets a list of TransferObserver instances which are observing records
 * with the given type./*from  w  w  w  .ja  v a 2s.com*/
 *
 * @param type The type of the transfer "any".
 * @return A list of TransferObserver instances.
 */
public List<TransferObserver> getTransfersWithType(TransferType type) {
    final List<TransferObserver> transferObservers = new ArrayList<TransferObserver>();
    Cursor c = null;
    try {
        c = dbUtil.queryAllTransfersWithType(type);
        while (c.moveToNext()) {
            final int id = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID));
            final TransferObserver to = new TransferObserver(id, dbUtil);
            to.updateFromDB(c);
            transferObservers.add(to);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return transferObservers;
}

From source file:com.ruuhkis.cookies.CookieSQLSource.java

/**
 * Creates SQLCookie from cursor that is assumed
 * to be located at SQLCookie entry//from www.j  av a  2  s . com
 * @param cursor
 * @return
 */

private SQLCookie cursorToCookie(Cursor cursor) {
    SQLCookie cookie = new SQLCookie();
    cookie.setComment(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COMMENT)));
    cookie.setCommentURL(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COMMENT_URL)));
    cookie.setDomain(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_DOMAIN)));
    long expiryDate = cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_EXPIRY_DATE));
    cookie.setExpiryDate(expiryDate != -1 ? new Date(expiryDate) : null);
    cookie.setName(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_NAME)));
    cookie.setPath(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PATH)));
    cookie.setPersistent(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PERSISTENT)) == 1);
    cookie.setPorts(getPorts(cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_ID))));
    cookie.setSecure(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_SECURE)) == 1);
    cookie.setValue(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_VALUE)));
    cookie.setVersion(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_VERSION)));
    cookie.setId(cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_ID)));
    return cookie;
}