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.asd.littleprincesbeauty.data.Task.java

@Override
public int getSyncAction(Cursor c) {
    try {//w  ww . j av a  2 s  . c  om
        JSONObject noteInfo = null;
        if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) {
            noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
        }

        if (noteInfo == null) {
            Log.w(TAG, "it seems that note meta has been deleted");
            return SYNC_ACTION_UPDATE_REMOTE;
        }

        if (!noteInfo.has(NoteColumns.ID)) {
            Log.w(TAG, "remote note id seems to be deleted");
            return SYNC_ACTION_UPDATE_LOCAL;
        }

        // validate the note id now
        if (c.getLong(SqlNote.ID_COLUMN) != noteInfo.getLong(NoteColumns.ID)) {
            Log.w(TAG, "note id doesn't match");
            return SYNC_ACTION_UPDATE_LOCAL;
        }

        if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
            // there is no local update
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // no update both side
                return SYNC_ACTION_NONE;
            } else {
                // apply remote to local
                return SYNC_ACTION_UPDATE_LOCAL;
            }
        } else {
            // validate gtask id
            if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
                Log.e(TAG, "gtask id doesn't match");
                return SYNC_ACTION_ERROR;
            }
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // local modification only
                return SYNC_ACTION_UPDATE_REMOTE;
            } else {
                return SYNC_ACTION_UPDATE_CONFLICT;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }

    return SYNC_ACTION_ERROR;
}

From source file:com.nadmm.airports.DownloadActivity.java

protected void cleanupExpiredData() {
    SQLiteDatabase catalogDb = mDbManager.getCatalogDb();

    Time now = new Time();
    now.setToNow();/*from w w w.  j  av  a2  s .c  om*/
    String today = now.format3339(true);

    Cursor c = mDbManager.getAllFromCatalog();
    if (c.moveToFirst()) {
        do {
            // Check and delete all the expired databases
            String end = c.getString(c.getColumnIndex(Catalog.END_DATE));
            if (end.compareTo(today) < 0) {
                // This database has expired, remove it
                Integer _id = c.getInt(c.getColumnIndex(Catalog._ID));
                String dbName = c.getString(c.getColumnIndex(Catalog.DB_NAME));
                File file = new File(DatabaseManager.DATABASE_DIR, dbName);
                if (catalogDb.isOpen() && file.delete()) {
                    // Now delete the catalog entry for the file
                    catalogDb.delete(Catalog.TABLE_NAME, Catalog._ID + "=?",
                            new String[] { Integer.toString(_id) });
                }
            }
        } while (c.moveToNext());
    }
    c.close();
}

From source file:com.cloudmine.api.db.RequestDBOpenHelper.java

/**
 * Convert Cursor contents to a map from the request id to the request. The Map will have the same iteration order
 * as the Cursor/*from w  w w .j a va  2s .c  o  m*/
 * @param cursor
 * @return
 */
private LinkedHashMap<Integer, RequestDBObject> createRequestMapping(Cursor cursor) {
    int idIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_ID);
    int jsonIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_JSON_BODY);
    int urlIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_TARGET_URL);
    int verbIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_VERB);
    int syncedIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_SYNCHRONIZED);
    int headerNameIndex = cursor.getColumnIndexOrThrow(KEY_HEADER_NAME);
    int headerValueIndex = cursor.getColumnIndexOrThrow(KEY_HEADER_VALUE);
    int objectIdIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_OBJECT_ID);
    int fileIdIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_FILE_ID);
    LinkedHashMap<Integer, RequestDBObject> requestMapping = new LinkedHashMap<Integer, RequestDBObject>();
    while (cursor.moveToNext()) {
        Integer id = cursor.getInt(idIndex);

        RequestDBObject request = requestMapping.get(id);
        if (request == null) {
            String json = cursor.getString(jsonIndex);
            String url = cursor.getString(urlIndex);
            String verb = cursor.getString(verbIndex);
            String objectId = cursor.getString(objectIdIndex);
            String fileId = cursor.getString(fileIdIndex);
            int syncOrdinal = cursor.getInt(syncedIndex);
            RequestDBObject.SyncStatus status = RequestDBObject.SyncStatus.getSyncStatus(syncOrdinal);
            request = new RequestDBObject(url, RequestDBObject.Verb.getVerb(verb), json, objectId, fileId, id,
                    status, new ArrayList<Header>());
            requestMapping.put(id, request);
        }
        String headerName = cursor.getString(headerNameIndex);
        String headerValue = cursor.getString(headerValueIndex);
        request.addHeader(new BasicHeader(headerName, headerValue));
    }
    return requestMapping;
}

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

