pardom-zz / ActiveAndroid

Active record style SQLite persistence for Android
http://www.activeandroid.com
4.7k stars 1.03k forks source link

Raw query #181

Open fabreax opened 10 years ago

fabreax commented 10 years ago

Hello, I need to do a "SELECT DISTINCT column FROM MyTable"

I tried ActiveAndroid.getDatabase().rawQuery("SELECT DISTINCT column FROM MyTable", null); but I have a "java.lang.NoSuchMethodError: android.database.sqlite.SQLiteDatabase.query"

Is there a solution ?

Thank you.

fabreax commented 10 years ago

Hello,

Thank you but "execSQL" has no value returned.

2014-02-03 Leonardo Rossetto notifications@github.com:

Use ActiveAndroid.execSQL(String)

https://github.com/pardom/ActiveAndroid/blob/master/src/com/activeandroid/ActiveAndroid.java#L79

— Reply to this email directly or view it on GitHubhttps://github.com/pardom/ActiveAndroid/issues/181#issuecomment-33940385 .

omaraf commented 10 years ago

Did you ever find a solution to this issue?

joshuapinter commented 10 years ago

Have you tried using the distinct() method? e.g new Select().distinct()

omaraf commented 10 years ago

Yes, but where should I set which column to filter distincts? For example, to count how many distinct values are on a specific column?— Sent from Mailbox

On Tue, May 13, 2014 at 7:24 PM, Joshua Pinter notifications@github.com wrote:

Have you tried using the distinct() method? e.g new Select().distinct()

Reply to this email directly or view it on GitHub: https://github.com/pardom/ActiveAndroid/issues/181#issuecomment-43035910

fabreax commented 10 years ago

Hello, I have not found any solution, I have switched to another ORM framework.

Maragues commented 10 years ago

Did you try SQLiteUtils.rawQuery ? https://github.com/pardom/ActiveAndroid/blob/master/src/com/activeandroid/util/SQLiteUtils.java

public static <T extends Model> List<T> rawQuery(Class<? extends Model> type, String sql, String[] selectionArgs) {
        Cursor cursor = Cache.openDatabase().rawQuery(sql, selectionArgs);
        List<T> entities = processCursor(type, cursor);
        cursor.close();
        return entities;
    }
melwinm commented 10 years ago

Von meinem Sony Xperia™-Smartphone gesendet

---- Miguel Aragues schrieb ----

Did you try SQLiteUtils.rawQuery ? https://github.com/pardom/ActiveAndroid/blob/master/src/com/activeandroid/util/SQLiteUtils.java

public static List rawQuery(Class<? extends Model> type, String sql, String[] selectionArgs) { Cursor cursor = Cache.openDatabase().rawQuery(sql, selectionArgs); List entities = processCursor(type, cursor); cursor.close(); return entities; }

— Reply to this email directly or view it on GitHub.

roozevasl commented 9 years ago

You should use Distinct as below:

List datas = new Select() .distinct() .from(Data.class) .groupBy("course_type") .execute();