Example usage for android.database Cursor moveToNext

List of usage examples for android.database Cursor moveToNext

Introduction

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

Prototype

boolean moveToNext();

Source Link

Document

Move the cursor to the next row.

Usage

From source file:com.clevertrail.mobile.Database_SavedTrails.java

public String getJSONString() {
    String[] columns = new String[] { "json" };
    Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, null, null, null, null, null);

    cursor.moveToFirst();//  w  ww .j a  v  a2 s  .  c  o  m
    int index_JSON = cursor.getColumnIndex("json");

    //we will create a simple return value of the format:
    //"[trail1JSON, trail2JSON, ...]"
    String sReturn = "[";
    while (!cursor.isAfterLast()) {
        String sTrailJSON = cursor.getString(index_JSON);
        sReturn = sReturn.concat(sTrailJSON);
        cursor.moveToNext();
        if (!cursor.isAfterLast()) {
            if (sTrailJSON.compareTo("") != 0)
                sReturn = sReturn.concat(",");
        } else {
            break;
        }
    }
    sReturn = sReturn.concat("]");

    return sReturn;
}

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

/**
 * Loads transfers from database. These transfers are unfinished from
 * previous session or are new transfers waiting for network. It skips any
 * transfer that is already tracked by the status updater. Also starts
 * transfers whose states indicate running but aren't.
 *///from w w w.jav a 2  s.c o m