/**
 * Queries uncompleted partUpload tasks of a multipart upload and constructs
 * a UploadPartRequest for each task. It's used when resuming a multipart
 * upload/*from  ww w  . j av a  2  s .c o m*/
 *
 * @param mainUploadId The mainUploadId of a multipart upload task
 * @param multipartId The multipartId of a multipart upload task
 * @return A list of UploadPartRequest
 */
public List<UploadPartRequest> getNonCompletedPartRequestsFromDB(int mainUploadId, String multipartId) {
    final ArrayList<UploadPartRequest> list = new ArrayList<UploadPartRequest>();
    Cursor c = null;
    try {
        c = transferDBBase.query(getPartUri(mainUploadId), null, null, null, null);
        while (c.moveToNext()) {
            if (TransferState.PART_COMPLETED.equals(
                    TransferState.getState(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_STATE))))) {
                continue;
            }
            final UploadPartRequest putPartRequest = new UploadPartRequest()
                    .withId(c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID)))
                    .withMainUploadId(c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_MAIN_UPLOAD_ID)))
                    .withBucketName(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_BUCKET_NAME)))
                    .withKey(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_KEY)))
                    .withUploadId(multipartId)
                    .withFile(new File(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_FILE))))
                    .withFileOffset(c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_FILE_OFFSET)))
                    .withPartNumber(c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_PART_NUM)))
                    .withPartSize(c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_BYTES_TOTAL)))
                    .withLastPart(1 == c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_LAST_PART)));
            list.add(putPartRequest);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return list;
}

From source file:eu.operando.operandoapp.database.DatabaseHelper.java

public List<FilterFile> getAllDomainFilterFiles() {
    List<FilterFile> filterFiles = new ArrayList<>();
    String selectQuery = "SELECT " + KEY_SOURCE + ", COUNT(*) AS " + KEY_COUNT + " FROM " + TABLE_DOMAIN_FILTERS
            + " WHERE " + KEY_SOURCE + " IS NOT NULL GROUP BY " + KEY_SOURCE;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);
    if (c.moveToFirst()) {
        do {//  w w  w . j  ava  2s  .c  o  m

            FilterFile filterFile = new FilterFile();
            filterFile.setSource((c.getString(c.getColumnIndex(KEY_SOURCE))));
            filterFile.setFilterCount(c.getInt(c.getColumnIndex(KEY_COUNT)));
            filterFiles.add(filterFile);
        } while (c.moveToNext());
    }

    return filterFiles;
}

From source file:br.ufc.mdcc.benchimage2.dao.ResultDao.java

private ArrayList<ResultImage> queryResultImage(String sql) throws JSONException, ParseException {
    openDatabase();/*from  w  w  w .jav a 2s .  c o m*/

    Cursor cursor = database.rawQuery(sql, null);

    ArrayList<ResultImage> lista = new ArrayList<ResultImage>();

    // obtem todos os indices das colunas da tabela
    int idx_id = cursor.getColumnIndex(F_ID);
    int idx_date = cursor.getColumnIndex(F_DATE);

    int idx_photo_name = cursor.getColumnIndex(F_PHOTO_NAME);
    int idx_filter_name = cursor.getColumnIndex(F_FILTER_NAME);
    int idx_local = cursor.getColumnIndex(F_LOCAL);
    int idx_size = cursor.getColumnIndex(F_SIZE);

    int idx_cpu_time = cursor.getColumnIndex(F_EXECUTION_CPU_TIME);
    int idx_up_time = cursor.getColumnIndex(F_UPLOAD_TIME);
    int idx_down_time = cursor.getColumnIndex(F_DOWNLOAD_TIME);
    int idx_total_time = cursor.getColumnIndex(F_TOTAL_TIME);
    int idx_down_size = cursor.getColumnIndex(F_DOWN_SIZE);
    int idx_up_size = cursor.getColumnIndex(F_UP_SIZE);

    if (cursor != null && cursor.moveToFirst()) {
        do {
            ResultImage result = new ResultImage();
            result.setId(cursor.getInt(idx_id));
            result.setDate(simpleDateFormat.parse(cursor.getString(idx_date)));
            result.setTotalTime(cursor.getLong(idx_total_time));

            AppConfiguration config = new AppConfiguration();
            config.setImage(cursor.getString(idx_photo_name));
            config.setFilter(cursor.getString(idx_filter_name));
            config.setLocal(cursor.getString(idx_local));
            config.setSize(cursor.getString(idx_size));
            result.setConfig(config);

            RpcProfile profile = new RpcProfile();
            profile.setDonwloadTime(cursor.getLong(idx_down_time));
            profile.setDownloadSize(cursor.getInt(idx_down_size));
            profile.setUploadTime(cursor.getLong(idx_up_time));
            profile.setUploadSize(cursor.getInt(idx_up_size));
            profile.setExecutionCpuTime(cursor.getLong(idx_cpu_time));
            result.setRpcProfile(profile);

            lista.add(result);
        } while (cursor.moveToNext());
    }

    cursor.close();
    closeDatabase();

    return lista;
}

