Esempio n. 1
0
  /**
   * Creates the underlying database with the SQL_CREATE queries from the contract classes to create
   * the tables and initialize the data. The onCreate is triggered the first time someone tries to
   * access the database with the getReadableDatabase or getWritableDatabase methods.
   *
   * @param db the database being accessed and that should be created.
   */
  @Override
  public void onCreate(SQLiteDatabase db) {
    METHOD = "onCreate()";

    // Create the db to contain the data for AppUser
    if (DEBUG) log.i(TAG, METHOD, "Creating Database: [" + DATABASE_NAME + "].");
    db.execSQL(CREATE_USER_TABLE);
    db.execSQL(CREATE_CONTACT_TABLE);
  }
Esempio n. 2
0
  /**
   * This method must be implemented if your application is upgraded and must include the SQL query
   * to upgrade the database from your old to your new schema.
   *
   * @param db the database being upgraded.
   * @param oldVersion the current version of the database before the upgrade.
   * @param newVersion the version of the database after the upgrade.
   */
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    METHOD = "onUpgrade()";

    // Logs the the process of the DB upgrade
    if (DEBUG)
      log.i(
          TAG,
          METHOD,
          "Ugrading Database from version [" + oldVersion + "] to [" + newVersion + "]");

    // Drop existing tables. TODO: If this is ever released, must implement data migration
    db.execSQL("DROP TABLE IF EXISTS " + USER_TABLE);
    db.execSQL("DROP TABLE IF EXISTS " + CONTACT_TABLE);

    // Recreate the db
    onCreate(db);
  }