void loadTransfersFromDB() {
    LOGGER.debug("Loading transfers from database");
    Cursor c = null;
    int count = 0;

    try {
        // Query for the unfinshed transfers
        c = dbUtil.queryTransfersWithTypeAndStates(TransferType.ANY, UNFINISHED_TRANSFER_STATES);
        while (c.moveToNext()) {
            final int id = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID));
            final TransferState state = TransferState
                    .getState(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_STATE)));
            final int partNumber = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_PART_NUM));
            // add unfinished transfers
            if (partNumber == 0) {
                if (updater.getTransfer(id) == null) {
                    final TransferRecord transfer = new TransferRecord(id);
                    transfer.updateFromDB(c);
                    if (transfer.start(s3, dbUtil, updater, networkInfoReceiver)) {
                        updater.addTransfer(transfer);
                        count++;
                    }
                } else {
                    final TransferRecord transfer = updater.getTransfer(id);
                    if (!transfer.isRunning()) {
                        transfer.start(s3, dbUtil, updater, networkInfoReceiver);
                    }
                }
            }
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    LOGGER.debug(count + " transfers are loaded from database");
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<LabelDto> getAllLabels() {
    List<LabelDto> allLabels = new ArrayList<LabelDto>();
    Cursor c = db.query(LabelQuery.TABLE, LabelQuery.COLUMNS, null, null, null, null, LabelColumn.NAME);
    try {/*  www. j  a  va  2s .  c o  m*/
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                LabelDto bookmark = getLabelDto(c);
                allLabels.add(bookmark);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    return allLabels;
}

From source file:com.citrus.sdk.database.DBHandler.java

public List<BankOptions> getBankOptions() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor current_cursor;
    String[] columNames = { BANK, BANK_CID };
    List<BankOptions> bankOptionsList = new ArrayList<BankOptions>();
    current_cursor = db.query(BANK_TABLE, columNames, null, null, null, null, null);
    if (current_cursor.moveToFirst()) {
        do {/*  w  w w . ja  va 2s .c o m*/
            BankOptions currentOption = new BankOptions(current_cursor.getString(0),
                    current_cursor.getString(1));
            bankOptionsList.add(currentOption);
        } while (current_cursor.moveToNext());
    }
    return bankOptionsList;
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<BookmarkDto> getAllBookmarks() {
    List<BookmarkDto> allBookmarks = new ArrayList<BookmarkDto>();
    Cursor c = db.query(BookmarkQuery.TABLE, BookmarkQuery.COLUMNS, null, null, null, null, null);
    try {//from  www  . j  a  v a2  s  . c o m
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                BookmarkDto bookmark = getBookmarkDto(c);
                allBookmarks.add(bookmark);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    return allBookmarks;
}

From source file:com.google.zxing.client.android.history.HistoryManager.java

public void trimHistory() {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;//from w w w  .ja  va  2s  .c om
    Cursor cursor = null;
    try {
        db = helper.getWritableDatabase();
        cursor = db.query(DBHelper.TABLE_NAME, ID_COL_PROJECTION, null, null, null, null,
                DBHelper.TIMESTAMP_COL + " DESC");
        cursor.move(MAX_ITEMS);
        while (cursor.moveToNext()) {
            String id = cursor.getString(0);
            Log.i(TAG, "Deleting scan history ID " + id);
            db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + id, null);
        }
    } catch (SQLiteException sqle) {
        // We're seeing an error here when called in
        // CaptureActivity.onCreate() in rare cases
        // and don't understand it. First theory is that it's transient so
        // can be safely ignored.
        Log.w(TAG, sqle);
        // continue
    } finally {
        close(cursor, db);
    }
}

From source file:gov.wa.wsdot.android.wsdot.service.FerriesSchedulesSyncService.java

/** 
 * Check the ferries schedules table for any starred entries. If we find some, save them
 * to a list so we can re-star those after we flush the database.
 *//*from ww w.j  a  v  a2 s. c om*/
private List<Integer> getStarred() {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;
    List<Integer> starred = new ArrayList<Integer>();

    try {
        cursor = resolver.query(FerriesSchedules.CONTENT_URI,
                new String[] { FerriesSchedules.FERRIES_SCHEDULE_ID },
                FerriesSchedules.FERRIES_SCHEDULE_IS_STARRED + "=?", new String[] { "1" }, null);

        if (cursor != null && cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                starred.add(cursor.getInt(0));
                cursor.moveToNext();
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return starred;
}

From source file:com.barcamppenang2014.tabfragment.ProfileFragment.java

License:asdf

public String[] fillTextField() {
    String[] myInfo = new String[5];

    MyDatabase database = new MyDatabase(getActivity());
    SQLiteDatabase sqliteDatabase = database.getReadableDatabase();
    String sql = "SELECT * FROM USERPROFILE;";
    Cursor retrieved = sqliteDatabase.rawQuery(sql, null);

    // Log.d("yc","row of cursor in database is "+
    // Integer.toString(retrieved.getCount()));

    // If cursor is not null
    while (retrieved.moveToNext()) {

        myInfo[0] = retrieved.getString(retrieved.getColumnIndex("MYNAME"));
        myInfo[1] = retrieved.getString(retrieved.getColumnIndex("MYEMAIL"));
        myInfo[2] = retrieved.getString(retrieved.getColumnIndex("MYPHONE"));
        myInfo[3] = retrieved.getString(retrieved.getColumnIndex("MYPROFESSION"));
        myInfo[4] = retrieved.getString(retrieved.getColumnIndex("MYFBID"));
        // myInfo[5] =
        // retrieved.getString(retrieved.getColumnIndex("MYURI"));

    }//w  w w.j  a va 2 s. c o  m

    retrieved.close();
    database.close();
    sqliteDatabase.close();

    return myInfo;

}

From source file:be.vbsteven.bmtodesk.SendAllCurrentBookmarksActivity.java

protected ArrayList<Bookmark> getAllBookmarks() {
    ArrayList<Bookmark> result = new ArrayList<SendAllCurrentBookmarksActivity.Bookmark>();
    String[] projection = new String[] { BookmarkColumns.TITLE, BookmarkColumns.URL };
    Cursor c = managedQuery(Browser.BOOKMARKS_URI, projection, "bookmark = ?", new String[] { "1" }, null);

    if (c.moveToFirst()) {
        int title = c.getColumnIndex(BookmarkColumns.TITLE);
        int url = c.getColumnIndex(BookmarkColumns.URL);
        while (!c.isAfterLast()) {
            Bookmark b = new Bookmark();
            b.title = c.getString(title);
            b.url = c.getString(url);//from   w w w  .  jav  a  2 s . co m
            result.add(b);

            c.moveToNext();
        }
    }

    return result;
}

From source file:cn.code.notes.gtask.data.SqlNote.java

private void loadFromCursor(long id) {
    Cursor c = null;
    try {/*from w  ww  . jav a 2 s .c  o m*/
        c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
                new String[] { String.valueOf(id) }, null);
        if (c != null) {
            c.moveToNext();
            loadFromCursor(c);
        } else {
            Log.w(TAG, "loadFromCursor: cursor = null");
        }
    } finally {
        if (c != null)
            c.close();
    }
}