samedi 2 avril 2016

Issue with 2nd table in DB

I have DB with 2 tables. 1st table works good, but AS doesn`t see 2nd table. This is strange, because I create 2nd as well as 1st. Whats wrong? Here is my DB class:

public class DBHelper extends SQLiteOpenHelper {

    public DBHelper(Context context) {
        super(context, "myDB", null, 1);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.d(LOG_TAG, "--- onCreate database ---");
        db.execSQL("create table mytable ("
                + "id integer primary key autoincrement,"
                + "myId integer,"
                + "parent integer,"
                + "name text,"
                + "code text" + ");");

        db.execSQL("create table filtertable ("
                + "id integer primary key autoincrement,"
                + "filtername text" + ");");
    }

Filling 2nd table:

 dbHelper = new DBHelper(getActivity());
        db = dbHelper.getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.clear();
 cv.put("filtername", "example");
 db.insert("filtertable", null, cv);

LogCat error:

04-02 09:31:42.841 8730-8730/com.my.app E/SQLiteLog: (1) no such table: filtertable 04-02 09:31:42.845 8730-8730/com.my.app E/SQLiteDatabase: Error inserting filtername=example android.database.sqlite.SQLiteException: no such table: filtertable (code 1): , while compiling: INSERT INTO filtertable(filtername) VALUES (?)

Aucun commentaire:

Enregistrer un commentaire