Java Code Examples for android.database.Cursor#move()

The following examples show how to use android.database.Cursor#move() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistoryManager.java    From reacteu-app with MIT License 7 votes vote down vote up
public void deleteHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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(number + 1);
    db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
  } finally {
    close(cursor, db);
  }
}
 
Example 2
Source File: HistoryManager.java    From android-apps with MIT License 6 votes vote down vote up
public void deleteHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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(number + 1);
    db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
  } finally {
    close(cursor, db);
  }
}
 
Example 3
Source File: HistoryManager.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public void deleteHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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(number + 1);
    db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
  } finally {
    close(cursor, db);
  }
}
 
Example 4
Source File: HistoryManager.java    From zxingfragmentlib with Apache License 2.0 6 votes vote down vote up
public void deleteHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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(number + 1);
    db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
  } finally {
    close(cursor, db);
  }
}
 
Example 5
Source File: HistoryManager.java    From reacteu-app with MIT License 6 votes vote down vote up
public HistoryItem buildHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(number + 1);
    String text = cursor.getString(0);
    String display = cursor.getString(1);
    String format = cursor.getString(2);
    long timestamp = cursor.getLong(3);
    String details = cursor.getString(4);
    Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
    return new HistoryItem(result, display, details);
  } finally {
    close(cursor, db);
  }
}
 
Example 6
Source File: HistoryManager.java    From android-apps with MIT License 6 votes vote down vote up
public void trimHistory() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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()) {
      db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
    }
  } finally {
    close(cursor, db);
  }
}
 
Example 7
Source File: MessageLogger.java    From MaterialQQLite with Apache License 2.0 6 votes vote down vote up
synchronized public int getGroupMsgLogCount(int nGroupNum) {
	if (null == m_DB || !m_DB.isOpen())
		return 0;
	
	int nCount = 0;
	String strSql = "SELECT COUNT(*) FROM [tb_GroupMsg] WHERE [groupnum]=?";
	
	Cursor cursor = m_DB.rawQuery(strSql, 
			new String[]{String.valueOf(nGroupNum)});
	if (cursor.getCount() == 1) {
		cursor.move(1);
		nCount = cursor.getInt(0);
	}
	cursor.close();
	return nCount;
}
 
Example 8
Source File: HistoryManager.java    From zxingfragmentlib with Apache License 2.0 6 votes vote down vote up
public void trimHistory() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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);
  }
}
 
Example 9
Source File: HistoryManager.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public void trimHistory() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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);
  }
}
 
Example 10
Source File: HistoryManager.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
public void deleteHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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(number + 1);
    db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
  } finally {
    close(cursor, db);
  }
}
 
Example 11
Source File: MessageLogger.java    From MaterialQQLite with Apache License 2.0 6 votes vote down vote up
synchronized public int getBuddyMsgLogCount(int nQQNum) {
	if (null == m_DB || !m_DB.isOpen())
		return 0;
	
	int nCount = 0;
	String strSql = "SELECT COUNT(*) FROM [tb_BuddyMsg] WHERE [uin]=?";
	
	Cursor cursor = m_DB.rawQuery(strSql, 
			new String[]{String.valueOf(nQQNum)});
	if (cursor.getCount() == 1) {
		cursor.move(1);
		nCount = cursor.getInt(0);
	}
	cursor.close();
	return nCount;		
}
 
Example 12
Source File: HistoryManager.java    From ZXing-Standalone-library with Apache License 2.0 6 votes vote down vote up
public void deleteHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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(number + 1);
    db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
  } finally {
    close(cursor, db);
  }
}
 
Example 13
Source File: HistoryManager.java    From ZXing-Standalone-library with Apache License 2.0 6 votes vote down vote up
public HistoryItem buildHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(number + 1);
    String text = cursor.getString(0);
    String display = cursor.getString(1);
    String format = cursor.getString(2);
    long timestamp = cursor.getLong(3);
    String details = cursor.getString(4);
    Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
    return new HistoryItem(result, display, details);
  } finally {
    close(cursor, db);
  }
}
 
