use order-by so don't have to iterate over results

This assumes, as seems to be the case, that rowid is assigned increasing
order.
This commit is contained in:
Eric House 2020-09-05 17:47:59 -07:00
parent fbc8a62a13
commit 3510268752

View file

@ -2265,22 +2265,18 @@ public class DBUtils {
private static String getStringForSyncSel( SQLiteDatabase db, String selection ) private static String getStringForSyncSel( SQLiteDatabase db, String selection )
{ {
String result = null; String result = null;
String[] columns = { ROW_ID, DBHelper.VALUE }; String[] columns = { DBHelper.VALUE, };
Cursor cursor = DBHelper.query( db, TABLE_NAMES.PAIRS, columns, selection );
// Log.d( TAG, "getStringForSyncSel(selection=%s)", selection );
boolean tooMany = BuildConfig.DEBUG && 1 < cursor.getCount();
// If there are multiple matches, we want to use the newest. At least // If there are multiple matches, we want to use the newest. At least
// that's the right move where a devID's key has been changed with // that's the right move where a devID's key has been changed with
// each upgrade. // each upgrade.
long prevRow = 0; String orderBy = ROW_ID + " DESC";
while ( cursor.moveToNext() ) {
long row = cursor.getLong(cursor.getColumnIndex(ROW_ID)); Cursor cursor = DBHelper.query( db, TABLE_NAMES.PAIRS, columns, selection, orderBy );
if ( row > prevRow ) { // Log.d( TAG, "getStringForSyncSel(selection=%s)", selection );
boolean tooMany = BuildConfig.DEBUG && 1 < cursor.getCount();
if ( cursor.moveToNext() ) {
result = cursor.getString( cursor.getColumnIndex(DBHelper.VALUE) ); result = cursor.getString( cursor.getColumnIndex(DBHelper.VALUE) );
prevRow = row;
}
} }
cursor.close(); cursor.close();