mercredi 16 décembre 2015

ORMLite on Android: cannot get table entries

I am trying to use ORMLite on Android. I use an existing SQLite database that I copy from the assets folder in the external storage space of the phone. This part works correctly.

I also managed to create a DAO for one of the tables (it is able to find the table, I am sure of it) but when I try getting the entries by using queryForAll on the DAO, I always get 0 items. I used the count method and I also get a value of 0, but this table has items.

How is it possible?

My table name is "info" and I use this DAO:

@DatabaseTable(tableName="info")
public class Info {
@DatabaseField
private String version;

@DatabaseField
private String kanjidic2Version;

@DatabaseField
private String kanjiVGVersion;

/**
 * Gets the version.
 * @return the version.
 */
public String getVersion(){
    return this.version;
}

/**
 * Gets the KanjiDic2 version
 * @return the version.
 */
public String getKanjidic2Version(){
    return this.kanjidic2Version;
}

/**
 * Gets the KanjiVG version.
 * @return the version.
 */
public String getKanjiVGVersion(){
    return this.kanjiVGVersion;
}

I have 1 row in the info table but it looks like the app is not able to get it. Here is the code I use to get it:

public class InfoRepository {
Dao<Info, String> infoDao;

public InfoRepository(DBHelper helper){
    try{
        this.infoDao = helper.getInfoDao();
    }catch(SQLException e){
        Log.e(getClass().getSimpleName(), e.getMessage());
    }
}

/**
 * Gets all the info.
 * @return all the info.
 */
public List<Info> getAll(){
    List<Info> infos = new ArrayList<>();
    try{
        long count = this.infoDao.countOf();
        Log.d(getClass().getSimpleName(), "Info entry count: " +count);
        infos.addAll(this.infoDao.queryForAll());
    }catch(SQLException e){
        Log.e(getClass().getSimpleName(), e.getMessage());
    }
    return infos;
}
}

Does anyone has any idea?

Thank you!

Aucun commentaire:

Enregistrer un commentaire