thanks for reading my question here.
Actually i have some confusion for how to deal with SQLite tables
when i need to add some rows in table for multipl
From what you have mentioned (e.g. the onUpgrade method) I assume you are using a SQLiteOpenHelper.
First update your database version to 3.
In onCreate(SQLiteDatabase db), update the code so that it creates all the tables as per the latest version 3 schema (e.g the table has col1, col2 and col3). A new install will trigger this code creating a brand new v3 table.
In onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion), refer to the old and new version parameters and update the tables that already exist accordingly, e.g.
if (oldVersion == 1 && newVersion = 2)
{
//Going from v1 to v2
db.execSQL("ALTER TABLE mytable ADD COLUMN col2 INTEGER");
}
if (oldVersion == 1 && newVersion = 3)
{
//Going from v1 to v3
db.execSQL("ALTER TABLE mytable ADD COLUMN col2 INTEGER");
db.execSQL("ALTER TABLE mytable ADD COLUMN col3 INTEGER");
}
if (oldVersion == 2 && newVersion = 3)
{
//Going from v2 to v3
db.execSQL("ALTER TABLE mytable ADD COLUMN col3 INTEGER");
}
This code is triggered when the database version doesn't match what the user currently has. You know what version they do have so can amend the existing tables accordingly to bring them up to the same definition as found in onCreate. You can of course do anything you like within onUpgrade such as creating new tables and inserting/updating/deleting data.