Here is the code I used in case someone had a similar problem:
public class DataHelper { private static final int DATABASE_VERSION = 1; private static final String TABLE_NAME = "TableName"; private Context context; private SQLiteDatabase db; public static final String ColName = "ColumnName"; public static final String KEY_ID = "_id"; public DataHelper(Context context) { this.context = context; OpenHelper openHelper = new OpenHelper(this.context); this.db = SQLiteDatabase.openDatabase( Environment.getExternalStorageDirectory() + "/myDB.db", null, SQLiteDatabase.NO_LOCALIZED_COLLATORS); } public void deleteAll() { this.db.delete(TABLE_NAME, null, null); } public Cursor selectBrandsCursor() { String[] columns = new String[] { ColName, KEY_ID }; Cursor cursor = this.db.rawQuery("SELECT " + ColName + ", " + KEY_ID + " FROM " + TABLE_NAME + " GROUP BY " + ColName + ";", null); return cursor; } private static class OpenHelper extends SQLiteOpenHelper { OpenHelper(Context context) { super(context, null, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { onCreate(db); } } }
Works well, MUCH faster, duplicates for free, thanks to Matthew and Femi for the suggestions.
source share