From source file:com.mk4droid.IMC_Services.DatabaseHandler.java

/**
 * Get issue picture from SQlite according to issue id
 * /*  w w  w.  ja  va2s .com*/
 * @param IssueID
 * @return
 */
public IssuePic getIssuePic(int IssueID) {
    SQLiteDatabase db = this.getReadableDatabase();
    IssuePic mIssuePic;

    if (!db.isOpen())
        db = this.getWritableDatabase();

    Cursor cr = db.query(TABLE_IssuesPics, new String[] { KEY_IssueID, KEY_IssuePicData }, KEY_IssueID + "=?",
            new String[] { Integer.toString(IssueID) }, null, null, null, null);

    boolean ExistsRes = cr.moveToFirst();

    if (!ExistsRes) {
        mIssuePic = new IssuePic(-1, null);
    } else {

        mIssuePic = new IssuePic(cr.getInt(0), cr.getBlob(1));
    }
    cr.close();
    if (db.isOpen())
        db.close();

    return mIssuePic;
}

From source file:com.mk4droid.IMC_Services.DatabaseHandler.java

/**
 *  Get Issue Thumb from SQLite table according to issue id.
 * /*from   ww w  .  ja  v a 2s. c o m*/
 * @param IssueID
 * @return
 */
public IssuePic getIssueThumb(int IssueID) {
    SQLiteDatabase db = this.getReadableDatabase();
    IssuePic mIssueThumb;

    if (!db.isOpen())
        db = this.getWritableDatabase();

    Cursor cr = db.query(TABLE_IssuesThumbs, new String[] { KEY_IssueID, KEY_IssueThumbData },
            KEY_IssueID + "=?", new String[] { Integer.toString(IssueID) }, null, null, null, null);

    boolean ExistsRes = cr.moveToFirst();

    if (!ExistsRes) {
        mIssueThumb = new IssuePic(-1, null);
    } else {
        mIssueThumb = new IssuePic(cr.getInt(0), cr.getBlob(1));
    }
    cr.close();

    if (db.isOpen())
        db.close();

    return mIssueThumb;
}

From source file:com.android.emailcommon.provider.Account.java

@Override
public void restore(Cursor cursor) {
    mId = cursor.getLong(CONTENT_ID_COLUMN);
    mBaseUri = CONTENT_URI;//from  w w w  .j  av a 2  s .co m
    mDisplayName = cursor.getString(CONTENT_DISPLAY_NAME_COLUMN);
    mEmailAddress = cursor.getString(CONTENT_EMAIL_ADDRESS_COLUMN);
    mSyncKey = cursor.getString(CONTENT_SYNC_KEY_COLUMN);
    mSyncLookback = cursor.getInt(CONTENT_SYNC_LOOKBACK_COLUMN);
    mSyncInterval = cursor.getInt(CONTENT_SYNC_INTERVAL_COLUMN);
    mHostAuthKeyRecv = cursor.getLong(CONTENT_HOST_AUTH_KEY_RECV_COLUMN);
    mHostAuthKeySend = cursor.getLong(CONTENT_HOST_AUTH_KEY_SEND_COLUMN);
    mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN);
    mSenderName = cursor.getString(CONTENT_SENDER_NAME_COLUMN);
    mRingtoneUri = cursor.getString(CONTENT_RINGTONE_URI_COLUMN);
    mProtocolVersion = cursor.getString(CONTENT_PROTOCOL_VERSION_COLUMN);
    mSecuritySyncKey = cursor.getString(CONTENT_SECURITY_SYNC_KEY_COLUMN);
    mSignature = cursor.getString(CONTENT_SIGNATURE_COLUMN);
    mPolicyKey = cursor.getLong(CONTENT_POLICY_KEY_COLUMN);
    mPingDuration = cursor.getLong(CONTENT_PING_DURATION_COLUMN);
}

From source file:com.odoo.core.orm.OModel.java

public int count(String selection, String[] args) {
    int count = 0;
    SQLiteDatabase db = getReadableDatabase();
    Cursor cr = db.query(getTableName(), new String[] { "count(*)" }, selection, args, null, null, null);
    try {/*from  w  w w  .  jav  a  2 s . c  o  m*/
        cr.moveToFirst();
        count = cr.getInt(0);
    } finally {
        cr.close();
    }
    return count;
}