1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
private static final String TABLE_LIVRES = "table_livres";
private static final String TABLE_PINGOUIN = "table_pingouin";
private static final String COL_ID = "ID";
private static final String COL_ISBN = "ISBN";
private static final String COL_TITRE = "Titre";
private static final String COL_ID_PINGOUIN = "ID_PINGOUIN";
private static final String COL_TEST = "test";
private static final String CREATE_BDD = "CREATE TABLE " + TABLE_LIVRES + " ("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_ISBN + " TEXT NOT NULL, "
+ COL_TITRE + " TEXT NOT NULL);";
private static final String CREATE_BDD_PINGOUIN = "CREATE TABLE " + TABLE_PINGOUIN + " ("
+ COL_ID_PINGOUIN + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COL_TEST + " TEXT NOT NULL);";
public MaBaseSQLite(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
//on crée la table à partir de la requête écrite dans la variable CREATE_BDD
db.execSQL(CREATE_BDD);
db.execSQL(CREATE_BDD_PINGOUIN);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//On peut faire ce qu'on veut ici moi j'ai décidé de supprimer la table et de la recréer
//comme ça lorsque je change la version les id repartent de 0
db.execSQL("DROP TABLE " + TABLE_LIVRES + ";");
db.execSQL("DROP TABLE " + TABLE_PINGOUIN + ";");
onCreate(db);
} |
Partager