pardom-zz / ActiveAndroid

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

Can't Select only specific Columns #541

Open HamzehSoboh opened 6 years ago

HamzehSoboh commented 6 years ago

I'm trying to fetch only 2 columns from my table, as the rest are not needed and -more important- very heavy, and if fetched then I'll have a memory leak!

new Select("cached_id", "group_id", "server_time").from(CachedObject.class).where("type = ?", 3).execute()

Having cached_id the primary key. I'm getting the correct records, but with full data (all columns), including the very heavy and not needed ones!

Any idea how to solve that?

egithub13 commented 6 years ago

This worked for me. Hope it helps

public static List getEmployee(String name){ //Method in my Employee class String[] getName = {name}; //Added a string array to grab name return new Select() .from(Employee.class) //Employee class extends Model .where("First_Name = ?",getName)//Added the array here; "First_name" is a column in my table .execute(); }

ImangazalievM commented 6 years ago

Hello. ActiveAndroid no longer be maintained. You can use ReActiveAndroid, it's based on ActiveAndroid.

For example, you can select specific columns:

List<Note> notes = Select.columns("id", "text").from(Note.class).fetch();

Full Documentation.

joshuapinter commented 4 years ago

You need to provide an Array of Strings instead of just String params, so do this instead:

new Select( new String[]{ "cached_id, group_id, server_time" } ).from( CachedObject.class ).where( "type = ?", 3 ).execute();