Using SQL to reorder items in a list view - is this efficient? I'm writing an application for work that requires me to process a list of transactions.  The list is small (5 records at the most) and I'm required to display that data in an android ListView. My client has asked that I include the ability to order the list based on the date (I have added ordering it by the amount spent.)

My code uses SQLite queries to get the transactions, from an in-memory database, in the desired order.

public Cursor getAllTransactions(int orderByType)
{
    String orderBy = " order by ";
    switch (orderByType)
    {
        case ORDER_BY_NEWER:
            orderBy += "date(" + KEY_DATE + ") desc";
            break;
        case ORDER_BY_OLDER:
            orderBy += "date(" + KEY_DATE + ")";
            break;
        case ORDER_BY_MOST:
            orderBy += KEY_AMOUNT;
            break;
        case ORDER_BY_LEAST:
            orderBy += KEY_AMOUNT + " desc";
            break;
        default:
            orderBy = null;
    }

    return getAllTransactions(orderBy);
}


The getAllTransactions(orderBy) line executes the SQL command select * from TABLE_TRANSACTIONS appending the order by constraint should it be non-null.

Is this the proper use of SQL? Would it be more efficient (aka faster) to store this data in a standard container (such as List&lt;Transaction&gt;) and then sort them in the desired order?
Enum
First of all, instead of an int orderByType, I would use an enum.
enum SortOrder {
    NEWER(&quot;date(&quot; + SomeConstant.KEY_DATE + &quot;) desc&quot;),
    OLDER(&quot;date(&quot; + SomeConstant.KEY_DATE + &quot;) asc&quot;),
    ...;
    private SortOrder(String order) {
        this.order = order;
    }

    public String getOrder() {
        return this.order;
    }
}

This will clean up your getAllTransactions method:
public Cursor getAllTransactions(SortOrder orderByType) {
    return getAllTransactions(orderByType == null ? null : orderByType.getOrder());
}


Database vs. Application
I feel that is OK to let the database deal with this. There is a positive aspect of letting it be handled in the application: If the application deals with it, then you can reorder the elements without querying the database.
However,

The list is small (5 records at the most)

I think either way will work just fine. If it is common to reorder the list, then I would let the application deal with it. Although your enum SortOrder needs quite a lot of more code to work directly with a List&lt;T&gt;.
If you want to use an enum and reorder inside the application, then I would let the enum take a Comparator&lt;T&gt; in the constructor and create an anonymous inner class for each enum value.