Note that there are some explanatory texts on larger screens.

plurals
  1. POHow is onUpgrade triggered?
    text
    copied!<p>I'm new at Android and database, I have this method in DatabaseIncomeOutcome.java class:</p> <pre><code>public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL("CREATE TABLE IF NOT EXISTS " + DATABASE_TABLE + "(" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_IO + " TEXT NOT NULL, " + KEY_NOTE + " TEXT NOT NULL);" ); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } public DatabaseIncomeOutcome(Context c){ ourContext = c; } public DatabaseIncomeOutcome open(){ ourHelper = new DbHelper(ourContext); ourDatabase = ourHelper.getWritableDatabase(); return this; </code></pre> <p>when I called the method from another class</p> <pre><code> DatabaseIncomeOutcome entry = new DatabaseIncomeOutcome(this); entry.open(); </code></pre> <p>How and when the <code>onUpgrade</code> called? Is it called everytime I execute the <code>entry.open()</code>?</p> <p>I also want to add this script</p> <pre><code>if (newVersion &gt; oldVersion) { db.execSQL("ALTER TABLE foo ADD COLUMN new_column INTEGER DEFAULT 0"); </code></pre> <p>on <code>onUpgrade</code> to add new Column,</p> <p>Then, how I should call the `onUpgrade', so I could add new column, if I might need it for future development.</p> <p>Thanks...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload