get Page Sorted With Condition from database table - Android Database

Android examples for Database:SQL Query

Description

get Page Sorted With Condition 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 getPageSortedWithCondition(SQLiteDatabase db,
            String tableName, String condition, String keyColumn,
            boolean desc, int pageNum) {
        return db.rawQuery("SELECT * " + "FROM " + tableName + " "
                + "WHERE " + condition + " " + "ORDER BY " + keyColumn
                + " " + (desc ? "DESC" : "") + " " + "LIMIT " + PAGE_SIZE
                + " " + "OFFSET " + (PAGE_SIZE * pageNum) + ";", null);

    }//from  w  w  w  .  j  a va2  s. c o  m
}

Related Tutorials