Monty
Monty

Reputation: 3215

SQLite Can't upgrade read-only database from version 2 to 3

I have one table in my SQLite Database.

@Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL( "CREATE TABLE book1(_id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT, author TEXT,isbn TEXT);");

and i am adding new column in table and change the version number of DB.

@Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("ALTER TABLE book1 ADD COLUMN Cost TEXT");
        Log.v("Alter Table", "Colunm Added enjoy"+db.getVersion());
        db.execSQL("INSERT into book1 (title,author,isbn,Cost,city) VALUES('php','Lioneworge',1111,1500)");

its add new column in my table.

but if i want to add new column again in my this table. version 2 to 3

@Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("ALTER TABLE book1 ADD COLUMN Cost TEXT,city TEXT");

        db.execSQL("INSERT into book1 (title,author,isbn,Cost,city) VALUES('php','Lioneworge',1111,1500,'Hydrabad')");

it is showing this

Caused by:  Can't upgrade read-only database from version 2 to 3

i do not want to loss my data on upgrade thats why i am not using drop query.

UPDATE:- I read this ALTER TABLE is limited in sqlite ,some one please tell me that how many time i can you alter for add and rename.

Upvotes: 0

Views: 508

Answers (1)

Himanshu
Himanshu

Reputation: 2454

You can add as many as you like but only one at a time. See http://www.sqlite.org/lang_altertable.html

Split the ALTER TABLE into two each adding 1 column and try

NOT TESTED

Upvotes: 1

Related Questions