lundi 25 mai 2015

Reverse Query in Sqlite

 public ArrayList<Advertising> getAdvertises() {
    ArrayList<Advertising> advertises = new ArrayList<Advertising>();
    String query = "SELECT " + ADVERTISING_ID_WITH_PREFIX + ","
            + ADVERTISING_TITLE_WITH_PREFIX + ","
            + DataBaseHelper.ADVERTISING_DESCRIPTION + ","
            + DataBaseHelper.ADVERTISING_FD + ","
            + DataBaseHelper.ADVERTISING_TD + ","
            + DataBaseHelper.ADVERTISING_DISCOUNT + ","
            + DataBaseHelper.ADVERTISING_PRICE + ","
            + DataBaseHelper.ADVERTISING_IMAGE + ","
            + DataBaseHelper.ADVERTISING_CATEGORY_ID + ","
            + CAT_NAME_WITH_PREFIX + " FROM "
            + DataBaseHelper.ADVERTISING_TABLE + " adv, "
            + DataBaseHelper.CATEGORY_TABLE + " cat WHERE adv."
            + DataBaseHelper.ADVERTISING_CATEGORY_ID + " = cat."
            + DataBaseHelper.ID_COLUMN;

//setTables() method from SQLiteQueryBuilder is used to set list of tables to query. Multiple tables can be specified to perform a join.

    Log.d("query", query);
    Cursor cursor = database.rawQuery(query, null);
    while (cursor.moveToNext()) {
        Advertising advertising = new Advertising();
        advertising.setId(cursor.getInt(0));
        advertising.setTitle(cursor.getString(1));
        advertising.setDescription(cursor.getString(2));
        try {
            advertising.setFromDate(formatter.parse(cursor.getString(3)));
            advertising.setToDate(tormatter.parse(cursor.getString(4)));
        } catch (ParseException e) {
            advertising.setFromDate(null);
            advertising.setToDate(null);
        }
        advertising.setDiscount(cursor.getInt(5));
        advertising.setPrice(cursor.getDouble(6));
        advertising.setImage(cursor.getBlob(7));
        Category category = new Category();
        category.setId(cursor.getInt(8));
        category.setName(cursor.getString(9));

        advertising.setCategory(category);

        advertises.add(advertising);
    }
    return advertises;
}

Am want to query in reverse order , from last item in the table the last item in database pick to the first item in list view and so on am using

"WHERE ORDER BY "+Database.clcolumnid+" ASC" but not work.

Aucun commentaire:

Enregistrer un commentaire