Exemplo n.º 1
0
 @Override
 public void onCreate(SQLiteDatabase database) {
   Log.v("Checkmycar", "Requête création db : " + DATABASE_CREATE);
   database.execSQL(DbVoiture.createTableVoiture());
   database.execSQL(DbPorte.createTablePorte());
   database.execSQL(DbParam.createTableParam());
   // Ajout d'un param par défaut
   database.execSQL(DbParam.insertDefaultValue());
   database.execSQL(DbVoiture.insertDefaultValue());
   database.execSQL(DbPorte.insertPorte());
 }
Exemplo n.º 2
0
public class MySQLiteHelper extends SQLiteOpenHelper {

  public static final String DATABASE_NAME = "checkMyCar.db";
  private static final int DATABASE_VERSION = 3;
  private static final String DATABASE_CREATE =
      DbVoiture.createTableVoiture()
          + " "
          + DbPorte.createTablePorte()
          + " "
          + DbParam.createTableParam();

  public MySQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    this.getWritableDatabase();
  }

  @Override
  public void onCreate(SQLiteDatabase database) {
    Log.v("Checkmycar", "Requête création db : " + DATABASE_CREATE);
    database.execSQL(DbVoiture.createTableVoiture());
    database.execSQL(DbPorte.createTablePorte());
    database.execSQL(DbParam.createTableParam());
    // Ajout d'un param par défaut
    database.execSQL(DbParam.insertDefaultValue());
    database.execSQL(DbVoiture.insertDefaultValue());
    database.execSQL(DbPorte.insertPorte());
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w(
        MySQLiteHelper.class.getName(),
        "Upgrading database from version "
            + oldVersion
            + " to "
            + newVersion
            + ", which will destroy all old data");
    /*db.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENTS);*/
    onCreate(db);
  }
}