this is my db:
@Database(name = GamersDatabase.NAME, version = GamersDatabase.version)
public class GamersDatabase {
public static final String NAME = "and_roid";
public static final int version = 1;
}
and this is my table:
@Table(database = GamersDatabase.class)
public class Gamers extends BaseModel{
@PrimaryKey(autoincrement = true)
int id;
@Column@NotNull
String name;
}
this is my insert statement that works good (because the select statement below returns correct list size):
TransactionManager.getInstance().addTransaction(new SaveModelTransaction<>(ProcessModelInfo.withModels()));
//insert
SQLite.insert(Gamers.class).columns(Gamers_Table.name.getDefinition() ).values("ali").execute();
this is my select statement :
List<Gamers> w = SQLite.select().from(Gamers.class).where(Gamers_Table.fName.eq("ali")).queryList();
for (Gamers o : w) {
// The problem is this part that I can't get gamer's name
Toast.makeText(MainActivity.this, ""+o.toString(), Toast.LENGTH_SHORT).show();
}
so if DBFlow is an ORM
system, how can I get my object and get it's behavior as a gamer object that we have in normal sqlite
cursor
method? if the question is not clear I should add comment:
in old fashion database method, we use SQLite
queries like this:
Cursor c = db.getRawQuery("select * from tbl_gamers" , null);
if(c.moveToFirst()){
// fill object
}
and then use our filled object, Now how can I have access to DBFlow retrieved object's fields (like name
and id
)?
I'm quire confused that you're using both a different table and field name in your select query. It works fine for me if I'm using the declared values of your Workers table.
But I guess that's not the point. Maybe your problem is that the fields of the Workers class are package-local. Simply make them public or provide public getters to access them.
Please note that's I'm also not very familiar with DBFlow but I think your TransactionManager doesn't do anything. According to the documentation at here you should pass a list of models that you want to save. After some problems with using SaveModelsTransaction using the following code worked fine for me:
Hope, this can help you.
Regards,
Alex