Example 14
Source File: HistoryManager.java    From zxingfragmentlib with Apache License 2.0 6 votes vote down vote up
public HistoryItem buildHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(number + 1);
    String text = cursor.getString(0);
    String display = cursor.getString(1);
    String format = cursor.getString(2);
    long timestamp = cursor.getLong(3);
    String details = cursor.getString(4);
    Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
    return new HistoryItem(result, display, details);
  } finally {
    close(cursor, db);
  }
}
 
Example 15
Source File: HistoryManager.java    From reacteu-app with MIT License 6 votes vote down vote up
public void trimHistory() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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()) {
      db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), 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.
    // TODO revisit this after live in a future version to see if it 'worked'
    Log.w(TAG, sqle);
    // continue
  } finally {
    close(cursor, db);
  }
}
 
Example 16
Source File: MessageLogger.java    From MaterialQQLite with Apache License 2.0 6 votes vote down vote up
synchronized public int readGroupMsgLogCount(int nGroupNum, 
		int nOffset, int nRows) {
	if (null == m_DB || !m_DB.isOpen())
		return 0;
	
	int nCount = 0;
	String strSql = "SELECT COUNT(*) FROM (SELECT * FROM [tb_GroupMsg] WHERE [groupnum]=? ORDER BY [time] LIMIT ?,?)";
	
	Cursor cursor = m_DB.rawQuery(strSql, 
			new String[]{String.valueOf(nGroupNum), 
			String.valueOf(nOffset), String.valueOf(nRows)});
	if (cursor.getCount() == 1) {
		cursor.move(1);
		nCount = cursor.getInt(0);
	}
	cursor.close();
	return nCount;
}
 
Example 17
Source File: HistoryManager.java    From incubator-weex-playground with Apache License 2.0 6 votes vote down vote up
public void deleteHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  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(number + 1);
    db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
  } finally {
    close(cursor, db);
  }
}
 
Example 18
Source File: WorldCupTraceHandler.java    From letv with Apache License 2.0 5 votes vote down vote up
public DownloadDBBean getDownloadDBBeanPosition(int position) {
    DownloadDBBean mDownloadDBBean = null;
    try {
        Cursor cursor = this.context.getContentResolver().query(LetvContentProvider.URI_WORLDCUPTRACE, null, "finish<>?", new String[]{"4"}, "timestamp ASC");
        if (cursor.move(position + 1)) {
            mDownloadDBBean = createDownloadDBBean(cursor);
        }
        LetvTools.closeCursor(cursor);
        return mDownloadDBBean;
    } catch (Throwable th) {
        LetvTools.closeCursor(null);
    }
}
 
Example 19
Source File: SQLiteLocalStore.java    From azure-mobile-apps-android-client with Apache License 2.0 4 votes vote down vote up
@Override
public JsonElement read(Query query) throws MobileServiceLocalStoreException {
    try {
        JsonElement result;
        JsonArray rows = new JsonArray();

        String invTableName = normalizeTableName(query.getTableName());

        Map<String, ColumnDataInfo> table = this.mTables.get(invTableName);

        String[] columns = getColumns(query, table);

        String whereClause = getWhereClause(query);

        String orderByClause = QuerySQLWriter.getOrderByClause(query);

        String limitClause = QuerySQLWriter.getLimitClause(query);

        Integer inlineCount = null;

        SQLiteDatabase db = this.getWritableDatabaseSynchronized();

        try {
            Cursor cursor = null;

            try {
                if (query.hasInlineCount()) {
                    cursor = db.query(invTableName, columns, whereClause, null, null, null, orderByClause, null);
                    inlineCount = cursor.getCount();

                    if (query.getSkip() > 0) {
                        cursor.move(query.getSkip());
                    }
                } else {
                    cursor = db.query(invTableName, columns, whereClause, null, null, null, orderByClause, limitClause);
                }

                int limit = 0;

                while (!(query.getTop() > 0 && limit == query.getTop()) && cursor.moveToNext()) {
                    JsonObject row = parseRow(cursor, table);
                    rows.add(row);

                    limit++;
                }
            } finally {
                if (cursor != null && !cursor.isClosed()) {
                    cursor.close();
                }
            }
        } finally {
            this.closeDatabaseSynchronized(db);
        }

        if (query.hasInlineCount()) {
            JsonObject resObj = new JsonObject();
            resObj.addProperty("count", inlineCount);
            resObj.add("results", rows);
            result = resObj;
        } else {
            result = rows;
        }

        return result;
    } catch (Throwable t) {
        throw new MobileServiceLocalStoreException(t);
    }
}
 
