get Page Sorted By Key from database table - Android Database

Android examples for Database:SQL Query

Description

get Page Sorted By Key from database table

Demo Code


//package com.book2s;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Main {
    public static final int PAGE_SIZE = 50;

    public static Cursor getPageSortedByKey(SQLiteDatabase db,
            String tableName, String keyColumn, boolean desc, int pageNum) {
        return db.rawQuery("SELECT * " + "FROM " + tableName + " "
                + "ORDER BY " + keyColumn + " " + (desc ? "DESC" : "")
                + " " + "LIMIT " + PAGE_SIZE + " " + "OFFSET "
                + (PAGE_SIZE * pageNum) + ";", null);
    }/* ww  w .  jav  a2 s .  com*/
}

Related Tutorials