mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
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:
parent
fbc8a62a13
commit
3510268752
1 changed files with 9 additions and 13 deletions
|
@ -2265,22 +2265,18 @@ public class DBUtils {
|
|||
private static String getStringForSyncSel( SQLiteDatabase db, String selection )
|
||||
{
|
||||
String result = null;
|
||||
String[] columns = { ROW_ID, 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();
|
||||
|
||||
String[] columns = { DBHelper.VALUE, };
|
||||
// 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
|
||||
// each upgrade.
|
||||
long prevRow = 0;
|
||||
while ( cursor.moveToNext() ) {
|
||||
long row = cursor.getLong(cursor.getColumnIndex(ROW_ID));
|
||||
if ( row > prevRow ) {
|
||||
result = cursor.getString( cursor.getColumnIndex( DBHelper.VALUE ) );
|
||||
prevRow = row;
|
||||
}
|
||||
String orderBy = ROW_ID + " DESC";
|
||||
|
||||
Cursor cursor = DBHelper.query( db, TABLE_NAMES.PAIRS, columns, selection, orderBy );
|
||||
// Log.d( TAG, "getStringForSyncSel(selection=%s)", selection );
|
||||
boolean tooMany = BuildConfig.DEBUG && 1 < cursor.getCount();
|
||||
|
||||
if ( cursor.moveToNext() ) {
|
||||
result = cursor.getString( cursor.getColumnIndex(DBHelper.VALUE) );
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
|
|
Loading…
Reference in a new issue