Example 20
Source File: DownloadTraceHandler.java    From letv with Apache License 2.0 4 votes vote down vote up
public DownloadDBBean getDownloadDBBeanPosition(int position) {
    Throwable th;
    Cursor cursor = null;
    DownloadDBBean mDownloadDBBean = null;
    try {
        cursor = this.mContext.getContentResolver().query(LetvContentProvider.URI_DOWNLOADTRACE, null, "finish<>?", new String[]{"4"}, "timestamp ASC");
        if (cursor.move(position + 1)) {
            DownloadDBBean mDownloadDBBean2 = new DownloadDBBean();
            try {
                mDownloadDBBean2.vid = cursor.getInt(cursor.getColumnIndex("episodeid"));
                mDownloadDBBean2.aid = cursor.getInt(cursor.getColumnIndex(PageJumpUtil.IN_TO_ALBUM_PID));
                mDownloadDBBean2.icon = cursor.getString(cursor.getColumnIndex(SettingsJsonConstants.APP_ICON_KEY));
                mDownloadDBBean2.type = cursor.getInt(cursor.getColumnIndex("type"));
                mDownloadDBBean2.ord = (float) cursor.getInt(cursor.getColumnIndex("ord"));
                mDownloadDBBean2.cid = cursor.getInt(cursor.getColumnIndex("cid"));
                mDownloadDBBean2.episodetitle = cursor.getString(cursor.getColumnIndex("episodetitle"));
                mDownloadDBBean2.episodeIcon = cursor.getString(cursor.getColumnIndex("episodeicon"));
                mDownloadDBBean2.albumtitle = cursor.getString(cursor.getColumnIndex(DownloadAlbumTable.COLUMN_ALBUMTITLE));
                mDownloadDBBean2.totalsize = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_TOTALSIZE));
                mDownloadDBBean2.finish = cursor.getInt(cursor.getColumnIndex("finish"));
                mDownloadDBBean2.timestamp = cursor.getLong(cursor.getColumnIndex("timestamp"));
                mDownloadDBBean2.length = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_LENGTH));
                mDownloadDBBean2.filePath = cursor.getString(cursor.getColumnIndex("file_path"));
                mDownloadDBBean2.isHd = cursor.getInt(cursor.getColumnIndex("isHd"));
                mDownloadDBBean2.isNew = cursor.getInt(cursor.getColumnIndex(DownloadVideoTable.COLUMN_ISNEW));
                mDownloadDBBean2.btime = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_BTIME));
                mDownloadDBBean2.etime = cursor.getLong(cursor.getColumnIndex(DownloadVideoTable.COLUMN_ETIME));
                mDownloadDBBean = mDownloadDBBean2;
            } catch (Throwable th2) {
                th = th2;
                mDownloadDBBean = mDownloadDBBean2;
                LetvTools.closeCursor(cursor);
                throw th;
            }
        }
        LetvTools.closeCursor(cursor);
        return mDownloadDBBean;
    } catch (Throwable th3) {
        th = th3;
        LetvTools.closeCursor(cursor);
        throw th;
    }
}