Reputation: 14585
I know that this kind of questions are asked a lot and I know that I'm not the first one or I'll be the last, but I need a little help with this issue. I'm trying to upgrade my database from older to a newer version and I'm trying to find out how to do this. I'm using my own SQLiteDatabaseHelper
class which copy a database file from assets folder and save it to system database folder. So i want to know which is the best way to implement my onUpgrade()
function so I can resolve this issue.
I want to find a way to copy all the data from the old table, to the new one and after that to delete the old one, but I'm not really sure how can I achieve this. Any ideas or any kind of help is welcomed!
Thanks!
Upvotes: 1
Views: 711
Reputation: 66657
In your onUpgrade() method, write a query to
1) create backup_table, (make sure backup_table is not already there using IF EXISTS)
2) Select data from original table and insert into backup
insert into table2 (name, address) select name, address from table1
3) remove original table
Upvotes: 1
Reputation: 9117
Copying is as simple as querying the old table, inserting into the new table.
And then, you can drop the old table.
Upvotes: 0