lundi 10 août 2015

Android 5.0 SQLITE insert fail

I get a weird error, every time i tried insert data on the database:

Error inserting date=1439183960 amount=5.0 icon=1 description=g or_amount=0.0 lat=0.0 long=0.0
android.database.sqlite.SQLiteException: table transactions has no column named icon (code 1): , 
while compiling: INSERT INTO transactions(date,amount,icon,description,or_amount,lat,long) VALUES (?,?,?,?,?,?,?)

The error says that the table icon doesn't have the column icon

here is my create query:

@Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS transactions (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "amount REAL, " +
                "or_amount REAL, " +
                "description TEXT" +
                "icon INTEGER, " +
                "lat REAL, " +
                "long REAL, " +
                "date INTEGER" +
                ")");
    }

Here is the method that insert some entitie to the db:

public long insert (Entitie entitie) {
        long NO_INSERTED_ENTITIE = -1;
        long id = NO_INSERTED_ENTITIE;

        getWritableDb();

        if (entitie.getId() == NO_INSERTED_ENTITIE){
            id = db.insert(entitie.getTableName(), null, entitie.getContentValues());
            entitie.setId( (int) id );
        }
        return id;
    }

and here is the Entitie it's called PaymentLog:

public class PaymentLog extends Entitie{

    //====== tables fields======

    private static final String tableName = "transactions";
    private static final String[] columnNames = {"id", "amount", "or_amount", "description", "icon", "long", "lat", "date"};
    private final int ID_POSITION = 0, AMOUNT_POSITION =1, OR_AMOUNT_POSITION = 2, ICON_POSTION = 4, LONG_POSTION =5, LAT_POSTION=6, DATE_POSTION=7, DESCRIPTION_POSTION = 3;

    @Override
    public ContentValues getContentValues(){
        ContentValues content = new ContentValues();
        content.put( columnNames[ AMOUNT_POSITION ], this.getTransaction());
        content.put( columnNames[ OR_AMOUNT_POSITION ], this.getOriginal_amount());
        content.put( columnNames[ ICON_POSTION ], this.getIcon() );
        content.put( columnNames[ LONG_POSTION ], this.getLang() );
        content.put( columnNames[ LAT_POSTION ], this.getLat() );
        content.put( columnNames[ DATE_POSTION ], this.getDate().getTime()/1000 );
        content.put( columnNames[ DESCRIPTION_POSTION ], this.getDescription() );
        return content;
    }

    public String getTableName() {
        return tableName;
    }

}

i don't know why i got this error, my create query it's correctly, i clean the cache and app data from my phone, to rebuild the DB with the onCreate method. My class PaymentLog it's correctly too, i don't know what it's wrong, i heard about some changes in sqlite on Android 5.0 but i don't know if insert had changes.

Aucun commentaire:

Enregistrer un commentaire