jeudi 7 mai 2015

(Bug?) SQLite - GreenDao: Correct SQL-Statement but table gets not created correctly on device

Okay this is now very strange.

I am using GreenDao to create this Restaurant entity and a few others:

Entity restaurant = schema.addEntity("Restaurant");
restaurant.addLongProperty("restaurantID").primaryKey();
restaurant.addStringProperty("restaurantName");
restaurant.addFloatProperty("latitude");
restaurant.addFloatProperty("longitude");

and if I create this database on the emulator it works without troubles.

If I run my App on a device only restaurantID, longitude and latitude are present as columns. My App crashes then with the error

android.database.sqlite.SQLiteException: table RESTAURANT has no column named RESTAURANT_NAME

despite GreenDao generates this creation statement - and like I said, it works on an emulated device:

/** Creates the underlying database table. */
public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
    String constraint = ifNotExists? "IF NOT EXISTS ": "";
    db.execSQL("CREATE TABLE " + constraint + "'RESTAURANT' (" + //
            "'RESTAURANT_ID' INTEGER PRIMARY KEY ," + // 0: restaurantID
            "'RESTAURANT_NAME' TEXT," + // 1: restaurantName
            "'LATITUDE' REAL," + // 2: latitude
            "'LONGITUDE' REAL);"); // 3: isFavorite
}

This one is really, really annoying. Any idea what is wrong here? I am helpless already.

Aucun commentaire:

Enregistrer un commentaire